-
Notifications
You must be signed in to change notification settings - Fork 72
/
CMakeLists.txt
164 lines (138 loc) · 5.37 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
cmake_minimum_required(VERSION 3.13)
cmake_policy(SET CMP0144 NEW)
project(Desbordante)
option(COPY_PYTHON_EXAMPLES "Copy Python examples" OFF)
option(COMPILE_TESTS "Build tests" ON)
option(UNPACK_DATASETS "Unpack datasets" ON)
option(BUILD_NATIVE "Build for host machine" ON)
option(USE_LTO "Build using interprocedural optimization" OFF)
option(GDB_DEBUG "Include debug information for use by GDB" OFF)
set(SANITIZER "" CACHE STRING "Build with sanitizer, possible values: ADDRESS, UB")
set(PYTHON OFF CACHE STRING "Compile Python bindings")
set_property(CACHE PYTHON PROPERTY STRINGS OFF COMPILE INSTALL)
# By default select Debug build
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif(NOT CMAKE_BUILD_TYPE)
if (SANITIZER)
if (SANITIZER STREQUAL "ADDRESS")
set(ASAN ON)
elseif (SANITIZER STREQUAL "UB")
set(UBSAN ON)
else ()
message(FATAL_ERROR "Unknown sanitizer '${SANITIZER}', try cmake -LH")
endif ()
endif ()
if (ASAN AND PYTHON)
message(WARNING "ASan runtime must be linked with Python or manually preloaded with LD_PRELOAD=/usr/lib/libasan.so")
endif()
# compiler and platform-dependent settings
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/target")
if (MSVC)
add_compile_options(/MT /MTd /EHsc)
add_compile_options("$<$<CONFIG:Release>:/O2>")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/target")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/target")
else()
# -DELPP_THREAD_SAFE -- for easylogging++ thread safety
set(BUILD_OPTS "-DELPP_THREAD_SAFE")
if (BUILD_NATIVE)
string(JOIN ";" BUILD_OPTS "${BUILD_OPTS}" "-march=native")
endif()
# RELEASE build options
string(JOIN ";" RELEASE_BUILD_OPTS "${BUILD_OPTS}"
"-O3")
set(DEBUG_BUILD_OPTS "${BUILD_OPTS}")
# Set common DEBUG build options
string(JOIN ";" DEBUG_BUILD_OPTS "${DEBUG_BUILD_OPTS}"
"-g"
"-Wall"
"-Wextra"
"-Werror"
"-fno-omit-frame-pointer"
"-fno-optimize-sibling-calls")
if (ASAN)
# Set DEBUG build options specific for build with ASAN
set(ASAN_OPTS "-fsanitize=address")
string(JOIN ";" DEBUG_BUILD_OPTS "${DEBUG_BUILD_OPTS}"
"-O1"
"-Wno-error" # Use of -Werror is discouraged with sanitizers
# See https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html#index-fsanitize_003dbuiltin
"${ASAN_OPTS}")
set(DEBUG_LINK_OPTS "${ASAN_OPTS}")
elseif (UBSAN)
# Set DEBUG build options specific for build with UBSAN
string(JOIN ";" UBSAN_OPTS "-fsanitize=undefined"
"-fsanitize=float-divide-by-zero"
"-Wno-error" # Use of -Werror is discouraged with sanitizers
# See https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html#index-fsanitize_003dbuiltin
"-fno-sanitize=signed-integer-overflow" # Remove this when CustomRandom gets fixed
"-fno-sanitize=shift" # Remove this when CustomRandom gets fixed
"-fno-sanitize-recover=all") # For tests to fail if UBSan finds an error
string(JOIN ";" DEBUG_BUILD_OPTS "${DEBUG_BUILD_OPTS}"
"-O1"
"${UBSAN_OPTS}")
set(DEBUG_LINK_OPTS "${UBSAN_OPTS}")
else ()
# No sanitizer, just debug build
string(JOIN ";" DEBUG_BUILD_OPTS "${DEBUG_BUILD_OPTS}"
"-O0")
endif()
if (GDB_DEBUG)
add_compile_options(-ggdb3)
endif()
add_compile_options("$<$<CONFIG:Debug>:${DEBUG_BUILD_OPTS}>")
add_link_options("$<$<CONFIG:Debug>:${DEBUG_LINK_OPTS}>")
add_compile_options("$<$<CONFIG:Release>:${RELEASE_BUILD_OPTS}>")
endif()
# configuring boost
set(Boost_USE_STATIC_LIBS OFF)
find_package(Boost 1.81.0 REQUIRED COMPONENTS container thread graph CONFIG)
include_directories(${Boost_INCLUDE_DIRS})
message(${Boost_INCLUDE_DIRS})
# providing subdirectories for header inclusion
include_directories(
"src/core"
"src/core/algorithms"
"src/core/model"
"src/core/model/types"
"src/core/parser"
"src/core/util"
"src/core/config"
)
include_directories(SYSTEM "lib/easyloggingpp/src" "lib/better-enums/" "lib/emhash" "lib/atomicbitvector/include" "lib/frozen/include")
# adding submodules
if (COMPILE_TESTS)
add_subdirectory("lib/googletest")
endif()
set( CMAKE_BUILD_TYPE_COPY "${CMAKE_BUILD_TYPE}" )
set( CMAKE_BUILD_TYPE "Release" )
option(build_static_lib "Build easyloggingpp as a static library" ON)
if (PYTHON STREQUAL INSTALL)
# Relies on undocumented behaviour. EXCLUDE_FROM_ALL is used to prevent install commands
# inside the easyloggingpp CMakeLists from executing and subsequently failing with a permission error,
# making it impossible to install the Python package as a normal user.
add_subdirectory("lib/easyloggingpp" EXCLUDE_FROM_ALL)
else ()
add_subdirectory("lib/easyloggingpp")
endif ()
set( CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE_COPY} )
if (USE_LTO)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
add_subdirectory("src/core")
if (COMPILE_TESTS)
add_subdirectory("src/tests")
endif()
if (UNPACK_DATASETS)
add_subdirectory("datasets")
endif()
add_subdirectory("cfg")
if (PYTHON)
add_subdirectory("lib/pybind11")
add_subdirectory("src/python_bindings")
endif()
if (COPY_PYTHON_EXAMPLES)
add_subdirectory("examples")
endif()