-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
437 lines (391 loc) · 10.5 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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
cmake_minimum_required(VERSION 3.20)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(FATAL_ERROR "Do not build in-source. Please remove CMakeCache.txt and the CMakeFiles/ directory. Then build out-of-source.")
endif()
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
# Put the project early since modules might need to detect the compiler.
# More information https://cmake.org/cmake/help/latest/command/project.html
project(
"WikiDice" # This will exposed as the variable PROJECT_NAME.
VERSION 0.1.0 # Used for installation and defines variables PROJECT_VERSION_MAJOR, PROJECT_VERSION_MINOR, PROJECT_VERSION_PATCH, and PROJECT_VERSION_TWEAK.
LANGUAGES C CXX # Used to determine the languages to use based on file extensions
)
############################
## Modules and scripts ##
############################
# Standard CMake modules
include(CTest) # Must be called before adding tests but after calling project(). This automatically calls enable_testing() and configures ctest targets when using Make/Ninja
include(CMakeDependentOption) # This is a really useful scripts that creates options that depends on other options. It can even be used with generator expressions !
include(GNUInstallDirs) # This will define the default values for installation directories (all platforms even if named GNU)
include(InstallRequiredSystemLibraries) # Tell CMake that the `install` target needs to install required system libraries (eg: Windows SDK)
include(CMakePackageConfigHelpers) # Helper to create relocatable packages
# Custom modules and scripts
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") # Make our cmake scripts available
include(LTO)
include(Warnings)
include(CopyDllsForDebug)
include(Coverage)
###############
## OPTIONS ##
###############
find_package(Threads REQUIRED)
find_package(Python 3.11 COMPONENTS Interpreter Development REQUIRED)
# External dependencies
add_subdirectory(external)
# It is always easier to navigate in an IDE when projects are organized in folders.
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Whe building a shared library, you do not want to export all symbols by default
# gcc (and hence clang) are wrong about this.
#
# For more information, see https://gcc.gnu.org/wiki/Visibility and https://www.youtube.com/embed/m0DwB4OvDXk
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
###############
## Project ##
###############
# Check for LTO support (needs to be after project(...) )
find_lto(CXX)
# static analyzers
# find_program(CPPCHECK cppcheck REQUIRED)
# set(CMAKE_CXX_CPPCHECK ${CPPCHECK} --enable=all)
# find_program(CLANGTIDY clang-tidy REQUIRED)
# set(CMAKE_CXX_CLANG_TIDY ${CLANGTIDY})
# project
add_subdirectory(src/file_utils)
add_subdirectory(src/entities)
add_library(
cross_platform_compat
INTERFACE
)
target_sources(
cross_platform_compat
INTERFACE
src/cross_platform_endian.h
src/cross_platform_set_thread_name.h
)
add_library(
bounded_string_ring
STATIC
)
target_sources(
bounded_string_ring
PRIVATE
src/bounded_string_ring.h
src/bounded_string_ring.cc
PUBLIC
src/bounded_string_ring.h
)
target_compile_features(
bounded_string_ring
PRIVATE
cxx_std_23
)
target_compile_options(
bounded_string_ring
PRIVATE
-Wall -Wextra -Werror
)
add_library(primitive_serializer STATIC)
target_sources(
primitive_serializer
PRIVATE src/primitive_serializer.h src/primitive_serializer.cc
PUBLIC src/primitive_serializer.h
)
target_link_libraries(primitive_serializer PUBLIC absl::span cross_platform_compat)
target_compile_features(primitive_serializer PRIVATE cxx_std_23)
target_compile_options(primitive_serializer PRIVATE -Wall -Wextra -Werror)
target_link_options(primitive_serializer PRIVATE -fuse-ld=lld)
add_library(
sql_parser
STATIC
)
target_sources(
sql_parser
PRIVATE
src/sql_parser.h
src/sql_parser.cc
PUBLIC
src/sql_parser.h
)
target_link_libraries(
sql_parser
PUBLIC
file_utils
entities
bounded_string_ring
absl::log absl::check
fmt::fmt
boost_headers
absl::flat_hash_map
)
target_compile_features(
sql_parser
PRIVATE
cxx_std_23
)
target_compile_options(
sql_parser
PRIVATE
-Wall -Wextra -Werror
)
add_library(
wiki_page_table
STATIC
)
target_sources(
wiki_page_table
PRIVATE
src/wiki_page_table.h
src/wiki_page_table.cc
PUBLIC
src/wiki_page_table.h
)
target_link_libraries(
wiki_page_table
PUBLIC
entities
rocksdb-compiled
PRIVATE
absl::log absl::check
primitive_serializer
)
target_compile_features(
wiki_page_table
PRIVATE
cxx_std_23
)
target_compile_options(
wiki_page_table
PRIVATE
-Wall -Wextra -Werror
)
add_library(
category_table
STATIC
)
target_sources(
category_table
PRIVATE
src/category_table.cc
PUBLIC
src/category_table.h
)
target_link_libraries(
category_table
PUBLIC
absl::flat_hash_map
)
target_compile_features(
category_table
PRIVATE
cxx_std_23
)
target_compile_options(
category_table
PRIVATE
-Wall -Wextra -Werror
)
add_library(wikidice STATIC)
target_sources(
wikidice
PRIVATE
src/category_tree_index.h src/category_tree_index.cc
src/wikidice_query.h src/wikidice_query.cc
PUBLIC
src/category_tree_index.h
src/wikidice_query.h
)
target_compile_features(
wikidice
PRIVATE
cxx_std_23
)
# position independent code
set_target_properties(
wikidice
PROPERTIES
POSITION_INDEPENDENT_CODE ON)
target_compile_options(
wikidice
PRIVATE
-Wall -Wextra -Werror
)
target_link_libraries(
wikidice
PUBLIC
cross_platform_compat
primitive_serializer
entities
category_table
wiki_page_table
fmt::fmt Threads::Threads boost_headers
absl::flags absl::flags_parse
absl::strings absl::str_format absl::time absl::base absl::hash absl::flat_hash_map
absl::log absl::check absl::log_flags absl::log_sink absl::absl_log
absl::random_random absl::random_bit_gen_ref
absl::btree absl::flat_hash_map absl::flat_hash_set absl::node_hash_map absl::node_hash_set
absl::span
rocksdb-compiled
)
add_executable(wikidice_builder)
target_sources(
wikidice_builder
PUBLIC
src/build_category_tree.h
src/build_category_tree.cc
)
target_compile_features(wikidice_builder PRIVATE cxx_std_23)
target_compile_options(
wikidice_builder
PRIVATE
-Wall -Wextra -Werror
)
target_link_libraries(
wikidice_builder
PUBLIC
sql_parser
wikidice
fmt::fmt Threads::Threads boost_headers
absl::flags absl::flags_parse
absl::log absl::check absl::log_flags
)
add_executable(wikidice_reader src/wikidice_reader.cc)
target_compile_features(wikidice_reader PRIVATE cxx_std_23)
target_compile_options(
wikidice_reader
PRIVATE
-Wall -Wextra -Werror
-fsanitize=undefined,address -fno-omit-frame-pointer
)
target_link_options(
wikidice_reader
PRIVATE
-fsanitize=undefined,address
)
target_link_libraries(
wikidice_reader
PUBLIC
wikidice
absl::flags absl::flags_parse absl::flags_usage
absl::log absl::check absl::log_flags
absl::log_initialize
absl::flat_hash_map
fmt::fmt
)
# Python module
pybind11_add_module(pywikidice src/pywikidice.cc)
target_compile_features(pywikidice PRIVATE cxx_std_23)
target_link_libraries(pywikidice PRIVATE wikidice)
# Setup our project as the startup project for Visual so that people don't need to do it manually
set_directory_properties(PROPERTIES VS_STARTUP_PROJECT WikiDice)
#===========#
# Tests #
#===========#
include(CTest)
enable_testing()
add_executable(sql_parser_test src/sql_parser_test.cc)
target_compile_features(sql_parser_test PRIVATE cxx_std_23)
target_compile_options(
sql_parser_test
PRIVATE
-Wall -Wextra -Werror -g3
-fsanitize=undefined,address -fno-omit-frame-pointer
)
target_link_libraries(
sql_parser_test
PUBLIC
sql_parser
gtest_main gmock_main gmock
fmt::fmt
absl::log absl::check
absl::flags absl::flags_usage absl::flags_parse
)
target_link_options(
sql_parser_test
PUBLIC
-fsanitize=undefined,address
-fuse-ld=lld
)
add_executable(
category_tree_index_test
src/category_tree_index_test.cc
)
target_compile_features(category_tree_index_test PRIVATE cxx_std_23)
target_compile_options(
category_tree_index_test
PRIVATE
-Wall -Wextra -Werror -g3
-g3 -fsanitize=undefined,address -fno-omit-frame-pointer
)
target_link_options(
category_tree_index_test
PRIVATE
-fsanitize=undefined,address -fuse-ld=lld
)
target_link_libraries(
category_tree_index_test
PUBLIC
gtest_main gmock_main gmock wikidice entities category_table
absl::log
)
add_executable(primitive_serializer_test src/primitive_serializer_test.cc)
target_compile_features(primitive_serializer_test PRIVATE cxx_std_23)
target_compile_options(
primitive_serializer_test
PRIVATE
-Wall -Wextra -Werror -g3
-fsanitize=undefined,address -fno-omit-frame-pointer
)
target_link_libraries(
primitive_serializer_test
PRIVATE
primitive_serializer
gtest_main gmock_main gmock
absl::span
)
target_link_options(
primitive_serializer_test
PRIVATE
-fsanitize=undefined,address
)
add_executable(bounded_string_ring_test src/bounded_string_ring_test.cc)
target_compile_features(bounded_string_ring_test PRIVATE cxx_std_23)
target_link_libraries(
bounded_string_ring_test
PRIVATE
bounded_string_ring
gtest_main gmock_main gmock
)
target_compile_options(
bounded_string_ring_test
PRIVATE
-Wall -Wextra -Werror -g3
-fsanitize=undefined,address -fno-omit-frame-pointer
)
target_link_options(bounded_string_ring_test PRIVATE -fsanitize=undefined,address -fuse-ld=lld)
add_executable(wiki_page_table_test src/wiki_page_table_test.cc)
target_compile_features(wiki_page_table_test PRIVATE cxx_std_23)
target_link_libraries(
wiki_page_table_test
PRIVATE
wiki_page_table
gtest_main gmock_main gmock
)
target_compile_options(
wiki_page_table_test
PRIVATE
-Wall -Wextra -Werror -g3
-fsanitize=undefined,address -fno-omit-frame-pointer
)
target_link_options(
wiki_page_table_test
PRIVATE
-fsanitize=undefined,address
)
include(GoogleTest)
gtest_discover_tests(sql_parser_test)
gtest_discover_tests(category_tree_index_test)
gtest_discover_tests(bounded_string_ring_test)
gtest_discover_tests(wiki_page_table_test)