Skip to content

Commit 3647f20

Browse files
committed
ADD: Add Windows support to databento-cpp
1 parent 851352f commit 3647f20

28 files changed

+273
-88
lines changed

.github/workflows/build.yaml

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ jobs:
1111
fail-fast: false
1212
matrix:
1313
compiler: [clang++, g++]
14-
1514
name: build - ubuntu-latest - ${{ matrix.compiler}}
1615
runs-on: ubuntu-latest
17-
1816
steps:
1917
- name: Checkout repository
2018
uses: actions/checkout@v3
@@ -54,7 +52,6 @@ jobs:
5452
macos:
5553
name: build - macos-latest - clang++
5654
runs-on: macos-latest
57-
5855
steps:
5956
- name: Checkout repository
6057
uses: actions/checkout@v3
@@ -74,3 +71,29 @@ jobs:
7471
run: cmake --build build
7572
- name: Unit tests
7673
run: cd build && ctest --verbose
74+
75+
windows:
76+
name: build - windows-latest - msvc
77+
runs-on: windows-latest
78+
steps:
79+
- name: Checkout repository
80+
uses: actions/checkout@v3
81+
- name: Cache dependencies
82+
uses: actions/cache@v3
83+
env:
84+
cache-name: cache-vcpkg
85+
with:
86+
path: build/vcpkg_installed
87+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('./vcpkg.json') }}
88+
- name: CMake configure
89+
run: |
90+
cmake -S . -B build `
91+
-DDATABENTO_ENABLE_UNIT_TESTING=1 `
92+
-DDATABENTO_ENABLE_EXAMPLES=1 `
93+
-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake `
94+
-DVCPKG_BUILD_TYPE=debug `
95+
-DDATABENTO_USE_EXTERNAL_GTEST=0
96+
- name: CMake build
97+
run: cmake --build build --parallel 10
98+
- name: Unit tests
99+
run: cd build && ctest --verbose --exclude-regex cmake

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
build
2+
CMakeSettings.json
3+
vcpkg_installed
4+
.vs
25
!*.zst

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 0.10.0 - TBD
44

55
#### Enhancements
6+
- Added preliminary support for Windows
67
- Added `LiveThreaded::BlockForStop` to make it easier to wait for one or more records
78
before closing the session
89

CMakeLists.txt

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
2424
include(cmake/StandardSettings.cmake)
2525
include(cmake/StaticAnalyzers.cmake)
2626
include(cmake/Utils.cmake)
27-
message(STATUS "Started CMake for ${PROJECT_NAME} v${PROJECT_VERSION}...\n")
27+
message(STATUS "Started CMake for ${PROJECT_NAME} v${PROJECT_VERSION}...")
2828

2929
if(NOT CMAKE_BUILD_TYPE)
3030
if(IS_MAIN_PROJECT)
@@ -41,7 +41,7 @@ endif()
4141
#
4242

4343
if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
44-
message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.\n")
44+
message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.")
4545
endif()
4646

4747
#
@@ -51,7 +51,7 @@ endif()
5151
include(TestBigEndian)
5252
test_big_endian(IS_BIG_ENDIAN)
5353
if(IS_BIG_ENDIAN)
54-
message(FATAL_ERROR "Big-endian platforms aren't supported because DBN parsing assumes the data is little-endian and in native byte order.\n")
54+
message(FATAL_ERROR "Big-endian platforms aren't supported because DBN parsing assumes the data is little-endian and in native byte order.")
5555
endif()
5656

5757
#
@@ -94,7 +94,7 @@ set_target_properties(
9494
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/${CMAKE_BUILD_TYPE}"
9595
)
9696

97-
message(STATUS "Added all header and implementation files.\n")
97+
message(STATUS "Added all header and implementation files.")
9898

9999
#
100100
# Set the project standard and warnings
@@ -110,7 +110,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_BUILD_TYPE STREQUAL "Debug")
110110
target_compile_options(${PROJECT_NAME} PRIVATE -fstandalone-debug)
111111
endif()
112112

113-
verbose_message("Applied compiler warnings.\n")
113+
verbose_message("Applied compiler warnings.")
114114

115115
#
116116
# Model project dependencies
@@ -169,6 +169,18 @@ endif()
169169
find_package(Zstd REQUIRED)
170170
find_package(Threads REQUIRED)
171171

172+
#
173+
# Platform-specific dependencies
174+
#
175+
if(WIN32)
176+
find_path(
177+
DIRENT_INCLUDE_DIR "dirent.h"
178+
PATHS "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include"
179+
REQUIRED
180+
)
181+
target_include_directories(${PROJECT_NAME} PRIVATE ${DIRENT_INCLUDE_DIR})
182+
endif()
183+
172184
target_link_libraries(
173185
${PROJECT_NAME}
174186
PUBLIC
@@ -210,7 +222,7 @@ message(STATUS "Finished setting up include directories.")
210222

211223
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
212224

213-
verbose_message("Project is now aliased as ${PROJECT_NAME}::${PROJECT_NAME}.\n")
225+
verbose_message("Project is now aliased as ${PROJECT_NAME}::${PROJECT_NAME}.")
214226

215227
#
216228
# Format the project using the `clang-format` target (i.e: cmake --build build --target clang-format)
@@ -319,7 +331,14 @@ if(${PROJECT_NAME_UPPERCASE}_GENERATE_EXPORT_HEADER)
319331
message(STATUS "Generated the export header `${PROJECT_NAME}_export.h` and installed it.")
320332
endif()
321333

322-
message(STATUS "Finished building requirements for installing the package.\n")
334+
message(STATUS "Finished building requirements for installing the package.")
335+
336+
#
337+
# Platform-specific
338+
#
339+
if(WIN32)
340+
add_compile_definitions(NOMINMAX)
341+
endif()
323342

324343
#
325344
# Unit testing setup

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ You'll need to ensure the following dependencies are installed:
6363
- [Zstandard (zstd)](https://github.com/facebook/zstd)
6464
- [nlohmann\_json (header-only)](https://github.com/nlohmann/json)
6565
- [cpp-httplib (header-only)](https://github.com/yhirose/cpp-httplib)
66+
- [dirent (Windows-only, header-only)](https://github.com/tronkko/dirent)
6667

6768
By default, cpp-httplib and nlohmann\_json are downloaded by CMake as part of the build process.
6869
If you would like to use a local version of these libraries, enable the CMake flag

cmake/CompilerWarnings.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
function(set_project_warnings project_name)
88
set(MSVC_WARNINGS
9-
/W4 # Baseline reasonable warnings
109
/w14242 # 'identifier': conversion from 'type1' to 'type1', possible loss
1110
# of data
1211
/w14254 # 'operator': conversion from 'type1:field_bits' to

cmake/Utils.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function(add_clang_format_target)
3030
-i ${sources} ${headers}
3131
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
3232
endif()
33-
message(STATUS "Format the project using the `clang-format` target (i.e: cmake --build build --target clang-format).\n")
33+
message(STATUS "Format the project using the `clang-format` target (i.e: cmake --build build --target clang-format).")
3434
endif()
3535
endfunction()
3636

cmake/mingw-w64-x86_64.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
set(CMAKE_SYSTEM_NAME Windows)
2+
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)
3+
4+
# Cross compilers to use for C and C++
5+
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
6+
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
7+
# Compiler for Windows resource files
8+
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)
9+
10+
# Target environment on the build host system
11+
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})
12+
13+
# Modify default behavior of FIND_XXX() commands
14+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
15+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
16+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

example/historical/symbology_resolve.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#include <sysexits.h>
2-
31
#include <iostream>
42
#include <vector>
53

@@ -12,7 +10,7 @@ int main(int argc, char* argv[]) {
1210
if (argc < 6) {
1311
std::cerr << "USAGE: symbology-resolve <DATASET> <STYPE_IN> <STYPE_OUT> "
1412
"<DATE> <SYMBOLS...>\n";
15-
return EX_USAGE;
13+
return 1;
1614
}
1715
const auto stype_in = databento::FromString<databento::SType>(argv[2]);
1816
const auto stype_out = databento::FromString<databento::SType>(argv[3]);

example/historical/timeseries_get_range.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
#include <ctime>
33
#include <iomanip>
44
#include <iostream> // setw
5+
#ifdef _WIN32
6+
// _mkgmtime is equivalent to timegm
7+
#define timegm _mkgmtime
8+
#endif
59

610
#include "databento/constants.hpp"
711
#include "databento/datetime.hpp"

0 commit comments

Comments
 (0)