-
Notifications
You must be signed in to change notification settings - Fork 35
/
CMakeLists.txt
344 lines (311 loc) · 11.9 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
cmake_minimum_required(VERSION 3.12)
project(quant VERSION 0.0.34 LANGUAGES C CXX)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# on Darwin, try and pick up dependencies from homebrew
list(APPEND CMAKE_PREFIX_PATH /opt/homebrew)
else ()
list(APPEND CMAKE_PREFIX_PATH /usr/local)
endif()
set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH ON)
# See if we have google benchmark
include(CheckCXXSymbolExists)
include(CMakePushCheckState)
include(CheckIncludeFile)
set(CMAKE_REQUIRED_LIBRARIES benchmark)
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_PREFIX_PATH}/include)
set(CMAKE_REQUIRED_LINK_OPTIONS -L${CMAKE_PREFIX_PATH}/lib)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_REQUIRED_LINK_OPTIONS -lc++ ${CMAKE_REQUIRED_LINK_OPTIONS})
endif()
check_cxx_symbol_exists(benchmark::Initialize benchmark/benchmark.h
HAVE_BENCHMARK_H)
cmake_reset_check_state()
# See if we have google gperftools
include(CheckSymbolExists)
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_PREFIX_PATH}/include)
set(CMAKE_REQUIRED_LIBRARIES profiler)
set(CMAKE_REQUIRED_LINK_OPTIONS -L${CMAKE_PREFIX_PATH}/lib)
check_symbol_exists(ProfilerStart gperftools/profiler.h HAVE_PROFILER)
cmake_reset_check_state()
link_directories(AFTER ${CMAKE_PREFIX_PATH}/lib)
find_package(OpenSSL 1.1.0 REQUIRED)
string(REGEX REPLACE "/include$" "" OPENSSL_ROOT_DIR ${OPENSSL_INCLUDE_DIR})
if("${CMAKE_SYSTEM}" MATCHES "Linux")
add_compile_definitions(_GNU_SOURCE)
endif()
# Build "Debug" type by default
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug
CACHE STRING "Set build type (default Debug)" FORCE)
endif()
# Generate compile_commands.json for clang-tidy
set(CMAKE_EXPORT_COMPILE_COMMANDS True)
# Use modern C and C++
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_C_STANDARD 11)
# Set general compile flags, if they are supported
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
set (FLAGS -pipe -Wextra -Wpedantic -Weverything -Werror
-fcolor-diagnostics -fdiagnostics-color=always -fstack-usage
-Wno-disabled-macro-expansion # clang on travis needs this
-Wno-missing-field-initializers # and this (clang-5)
-Wno-extra-semi-stmt # the kh_foreach* macros need this
-Wno-macro-redefined # because we redefine _FORTIFY_SOURCE
-Wno-covered-switch-default -Wno-missing-braces
-Wno-gnu-statement-expression -Wno-reserved-identifier
-Wno-declaration-after-statement
-Wno-deprecated-non-prototype
-fcomment-block-commands=dotfile
)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
list(APPEND FLAGS -Wno-poison-system-directories)
endif()
foreach(FLAG ${FLAGS})
string(REGEX REPLACE "[-=+]" "_" F ${FLAG})
set(C_F C_${F})
set(CXX_F CXX_${F})
check_c_compiler_flag(${FLAG} ${C_F})
if(${C_F})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAG}")
endif()
check_cxx_compiler_flag(${FLAG} ${CXX_F})
if(${CXX_F})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}")
endif()
endforeach()
# Set CXX flags
foreach(FLAG -Wno-c++98-compat -Wno-global-constructors)
string(REGEX REPLACE "[-=+]" "_" F ${FLAG})
set(CXX_F CXX_${F})
check_cxx_compiler_flag(${FLAG} ${CXX_F})
if(${CXX_F})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}")
endif()
endforeach()
# flags for "Debug" and "None" builds
set(CMAKE_C_FLAGS_DEBUG "-g3")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
# disable IPO by default
set(IPO NO)
if(CMAKE_BUILD_TYPE MATCHES Debug)
if (DSTACK)
# Check if we can instrument the code
list(APPEND CMAKE_REQUIRED_FLAGS -finstrument-functions)
check_c_source_compiles("
int main() {}
void __cyg_profile_func_enter(void *this_fn, void *call_site);
void __cyg_profile_func_enter(void *this_fn __attribute__((unused)),
void *call_site __attribute__((unused))){}
void __cyg_profile_func_exit(void *this_fn, void *call_site);
void __cyg_profile_func_exit(void *this_fn __attribute__((unused)),
void *call_site __attribute__((unused))){}
" _finstrument_functions)
cmake_reset_check_state()
endif()
add_compile_definitions(_FORTIFY_SOURCE=2)
if(NOT DEFINED ENV{CONTINUOUS_INTEGRATION} AND NOT DOCKER)
# See if we can use the address sanitizer
check_include_file(sanitizer/asan_interface.h HAVE_ASAN)
if(HAVE_ASAN AND NOT CMAKE_GENERATOR STREQUAL Xcode)
set(CMAKE_REQUIRED_FLAGS -fsanitize=address)
check_symbol_exists(__asan_address_is_poisoned
"sanitizer/asan_interface.h"
HAVE_ASAN_ADDRESS_IS_POISONED)
cmake_reset_check_state()
set(CMAKE_REQUIRED_FLAGS -fsanitize=address,undefined,leak)
check_c_compiler_flag("" C_fsanitize_address_undefined_leak)
if(C_fsanitize_address_undefined_leak)
string(CONCAT CMAKE_C_FLAGS "${CMAKE_C_FLAGS} "
"-fsanitize=address,undefined,leak")
string(CONCAT CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} "
"-fsanitize=address,undefined,leak")
endif()
unset(CMAKE_REQUIRED_FLAGS)
# Set some additional flags for Debug builds
set(FLAGS -Og -fno-omit-frame-pointer -fsanitize-address-use-after-scope
-fno-optimize-sibling-calls -fno-common
-fsanitize=unsigned-integer-overflow -fsanitize=local-bounds
-fsanitize=integer -fsanitize=nullability
-fsanitize=memory -fsanitize-memory-track-origins
-fsanitize-memory-use-after-dtor
-fno-sanitize-recover=all
)
foreach(FLAG ${FLAGS})
string(REGEX REPLACE "[-=+]" "_" F ${FLAG})
set(C_F C_${F})
set(CXX_F CXX_${F})
check_c_compiler_flag(${FLAG} ${C_F})
if(${C_F})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAG}")
endif()
check_cxx_compiler_flag(${FLAG} ${CXX_F})
if(${CXX_F})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}")
endif()
endforeach()
endif()
# add -finstrument-functions last, since it interferes with other detection
if (DSTACK)
if(_finstrument_functions)
string(CONCAT CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -finstrument-functions")
string(CONCAT CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -finstrument-functions")
add_compile_definitions(DSTACK)
else()
message(FATAL_ERROR "-finstrument-functions not supported by compiler")
endif()
endif()
find_program(CPPCHECK NAMES cppcheck)
if(CPPCHECK)
message(STATUS "Found cppcheck: ${CPPCHECK}")
set(CMAKE_C_CPPCHECK ${CPPCHECK} -q --inline-suppr
--enable=all
--suppress=duplicateValueTernary
--suppress=missingInclude
--suppress=missingIncludeSystem
--suppress=unmatchedSuppression
--suppress=unusedFunction
--error-exitcode=2
-I ${PROJECT_SOURCE_DIR}/lib/include
-I ${PROJECT_SOURCE_DIR}/lib/deps/warpcore/lib/include
)
set(CMAKE_CXX_CPPCHECK ${CMAKE_C_CPPCHECK})
endif()
# Use include-what-you-use to check #includes, if it's installed
find_program(IWYU NAMES include-what-you-use iwyu)
if(IWYU)
message(STATUS "Found include-what-you-use: ${IWYU}")
string(TOLOWER ${CMAKE_SYSTEM_NAME} CMAKE_SYSTEM_NAME_LC)
set(CMAKE_C_INCLUDE_WHAT_YOU_USE
${IWYU} -Xiwyu
--mapping_file=${PROJECT_SOURCE_DIR}/misc/${CMAKE_SYSTEM_NAME_LC}.imp)
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${CMAKE_C_INCLUDE_WHAT_YOU_USE})
endif()
if(CMAKE_C_COMPILER_ID MATCHES "Clang" AND
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Use clang-tidy for extra warnings, if it's installed
find_program(CLANGTIDY NAMES clang-tidy)
if(CLANGTIDY)
message(STATUS "Found clang-tidy: ${CLANGTIDY}")
set(CLANG_TIDY_CHECKS *
-altera-*
-bugprone-easily-swappable-parameters
-bugprone-assignment-in-if-condition,-warnings-as-errors
-bugprone-implicit-widening-of-multiplication-result
-bugprone-narrowing-conversions
-cert-err33-c
-cert-err58-cpp
-clang-diagnostic-declaration-after-statement
-clang-diagnostic-tautological-value-range-compare
-clang-diagnostic-deprecated-non-prototype
-concurrency-mt-unsafe
-cppcoreguidelines-avoid-magic-numbers
-cppcoreguidelines-avoid-non-const-global-variables
-cppcoreguidelines-init-variables
-cppcoreguidelines-macro-usage
-cppcoreguidelines-narrowing-conversions
-cppcoreguidelines-owning-memory
-cppcoreguidelines-pro-bounds-array-to-pointer-decay
-cppcoreguidelines-pro-bounds-constant-array-index
-cppcoreguidelines-pro-bounds-pointer-arithmetic
-cppcoreguidelines-pro-type-vararg
-fuchsia-default-arguments-calls
-fuchsia-statically-constructed-objects
-google-readability-braces-around-statements
-google-readability-todo
-google-runtime-references
-hicpp-braces-around-statements
-hicpp-multiway-paths-covered
-hicpp-no-array-decay
-hicpp-signed-bitwise
-hicpp-vararg
-llvmlibc-callee-namespace
-llvmlibc-implementation-in-namespace
-llvmlibc-restrict-system-libc-headers
-modernize-use-trailing-return-type
-modernize-macro-to-enum
-performance-no-int-to-ptr
-readability-braces-around-statements
-readability-function-cognitive-complexity
-readability-identifier-length
-readability-magic-numbers
-readability-misleading-indentation
-readability-suspicious-call-argument
)
string(REPLACE ";" "," CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS}")
set(CMAKE_C_CLANG_TIDY ${CLANGTIDY}
-system-headers -checks=${CLANG_TIDY_CHECKS} --warnings-as-errors=*
)
set(CMAKE_CXX_CLANG_TIDY ${CMAKE_C_CLANG_TIDY})
endif()
endif()
endif()
else()
# check for INTERPROCEDURAL_OPTIMIZATION support
# (except on older gcc where that breaks)
if(NOT CMAKE_COMPILER_IS_GNUCC
OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6.0)
include(CheckIPOSupported)
check_ipo_supported(RESULT IPO)
else()
set(IPO False)
endif()
endif()
if(APPLE AND NOT IPO)
find_program(DSYMUTIL dsymutil)
endif()
if(FUZZER)
# check if we have a fuzzer
set(CMAKE_REQUIRED_FLAGS -fsanitize=fuzzer)
check_c_compiler_flag(-fsanitize=fuzzer HAVE_FUZZER)
cmake_reset_check_state()
if(HAVE_FUZZER)
add_compile_definitions(FUZZING)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=fuzzer,address,undefined,leak")
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -fsanitize=fuzzer,address,undefined,leak")
else()
message(WARNING "No fuzzer available")
endif()
endif()
if(NOT CMAKE_BUILD_TYPE MATCHES Release AND HAVE_PROFILER)
set(CMAKE_C_STANDARD_LIBRARIES "-lprofiler")
set(CMAKE_CXX_STANDARD_LIBRARIES ${CMAKE_C_STANDARD_LIBRARIES})
endif()
# flags for "Release" builds
set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG -Ofast -march=native")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
# flags for "RelWithDebInfo" builds
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELEASE} -g3")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
# configuration defines
set (DEFINES
# FUZZER_CORPUS_COLLECTION
# MINIMAL_CIPHERS
# NO_ERR_REASONS
# NO_MIGRATION
# NO_OOO_0RTT
# NO_OOO_DATA
# NO_QINFO
# NO_QLOG
# NO_SERVER
# NO_SRT_MATCHING
# NO_TLS_LOG
# NO_ECN
)
if(NOT WITH_MINICRYPTO)
list(APPEND DEFINES WITH_OPENSSL)
if(NOT PTLS_WITH_FUSION_DEFAULT)
list(APPEND DEFINES PTLS_WITHOUT_FUSION)
endif()
endif()
if(FUZZER_CORPUS)
list(APPEND DEFINES FUZZER_CORPUS_COLLECTION)
endif()
add_subdirectory(bin)
add_subdirectory(doc)
add_subdirectory(external EXCLUDE_FROM_ALL)
add_subdirectory(lib)
add_subdirectory(misc)
enable_testing()
add_subdirectory(test)