forked from motis-project/motis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
executable file
·359 lines (312 loc) · 11.3 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
cmake_minimum_required(VERSION 3.16)
project(motis C CXX ASM)
if (MSVC)
# PDB debug information is not supported by buildcache.
# Store debug info in the object files.
string(REPLACE "/Zi" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
string(REPLACE "/Zi" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
string(REPLACE "/Zi" "" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
string(REPLACE "/Zi" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
endif()
include(cmake/buildcache.cmake)
if (APPLE)
# prevents ar from invoking ranlib, let CMake do it
set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
# tell ranlib to ignore empty compilation units
set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
set(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
endif()
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
option(MOTIS_AVX "enable AVX functions" ON)
option(MOTIS_CUDA "enable CUDA functions" OFF)
if (MOTIS_CUDA)
set(MOTIS_CUDA_ARCH "-gencode arch=compute_75,code=sm_75 -gencode arch=compute_61,code=sm_61")
if (MSVC)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} ${MOTIS_CUDA_ARCH} -lcudadevrt")
else()
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} ${MOTIS_CUDA_ARCH} --compiler-options -static")
endif()
enable_language(CUDA)
endif()
option(MOTIS_LINT "enable lint (clang-tidy) target" OFF)
option(MOTIS_COV "enable coverage (coverage) target" OFF)
add_library(motis-generated INTERFACE)
target_include_directories(motis-generated INTERFACE ${CMAKE_BINARY_DIR}/generated)
set(USE_OPENMP OFF CACHE BOOL openmp FORCE)
################################
# MOTIS Version
################################
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE motis_git_branch
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND git --no-pager log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE motis_git_ref
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND git describe --always --tags --dirty=-dirty
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE motis_git_tag
OUTPUT_STRIP_TRAILING_WHITESPACE
)
configure_file (
"base/core/include/motis/core/version.h.in"
"${CMAKE_BINARY_DIR}/generated/version.h"
)
add_definitions(/DBOOST_ASIO_DISABLE_CONCEPTS=1) # fixes issue with Boost 1.72.0
################################
# Dependencies
################################
if (MSVC)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME ON)
endif()
find_package(Boost 1.70.0 REQUIRED COMPONENTS system filesystem regex program_options thread)
find_package(Threads)
link_directories(${Boost_LIBRARY_DIRS})
include_directories(SYSTEM ${Boost_INCLUDE_DIR})
include(cmake/pkg.cmake)
add_subdirectory(modules/ris/gtfsrtpb)
################################
# Basic Compiler Flags
################################
if (NOT MSVC)
set(MOTIS_CXX_FLAGS -std=c++17 -Wall -Wextra -Wno-sign-compare)
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
set(MOTIS_CXX_FLAGS ${MOTIS_CXX_FLAGS} -Wno-maybe-uninitialized -Wno-unused-but-set-parameter)
endif()
if (MOTIS_COV)
set(MOTIS_CXX_FLAGS ${MOTIS_CXX_FLAGS} --coverage)
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} --coverage)
endif()
endif()
# Quickfix for GCC 7
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive -Wno-implicit-fallthrough")
endif()
# Quickfix for MSVC
if (MSVC)
set(MOTIS_COMPILE_DEFINITIONS
BOOST_THREAD_USE_LIB
WIN32_LEAN_AND_MEAN
_HAS_AUTO_PTR_ETC
_USE_MATH_DEFINES
NOMINMAX
${MOTIS_COMPILE_DEFINITIONS})
endif()
# MOTIS Compile Definitions
if (MOTIS_CUDA)
set(MOTIS_COMPILE_DEFINITIONS MOTIS_CUDA ${MOTIS_COMPILE_DEFINITIONS})
endif()
if (MOTIS_AVX)
set(MOTIS_COMPILE_DEFINITIONS MOTIS_AVX ${MOTIS_COMPILE_DEFINITIONS})
if (MSVC)
set(MOTIS_CXX_FLAGS ${MOTIS_CXX_FLAGS} /arch:AVX)
else()
set(MOTIS_CXX_FLAGS ${MOTIS_CXX_FLAGS} -mavx)
endif()
endif()
################################
# Linter
################################
option(MOTIS_LINT "Run clang-tidy with the compiler." OFF)
if(MOTIS_LINT)
# clang-tidy will be run on all targets defined hereafter
set(MOTIS_SCHEDULE_MODE "raw")
add_definitions(-DMOTIS_LINT=1)
include(cmake/clang-tidy.cmake)
endif()
################################
# MOTIS
################################
add_subdirectory(base/data EXCLUDE_FROM_ALL)
add_subdirectory(base/core EXCLUDE_FROM_ALL)
add_subdirectory(base/loader EXCLUDE_FROM_ALL)
add_subdirectory(base/module EXCLUDE_FROM_ALL)
file(GLOB all-modules RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/modules ${CMAKE_CURRENT_SOURCE_DIR}/modules/*)
list(REMOVE_ITEM all-modules ".DS_Store")
string(REPLACE ";" " " modules-option "${all-modules}")
set(MODULES ${modules-option} CACHE STRING "Modules to load")
if(MODULES STREQUAL "all")
set(modules ${all-modules})
else()
string(REPLACE " " ";" modules "${MODULES}")
endif()
set(module-targets "")
set(module-test-files "")
foreach(module ${modules})
add_subdirectory(modules/${module})
list(APPEND module-targets "motis-${module}")
list(APPEND module-test-files "modules/${module}/*_test.cc")
list(APPEND module-itest-files "modules/${module}/*_itest.cc")
endforeach(module)
add_subdirectory(base/bootstrap EXCLUDE_FROM_ALL)
add_subdirectory(base/launcher)
################################
# Tests
################################
configure_file (
${CMAKE_CURRENT_SOURCE_DIR}/test/test_dir.h.in
${CMAKE_BINARY_DIR}/generated/test_dir.h
)
file(GLOB_RECURSE motis-test-files test/src/*.cc)
file(GLOB_RECURSE motis-modules-test-files ${module-test-files})
file(GLOB_RECURSE motis-base-test-files base/*_test.cc)
file(GLOB_RECURSE motis-loader-test-files base/loader/*_test.cc)
set_source_files_properties(${motis-loader-test-files} PROPERTIES COMPILE_DEFINITIONS FLATBUFFERS_64=1)
add_executable(motis-test EXCLUDE_FROM_ALL
${motis-test-files}
${motis-modules-test-files}
${motis-base-test-files}
)
target_include_directories(motis-test PRIVATE test/include)
if (MSVC)
target_compile_features(motis-test PUBLIC cxx_std_20)
endif()
list(FIND modules "path" MOTIS_PATH_MODULE_ENABLE)
if(${MOTIS_PATH_MODULE_ENABLE} GREATER -1)
set(motis-test-extra-dependencies "motis-path-prepare")
endif()
target_compile_options(motis-test PRIVATE ${MOTIS_CXX_FLAGS})
target_compile_definitions(motis-test PRIVATE ${MOTIS_COMPILE_DEFINITIONS})
target_link_libraries(motis-test
${module-targets}
${motis-test-extra-dependencies}
motis-bootstrap
motis-core
motis-loader
motis-module
conf
ianatzdb-res
${Boost_LIBRARIES}
)
target_link_libraries(motis-test gtest gtest_main)
################################
# Integration Tests
################################
configure_file (
${CMAKE_CURRENT_SOURCE_DIR}/test/test_dir.h.in
${CMAKE_BINARY_DIR}/generated/test_dir.h
)
file(GLOB_RECURSE motis-modules-itest-files ${module-itest-files})
file(GLOB_RECURSE motis-base-itest-files base/*_itest.cc)
add_executable(motis-itest EXCLUDE_FROM_ALL
${motis-test-files}
${motis-modules-itest-files}
${motis-base-itest-files})
target_include_directories(motis-itest PRIVATE test/include)
if (MSVC)
target_compile_features(motis-itest PUBLIC cxx_std_20)
endif()
target_compile_options(motis-itest PRIVATE ${MOTIS_CXX_FLAGS})
target_compile_definitions(motis-itest PRIVATE ${MOTIS_COMPILE_DEFINITIONS})
target_link_libraries(motis-itest
${module-targets}
motis-bootstrap
motis-core
motis-loader
motis-module
conf
ianatzdb-res
${Boost_LIBRARIES}
)
target_link_libraries(motis-itest gtest gtest_main)
set_target_properties(motis-itest PROPERTIES VS_DEBUGGER_COMMAND_ARGUMENTS "--gtest_filter=\"ris_gtfsrt_cancel_message_itest_t0.before_cancel\"")
################################
# Lint (oclint)
################################
add_custom_target(oclint
find
./modules/routing/ ./modules/guesser/ ./modules/osrm/ ./base/
-type f
-name "*.cc"
! -name "*test*"
-print0
|
xargs
-0
oclint
-enable-global-analysis
-p ${CMAKE_CURRENT_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Running oclint"
VERBATIM
)
add_dependencies(oclint motis motis-test motis-itest)
if (TARGET motis-eval)
add_dependencies(oclint motis-eval)
endif()
################################
# clang-format check
################################
find_program(CLANG_FORMAT_COMMAND NAMES clang-format clang-format-9)
add_custom_target(format-check
COMMAND find
${CMAKE_CURRENT_SOURCE_DIR}/base
${CMAKE_CURRENT_SOURCE_DIR}/modules
${CMAKE_CURRENT_SOURCE_DIR}/test
-type f
(
-name "*.cc"
-o
-name "*.h"
)
-print0
| xargs -0 ${CLANG_FORMAT_COMMAND} -i
COMMAND git status --porcelain
COMMAND git status --porcelain | xargs -I {} -0 test -z \"{}\"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Checking source code formatting"
VERBATIM
)
################################
# coverage report
################################
if (MOTIS_COV)
set(LCOV_OPTS "")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(LCOV_OPTS "--gcov-tool=${CMAKE_CURRENT_SOURCE_DIR}/tools/llvm-gcov.sh")
endif()
add_custom_target(coverage
# clean previous files
rm -rf ./combined_coverage ./motis-test_coverage ./motis-itest_coverage
COMMAND rm -f combined-test.info motis-test.info motis-itest.info
COMMAND find . -name "*.gcda" -delete
# combined (motis-test + motis-itest)
COMMAND lcov --base-directory . --directory . --zerocounters -q
COMMAND ./motis-test
COMMAND ./motis-itest
COMMAND lcov ${LCOV_OPTS} --base-directory . --directory . -c -o combined-test.info
COMMAND lcov --remove combined-test.info "/usr*" -o combined-test.info
COMMAND lcov --remove combined-test.info "/external_lib*" -o combined-test.info
COMMAND lcov --remove combined-test.info "/test/*" -o combined-test.info
COMMAND genhtml -o combined_coverage -t "motis-test + motis-itest" --num-spaces 4 combined-test.info
# only motis-test
COMMAND lcov --base-directory . --directory . --zerocounters -q
COMMAND ./motis-test
COMMAND lcov ${LCOV_OPTS} --base-directory . --directory . -c -o motis-test.info
COMMAND lcov --remove motis-test.info "/usr*" -o motis-test.info
COMMAND lcov --remove motis-test.info "/external_lib*" -o motis-test.info
COMMAND lcov --remove motis-test.info "/test/*" -o motis-test.info
COMMAND genhtml -o motis-test_coverage -t "motis-test" --num-spaces 4 motis-test.info
# only motis-itest
COMMAND lcov --base-directory . --directory . --zerocounters -q
COMMAND ./motis-itest
COMMAND lcov ${LCOV_OPTS} --base-directory . --directory . -c -o motis-itest.info
COMMAND lcov --remove motis-itest.info "/usr*" -o motis-itest.info
COMMAND lcov --remove motis-itest.info "/external_lib*" -o motis-itest.info
COMMAND lcov --remove motis-itest.info "/test/*" -o motis-itest.info
COMMAND genhtml -o motis-itest_coverage -t "motis-itest" --num-spaces 4 motis-itest.info
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating coverage report"
VERBATIM
)
add_dependencies(coverage motis-test motis-itest)
endif()