-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
220 lines (178 loc) · 7.94 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
set(PACKAGE_VERSION_COMMITHASH "dev" CACHE STRING "git commit hash")
if(PACKAGE_VERSION_COMMITHASH STREQUAL "dev")
set(GDX_DEV_BUILD 1)
else()
set(GDX_DEV_BUILD 0)
endif()
enable_testing()
include(CTestUseLaunchers)
include(CMakeDependentOption)
include(CMakePackageConfigHelpers)
include(CheckCXXSymbolExists)
string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}" GDX_IS_TOPLEVEL)
option(GDX_ENABLE_SIMD "Build with simd support for DenseRaster (default = sse instructions)" ON)
cmake_dependent_option(GDX_AVX2 "Build with avx2 simd instructions support" OFF "GDX_ENABLE_SIMD" OFF)
option(GDX_ENABLE_OPENMP "Build without openmp acceleration support" OFF)
option(GDX_ENABLE_TOOLS "Build the gdx tools" ON)
option(GDX_ENABLE_TESTS "Build the c++ unit tests" OFF)
option(GDX_ENABLE_TEST_UTILS "Build the unit test utilities" ${GDX_ENABLE_TESTS})
option(GDX_ENABLE_BENCHMARKS "Build the micro benchmarks" OFF)
option(GDX_ENABLE_GEOMETRY "Build against geos for geometry processing" OFF)
option(GDX_PYTHON_BINDINGS "Build python bindings" OFF)
option(GDX_INSOURCE_DEPS "Use submodules for internal dependencies" ON)
option(GDX_INSTALL_DEVELOPMENT_FILES "Install the gdx development files (headers/libs)" ${GDX_IS_TOPLEVEL})
if(GDX_IS_TOPLEVEL)
option(ENABLE_ADDRESS_SANITIZER "Enable the address sanitizer" OFF)
option(ENABLE_UB_SANITIZER "Enable the undefined behavior sanitizer" OFF)
cmake_minimum_required(VERSION 3.20)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS OFF)
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/geodynamix)
project(GeoDynamiX
VERSION 0.14.5
LANGUAGES C CXX
)
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
include(GNUInstallDirs)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
message(STATUS "Gdx version: ${GDX_VERSION} (${PACKAGE_VERSION_COMMITHASH})")
message(STATUS "Unit tests: ${GDX_ENABLE_TESTS}")
message(STATUS "Address sanitizer: ${ENABLE_ADDRESS_SANITIZER}")
message(STATUS "Undefined behavior sanitizer: ${ENABLE_UB_SANITIZER}")
if(MSVC)
add_compile_options(/Zc:twoPhase- /permissive- /bigobj /w34100 /w34101 /w35038 /w34127)
# avoid windows specific warnings
add_compile_definitions(
_CRT_SECURE_NO_WARNINGS
_SCL_SECURE_NO_WARNINGS
_SILENCE_CXX17_NEGATORS_DEPRECATION_WARNING
_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING
_SILENCE_CXX17_OLD_ALLOCATOR_MEMBERS_DEPRECATION_WARNING
_SILENCE_CXX17_UNCAUGHT_EXCEPTION_DEPRECATION_WARNING
)
# Fixes warning when linking against release c library in debug mode
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:MSVCRT /NODEFAULTLIB:LIBCMT")
set(CMAKE_STATIC_LINKER_FLAGS_DEBUG "${CMAKE_STATIC_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:MSVCRT /NODEFAULTLIB:LIBCMT")
# Enable faster linking for debug builds
# set (CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /DEBUG:FASTLINK")
# set (CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /DEBUG:FASTLINK")
# set (CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG} /DEBUG:FASTLINK")
else()
add_compile_options(
-Wall -Wextra -Wpedantic -Wfatal-errors -Wno-unknown-pragmas
$<$<CXX_COMPILER_ID:GNU>:-Wno-maybe-uninitialized>
$<$<CXX_COMPILER_ID:GNU>:-fdiagnostics-color=always>
$<$<CXX_COMPILER_ID:Clang>:-fcolor-diagnostics>
)
endif()
if(NOT MSVC AND ENABLE_ADDRESS_SANITIZER)
add_compile_options($<$<CONFIG:Debug>:-O1 -fno-optimize-sibling-calls -fno-omit-frame-pointer -fsanitize=address>)
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address -fno-optimize-sibling-calls")
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address -fno-optimize-sibling-calls")
set(CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address -fno-optimize-sibling-calls")
if(${CMAKE_COMPILER_IS_GNUCXX})
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -static-libasan")
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -static-libasan")
set(CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG} -static-libasan")
endif()
endif()
if(NOT MSVC AND ENABLE_UB_SANITIZER)
add_compile_options($<$<CONFIG:Debug>:-fsanitize=undefined>)
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fsanitize=undefined")
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=undefined")
set(CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG} -fsanitize=undefined")
endif()
write_basic_package_version_file("GeodynamixConfigVersion.cmake"
VERSION ${GDX_VERSION}
COMPATIBILITY SameMajorVersion
)
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/GeodynamixConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/GeodynamixConfig.cmake
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
)
if(GDX_INSTALL_DEVELOPMENT_FILES)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/GeodynamixConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/GeodynamixConfigVersion.cmake
DESTINATION ${INSTALL_CONFIGDIR}
)
endif()
endif()
if(MINGW OR UNIX)
set(CMAKE_SHARED_LIBRARY_PREFIX "")
endif()
if(MINGW)
add_definitions("-DMINGW_HAS_SECURE_API")
endif()
if(NOT CMAKE_COMPILER_IS_GNUCXX) # gcc pstl is not compatible with recent tbb libraries
check_cxx_symbol_exists(std::execution::par "execution" GDX_HAVE_PAR_EXECUTION)
endif()
find_package(Eigen3 REQUIRED)
find_package(fmt CONFIG REQUIRED)
find_package(spdlog CONFIG REQUIRED)
if(GDX_ENABLE_GEOMETRY)
find_package(GEOS CONFIG REQUIRED)
endif()
if(GDX_ENABLE_OPENMP)
find_package(OpenMP)
endif()
message(STATUS "Gdx OpenMP support: ${OpenMP_FOUND}")
if(GDX_ENABLE_TEST_UTILS OR GDX_ENABLE_TESTS)
find_package(doctest CONFIG REQUIRED)
endif()
if(GDX_IS_TOPLEVEL)
if(GDX_INSOURCE_DEPS)
# gdx is the toplevel project so include the infra dependency
set(INFRA_LOGGING ON)
set(INFRA_GDAL ON)
set(INFRA_EMBED_GDAL_DATA OFF CACHE BOOL "")
set(INFRA_ENABLE_TESTS ${GDX_ENABLE_TESTS})
set(INFRA_ENABLE_TEST_UTILS ${GDX_ENABLE_TEST_UTILS})
set(INFRA_INSTALL_DEVELOPMENT_FILES ${GDX_INSTALL_DEVELOPMENT_FILES})
add_subdirectory(deps/infra)
else()
find_package(Infra CONFIG REQUIRED)
if(GDX_ENABLE_TEST_UTILS)
find_package(Infra CONFIG COMPONENTS testutil REQUIRED)
endif()
endif()
endif()
if(GDX_ENABLE_TEST_UTILS)
add_subdirectory(testutil)
endif()
add_subdirectory(common)
add_subdirectory(core)
add_subdirectory(algorithms)
if(GDX_PYTHON_BINDINGS)
find_package(Python3 COMPONENTS Interpreter Development.Module)
add_subdirectory(python)
add_subdirectory(test)
endif()
if(GDX_ENABLE_TOOLS)
add_subdirectory(tools)
endif()
if(GDX_ENABLE_BENCHMARKS)
find_package(benchmark REQUIRED)
add_subdirectory(benchmarks)
endif()
if(EMSCRIPTEN)
add_subdirectory(js)
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/gdxconfig.h.in ${CMAKE_BINARY_DIR}/gdx/config.h)
if(WIN32)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc @ONLY)
endif()
if(GDX_IS_TOPLEVEL AND GDX_INSTALL_DEVELOPMENT_FILES)
install(FILES ${CMAKE_BINARY_DIR}/gdx/config.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/gdx
)
install(EXPORT geodynamix-targets
FILE GeodynamixTargets.cmake
NAMESPACE geodynamix::
DESTINATION ${INSTALL_CONFIGDIR}
)
endif()
if(GDX_IS_TOPLEVEL)
add_subdirectory(dist)
endif()