forked from VowpalWabbit/reinforcement_learning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
178 lines (153 loc) · 6.39 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
cmake_minimum_required(VERSION 3.5)
if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif()
if(POLICY CMP0091)
cmake_policy(SET CMP0091 NEW)
endif()
if(WIN32)
# Due to needing to configure the CMAKE platform, this needs to be included before the
# top-level project() declaration.
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/platforms/win32.cmake)
message(STATUS "WinSDK Version: ${CMAKE_SYSTEM_VERSION}")
endif()
if(NOT WIN32)
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g -DNDEBUG")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -g -DNDEBUG")
endif()
if (NOT CMAKE_BUILD_TYPE AND NOT GENERATOR_IS_MULTI_CONFIG)
message(STATUS "No build type selected, defaulting to Release")
set(CMAKE_BUILD_TYPE "Release")
endif()
# Set this to on so that tooling can make use of the outputted compile commands (such as clang-tidy)
set(CMAKE_EXPORT_COMPILE_COMMANDS On)
# Options that add Vcpkg package requirements
# All additions to VCPKG_MANIFEST_FEATURES list must come before project()
option(RL_BUILD_BENCHMARKS "Build benchmarks" OFF)
if(RL_BUILD_BENCHMARKS)
list(APPEND VCPKG_MANIFEST_FEATURES "benchmarks")
endif()
project(reinforcement_learning)
# Add support for building library with latest version of C++ supported by your compiler
# Copied from VW
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake/")
option(USE_LATEST_STD "Override using C++11 with the latest standard the compiler offers. Default is C++11. " OFF)
include(DetectCXXStandard)
set(RL_CXX_STANDARD 11)
if(USE_LATEST_STD)
DetectCXXStandard(RL_CXX_STANDARD)
endif()
message(STATUS "Using C++ standard: " ${RL_CXX_STANDARD})
set(CMAKE_CXX_STANDARD ${RL_CXX_STANDARD})
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
option(RL_BUILD_PYTHON "Build the Python bindings" OFF)
option(RL_USE_ZSTD "Whether to enable usage of zstandard compression" ON)
option(RL_STATIC_DEPS "Only use static dependencies" OFF)
option(vw_USE_AZURE_FACTORIES "Whether to compile with the azure factories components" ON)
option(RL_OPENSSL_SYS_DEP "Use system-wide openssl library" ON)
option(RL_CPPRESTSDK_SYS_DEP "Use system-wide cpprestsdk library" ON)
option(RL_BUILD_NUGET "Build the Nuget package" OFF)
option(RL_BUILD_EXTERNAL_PARSER "Build external parser version of VW" OFF)
option(RL_USE_ASAN "Compile with AddressSanitizer" OFF)
option(RL_USE_UBSAN "Compile with UndefinedBehaviorSanitizer" OFF)
option(rlclientlib_BUILD_ONNXRUNTIME_EXTENSION "Build OnnxRuntime Inference Extension" OFF)
option(rlclientlib_BUILD_DOTNET "Build .NET bindings" OFF)
option(rlclientlib_DOTNET_USE_MSPROJECT "[Experimental] Use import_external_msproject to build .NET csproj files." OFF)
if(RL_USE_ASAN)
add_compile_definitions(RL_USE_ASAN VW_USE_ASAN)
if(MSVC)
add_compile_options(/fsanitize=address /GS- /wd5072)
add_link_options(/InferASanLibs /incremental:no /debug)
# Workaround for MSVC ASan issue here: https://developercommunity.visualstudio.com/t/VS2022---Address-sanitizer-on-x86-Debug-/10116361
add_compile_definitions(_DISABLE_STRING_ANNOTATION)
else()
add_compile_options(-fsanitize=address -fno-omit-frame-pointer -g3)
add_link_options(-fsanitize=address -fno-omit-frame-pointer -g3)
endif()
endif()
if(RL_USE_UBSAN)
add_compile_definitions(RL_USE_UBSAN VW_USE_UBSAN)
if(MSVC)
message(FATAL_ERROR "UBSan not supported on MSVC")
else()
add_compile_options(-fsanitize=undefined -fno-sanitize-recover -fno-omit-frame-pointer -g3)
add_link_options(-fsanitize=undefined -fno-sanitize-recover -fno-omit-frame-pointer -g3)
endif()
endif()
if(UNIX AND NOT APPLE)
# Temporary workaround for VW 9.6 missing size_t on Linux builds
# TODO remove when VW submodule is updated
# This must be stddef.h and not cstddef because it also applies to C code
add_compile_options(-include stddef.h)
# Enable C++17 math functions in C++11
add_compile_definitions(__STDCPP_WANT_MATH_SPEC_FUNCS__)
endif()
# For Nuget package don't use system libraries, use vendored ones in ext_libs instead
if(RL_BUILD_NUGET)
set(RAPIDJSON_SYS_DEP OFF CACHE BOOL "" FORCE)
set(FMT_SYS_DEP OFF CACHE BOOL "" FORCE)
set(SPDLOG_SYS_DEP OFF CACHE BOOL "" FORCE)
set(VW_ZLIB_SYS_DEP OFF CACHE BOOL "" FORCE)
set(VW_BOOST_MATH_SYS_DEP OFF CACHE BOOL "" FORCE)
set(RL_OPENSSL_SYS_DEP OFF CACHE BOOL "" FORCE)
set(RL_CPPRESTSDK_SYS_DEP OFF CACHE BOOL "" FORCE)
set(RL_STATIC_DEPS ON)
endif()
if(RL_STATIC_DEPS)
if(WIN32)
set(STATIC_LIB_SUFFIXES ".lib" ".a")
else()
set(STATIC_LIB_SUFFIXES ".a")
endif()
set(BUILD_SHARED_LIBS OFF CACHE BOOL "")
set(STATIC_LINK_VW_JAVA ON CACHE BOOL "")
set(Boost_USE_STATIC_LIBS ON CACHE BOOL "")
set(CMAKE_FIND_LIBRARY_SUFFIXES ${STATIC_LIB_SUFFIXES})
endif()
# We also require Boost::uuid, but that is a header-only dependency and is unable to be found
# using find_package as a component, which means it is possible to have a successfully configured
# build that will nonetheless not work due to missing dependencies.
find_package(Boost COMPONENTS unit_test_framework system program_options thread REQUIRED)
# On MacOS, Boost::thread needs to be linked separately.
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
find_package(Boost COMPONENTS thread REQUIRED)
endif()
include(ProcessorCount)
ProcessorCount(NumProcessors)
message("Number of processors: ${NumProcessors}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/nprocs.txt ${NumProcessors})
# This provides the variables such as CMAKE_INSTALL_LIBDIR for installation paths.
include(GNUInstallDirs)
include(ext_libs/ext_libs.cmake)
add_subdirectory(rlclientlib)
add_subdirectory(rlclientlib/extensions)
add_subdirectory(examples)
add_subdirectory(test_tools/joiner)
add_subdirectory(test_tools/sender_test)
add_subdirectory(test_tools/example_gen)
if(RL_BUILD_EXTERNAL_PARSER)
add_subdirectory(external_parser)
endif()
# enable_testing should be run after ext_libs so that the vw unit tests arent turned on.
enable_testing()
# Since bindings will add tests, if appropriate, it needs to be included after enable_testing().
if(rlclientlib_BUILD_DOTNET)
add_subdirectory(bindings/cs)
endif()
if(RL_BUILD_PYTHON)
add_subdirectory(bindings/python EXCLUDE_FROM_ALL)
endif()
add_subdirectory(unit_test)
add_subdirectory(unit_test/extensions)
if(RL_BUILD_BENCHMARKS)
add_subdirectory(benchmarks)
endif()
# Add the nuget subdirectory last
if(RL_BUILD_NUGET)
if(WIN32)
add_subdirectory(nuget)
else()
message(FATAL_ERROR "Nuget package must be built on Windows")
endif()
endif()