forked from JuPedSim/jpsreport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
306 lines (277 loc) · 10.8 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
# Documentation: Some useful options:
# -DCMAKE_CXX_COMPILER=clang++
# -DCMAKE_BUILD_TYPE=Debug (default Release)
# -DBUILD_TESTING=ON (default OFF) for python tests
# -DBUILD_UNIT_TEST=ON (default OFF) for unit tests
################################################################################
# Project setup
################################################################################
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
project(JPSreport VERSION 0.9.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
include(helper_functions)
check_prefix_path()
enforce_build_type_is_set()
#add_clang_tidy_support_option()
################################################################################
# Optional features
################################################################################
set(BUILD_TESTING OFF CACHE BOOL "Build with integration tests")
print_var(BUILD_TESTING)
set(BUILD_UNIT_TEST OFF CACHE BOOL "Build with unit tests")
print_var(BUILD_UNIT_TEST)
set(BUILD_DOC OFF CACHE BOOL "Build doxygen documentation")
print_var(BUILD_DOC)
# Due to old OpenMP implementation in MSVC we disable OpenMP on Windows for the moment.
if(${CMAKE_SYSTEM} MATCHES "Windows")
set(USE_OPENMP Off)
message(WARNING "OpenMP is disabled on Windows")
else()
set(USE_OPENMP ON CACHE BOOL "Build with OpenMP")
endif()
print_var(USE_OPENMP)
if(POLICY CMP0069)
cmake_policy(SET CMP0069 NEW)
include(CheckIPOSupported)
check_ipo_supported(RESULT USE_IPO)
else()
set(USE_IPO ON)
endif()
################################################################################
# Compilation flags
################################################################################
# Note: Setting global compile flags via CMAKE_CXX_FLAGS has the drawback that
# generator expressions cannot be used. This leads to all kind of
# conditional adding of flags. It is generally preferable to use generator
# expresssions.
#
# WARNING: Do not break the lines, each option has to be on its own line or
# CMake will enclose multiple flags in '' which the compiler then
# treats as a single flag and does not understand.
list(APPEND COMMON_COMPILE_OPTIONS
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:-Wall>
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:-Wextra>
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:-fdiagnostics-color=always>
$<$<CXX_COMPILER_ID:MSVC>:/W2>
$<$<CXX_COMPILER_ID:MSVC>:/EHsc>
)
################################################################################
# Dependencies
################################################################################
add_subdirectory(third-party)
# libfmt
find_package(fmt 8.0 REQUIRED CONFIG)
# spdlog
find_package(spdlog 1.9 REQUIRED CONFIG)
# Boost
find_package(Boost 1.79 REQUIRED ${BOOST_COMPONENTS})
# std::filesystem needs to be linked on gcc < 9
add_library(fs INTERFACE)
target_link_libraries(fs INTERFACE
$<$<PLATFORM_ID:Linux>:stdc++fs>
)
# CMakes find module for openmp (FindOpenMP) is currently (cmake 1.15.1) broken
# in several ways:
# 1st. Version detection does only work on first cmake generation. E.g. if
# version 3.1 is found but verison 4 required cmake generation will fail
# rightfully on the first call but subsequent calls will pass, i.e. silently use
# 3.1 even though 4 was strictly required.
# See Issue: https://gitlab.kitware.com/cmake/cmake/issues/19150
#
# 2nd. FindOpenMP is broken on MacOS Mojave, it cannot find openmp at all
# currently. See Issue:https://gitlab.kitware.com/cmake/cmake/issues/18520
#
# Due to the issues mentioned above we have to do some extra work to make sure
# openmp is found. Note this does not do ANY version checking!
if(USE_OPENMP)
find_package(OpenMP REQUIRED)
else()
list(APPEND COMMON_COMPILE_OPTIONS
# Disable warnigns about omp pragmas
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:-Wno-unknown-pragmas>
)
endif()
#find_package(Threads REQUIRED)
find_package(PythonInterp 3 REQUIRED)
################################################################################
# VCS info
################################################################################
find_package(Git QUIET)
find_program(GIT_SCM git DOC "Git version control")
mark_as_advanced(GIT_SCM)
find_file(GITDIR NAMES .git PATHS ${CMAKE_SOURCE_DIR} NO_DEFAULT_PATH)
if (GIT_SCM AND GITDIR)
# the commit's SHA1, and whether the building workspace was dirty or not
# describe --match=NeVeRmAtCh --always --tags --abbrev=40 --dirty
execute_process(COMMAND
"${GIT_EXECUTABLE}" --no-pager describe --tags --always --dirty
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_SHA1
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
# branch
execute_process(
COMMAND "${GIT_EXECUTABLE}" rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# the date of the commit
execute_process(COMMAND
"${GIT_EXECUTABLE}" log -1 --format=%ad --date=local
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_DATE
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND
"${GIT_EXECUTABLE}" describe --tags --abbrev=0
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_TAG
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
# the subject of the commit
execute_process(COMMAND
"${GIT_EXECUTABLE}" log -1 --format=%s
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_COMMIT_SUBJECT
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
# remove # from subject
string(REGEX REPLACE "[\#\"]+"
"" GIT_COMMIT_SUBJECT
${GIT_COMMIT_SUBJECT})
else()
message(STATUS "Not in a git repo")
set(GIT_SHA1 "UNKNOWN")
set(GIT_DATE "UNKNOWN")
set(GIT_COMMIT_SUBJECT "UNKNOWN")
set(GIT_BRANCH "UNKNOWN")
set(GIT_TAG "UNKNOWN")
endif()
add_library(git-info INTERFACE)
target_compile_definitions(git-info INTERFACE
GIT_COMMIT_HASH="${GIT_SHA1}"
GIT_COMMIT_DATE="${GIT_DATE}"
GIT_TAG="${GIT_TAG}"
GIT_COMMIT_SUBJECT="${GIT_COMMIT_SUBJECT}"
GIT_BRANCH="${GIT_BRANCH}"
)
################################################################################
# Documentation
################################################################################
if(BUILD_DOC)
find_package(Doxygen REQUIRED)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/docs/doxygen/Doxyfile.in
${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
@ONLY
)
add_custom_target(doc
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM
)
# generate file titlepage.tex based on titlepage.tex.in
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/docs/jps_guide/titlepage.tex.in
${CMAKE_CURRENT_SOURCE_DIR}/docs/jps_guide/titlepage.tex
@ONLY
)
add_custom_target(guide
"${PYTHON_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/docs/jps_guide/make_guide.py
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/docs/jps_guide
COMMENT "Generating guide"
VERBATIM
)
endif(BUILD_DOC)
################################################################################
# Testing
##############################################################################
if(BUILD_UNIT_TEST OR BUILD_TESTING)
enable_testing()
endif()
################################################################################
# Add libraries / executables
################################################################################
add_subdirectory(src)
################################################################################
# Code formating
################################################################################
if(UNIX)
find_program(CLANG_FORMAT
NAMES
clang-format-11
clang-format
)
if(CLANG_FORMAT)
execute_process(
COMMAND ${CLANG_FORMAT} --version
OUTPUT_VARIABLE version_string
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(version_string MATCHES "^.*clang-format version .*")
string(REGEX REPLACE
"^.*clang-format version ([.0-9]+).*"
"\\1"
version
"${version_string}"
)
if(version MATCHES "^11.*")
message(STATUS "Found clang-format ${version}, add format-check and reformat targets")
set(folders src tests)
add_custom_target(check-format
COMMENT "Checking format with clang-format"
COMMAND find ${folders}
-name '*.cpp'
-o -name '*.c'
-o -name '*.h'
-o -name '*.hpp' | xargs ${CLANG_FORMAT}
-n -Werror --style=file
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
add_custom_target(reformat
COMMENT "Reformatting code with clang-format"
COMMAND find ${folders}
-name '*.cpp'
-o -name '*.c'
-o -name '*.h'
-o -name '*.hpp' | xargs ${CLANG_FORMAT}
-i --style=file
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
endif()
endif()
endif()
endif()
################################################################################
# Integration tests
################################################################################
if (BUILD_TESTING)
# Find libraries needed by python tests
find_python_library(numpy)
find_python_library(scipy)
find_python_library(pandas)
find_python_library(shapely)
add_subdirectory(tests/systemtest)
endif (BUILD_TESTING)
#################################################################################
## Packaging with CPack
#################################################################################
#include(CPackUtilities)
#IF(UNIX AND NOT APPLE)
# cpack_write_deb_config()
#endif()
#if(WIN32 AND NOT UNIX)
# cpack_write_windows_config()
#endif()
#if(APPLE)
# cpack_write_osx_config()
#endif()
#
#cpack_write_config()