-
Notifications
You must be signed in to change notification settings - Fork 24
/
CMakeLists.txt
392 lines (287 loc) · 13.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
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
set(LIB_NAME saiga)
set(LIB_EXPORT saiga-export)
set (SAIGA_VERSION_MAJOR 1)
set (SAIGA_VERSION_MINOR 3)
set (SAIGA_VERSION_PATCH 2)
set(SAIGA_VERSION ${SAIGA_VERSION_MAJOR}.${SAIGA_VERSION_MINOR}.${SAIGA_VERSION_PATCH})
project(Saiga VERSION ${SAIGA_VERSION} LANGUAGES C CXX)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake" ${CMAKE_MODULE_PATH} )
include(helper_macros)
# Turn on the ability to create folders to organize projects (.vcproj)
# It creates "CMakePredefinedTargets" folder by default and adds CMake
# defined projects like INSTALL.vcproj and ZERO_CHECK.vcproj
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
enable_testing()
############# Build Options ###############
message(STATUS "\nBuild Options")
#option (SAIGA_BUILD_SHARED "Build this library as a shared library" ON)
OptionsHelper (SAIGA_BUILD_SHARED "Build this library as a shared library" ON)
OptionsHelper (SAIGA_DEBUG "alot of error checks and more console output" OFF)
OptionsHelper (SAIGA_ASSERTS "enable the SAIGA_ASSERT makro" ON)
OptionsHelper (SAIGA_BUILD_SAMPLES "build samples" ON)
OptionsHelper (SAIGA_BUILD_TESTS "build tests" ON)
OptionsHelper (SAIGA_STRICT_FP "strict ieee floating point" OFF)
OptionsHelper (SAIGA_FAST_MATH "enable fast-math compiler flag" OFF)
OptionsHelper (SAIGA_FULL_OPTIMIZE "finds and enables all possible optimizations" OFF)
OptionsHelper (SAIGA_ARCHNATIVE "adds the -march=native compile flag" ON)
OptionsHelper (SAIGA_CUDA_DEBUG "enables CUDA_SYNC_CHECK_ERROR and CUDA_ASSERT" ON)
OptionsHelper (SAIGA_CUDA_BLSP "enables cublas and cusparse" OFF)
OptionsHelper (SAIGA_CUDA_RDC "cuda relocateable device code" OFF)
OptionsHelper (SAIGA_CUDA_WITH_NVTOOLS "Enable the cuda nv tools" OFF)
OptionsHelper(SAIGA_BUILD_DOC "Build documentation" OFF)
OptionsHelper(SAIGA_NO_INSTALL "The build directory can be used for external projects." OFF)
OptionsHelper(SAIGA_LEGACY_GLM "Use GLM instead of eigen. This feature will be removed in the near future" OFF)
OptionsHelper(SAIGA_PCH "Generate a precompiled header" OFF)
OptionsHelper(SAIGA_OPENMP "Enable OPENMP" ON)
OptionsHelper(SAIGA_LIBSTDCPP "Use the GCC std lib for the clang compiler" OFF)
OptionsHelper(SAIGA_DEBUG_ASAN "Enable the address sanitizer. Does not work in combination with TSAN." OFF)
OptionsHelper(SAIGA_DEBUG_MSAN "Enable the memory sanitizer. Does not work in combination with TSAN." OFF)
OptionsHelper(SAIGA_DEBUG_TSAN "Enable the thread sanitizer. Does not work in combination with ASAN." OFF)
OptionsHelper(SAIGA_DEBIAN_BUILD "Saiga is currently build into a Debian Package. This will overwrite a lot of compile flags." OFF)
#OptionsHelper (SAIGA_CUDA_ARCH "Compile for a specific CUDA Arch. If empty the systems Arch is used. Example: \"7.5;8.0;8.6;8.6+PTX\"" "")
set(SAIGA_CUDA_ARCH "" CACHE STRING "Compile for a specific CUDA Arch. If empty the systems Arch is used. Example: \"7.5;8.0;8.6;8.6+PTX\"")
OptionsHelper(SAIGA_BUILD_GLFW "Build the GLFW as a submodule" ON)
OptionsHelper(SAIGA_GLFW_STATIC "Use static linking of the glfw library" OFF)
OptionsHelper(SAIGA_MODULE_CORE "Build the core module, if possible." ON)
OptionsHelper(SAIGA_MODULE_OPENGL "Build the opengl module, if possible." ON)
OptionsHelper(SAIGA_MODULE_VULKAN "Build the vulkan module, if possible." ON)
OptionsHelper(SAIGA_MODULE_VISION "Build the vision module, if possible." ON)
OptionsHelper(SAIGA_MODULE_CUDA "Build the cuda module, if possible." ON)
OptionsHelper(SAIGA_WITH_GTEST "Include the GTEST library, if possible." ON)
OptionsHelper(SAIGA_WITH_ASSIMP "Include the ASSIMP library, if possible." ON)
OptionsHelper(SAIGA_WITH_LIBZIP "Include the libzip library, if possible." ON)
OptionsHelper(SAIGA_WITH_MKL "Include the MKL library, if possible." OFF)
OptionsHelper(SAIGA_WITH_FFMPEG "Include the FFMPEG library, if possible." ON)
OptionsHelper(SAIGA_WITH_FREETYPE "Include the Freetype library, if possible." ON)
OptionsHelper(SAIGA_WITH_FREEIMAGE "Include the Freeimage library, if possible." ON)
OptionsHelper(SAIGA_WITH_TINYTIFF "Include the TinyTIFF library, if possible." OFF)
OptionsHelper(SAIGA_WITH_LIBTIFF "Include the libtiff library, if possible." ON)
OptionsHelper(SAIGA_WITH_YAMLCPP "Include the yaml-cpp library, if possible." ON)
OptionsHelper(SAIGA_WITH_OPENAL "Include the OPENAL and other Sound libraries, if possible." ON)
OptionsHelper(SAIGA_WITH_OPENMESH "Include the openmesh library, if possible." ON)
OptionsHelper(SAIGA_WITH_G2O "Include the openmesh library, if possible." ON)
OptionsHelper(SAIGA_WITH_CHOLMOD "Include the openmesh library, if possible." ON)
OptionsHelper(SAIGA_WITH_OPENNI "Include the openmesh library, if possible." ON)
OptionsHelper(SAIGA_WITH_K4A "Include the openmesh library, if possible." ON)
OptionsHelper(SAIGA_WITH_BULLET "Include the openmesh library, if possible." OFF)
OptionsHelper(SAIGA_WITH_OPENVR "Include the openmesh library, if possible." ON)
OptionsHelper(SAIGA_WITH_OPENCV "Include the opencv library, if possible." OFF)
OptionsHelper(SAIGA_WITH_TINY_EIGEN "Use the tiny-eigen library instead of the real Eigen" OFF)
if(SAIGA_DEBIAN_BUILD)
# Force release mode for package builds
# Debug info will make the files too big.
set(CMAKE_BUILD_TYPE Release)
set(SAIGA_ARCHNATIVE OFF)
set(SAIGA_FULL_OPTIMIZE OFF)
endif()
DefaultBuildType(RelWithDebInfo)
add_definitions()
set(EXTERNAL_DIR ${PROJECT_SOURCE_DIR}/External)
############# OUTPUT ###############
set(SAIGA_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}")
# Make to cache variable so it can be overwritten by the user of saiga
#set(SAIGA_RUNTIME_OUTPUT_DIRECTORY "${SAIGA_OUTPUT_DIR}/bin" CACHE PATH "Output dir of executables and dynamic libraries")
#set(SAIGA_LIBRARY_OUTPUT_DIRECTORY "${SAIGA_OUTPUT_DIR}/lib" CACHE PATH "Output dir of static libraries")
#set(SAIGA_ARCHIVE_OUTPUT_DIRECTORY "${SAIGA_OUTPUT_DIR}/lib" CACHE PATH "Output dir of static libraries")
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${SAIGA_RUNTIME_OUTPUT_DIRECTORY}")
#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${SAIGA_LIBRARY_OUTPUT_DIRECTORY}")
#set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${SAIGA_ARCHIVE_OUTPUT_DIRECTORY}")
############# COMPILER FLAGS ###############
include(Saiga_compiler_flags)
####### Dependencies #######
# Build Submodules first
unset(MODULE_CORE)
unset(MODULE_CUDA)
unset(MODULE_EXTRA)
unset(MODULE_OPENGL)
unset(MODULE_VISION)
unset(MODULE_VULKAN)
if(SAIGA_MODULE_CORE)
include (Dependencies_core)
endif()
if(MODULE_CORE)
if(SAIGA_MODULE_OPENGL)
include (Dependencies_opengl)
endif()
if(SAIGA_MODULE_VISION AND NOT SAIGA_WITH_TINY_EIGEN)
include (Dependencies_vision)
endif()
if(SAIGA_MODULE_VULKAN)
include (Dependencies_vulkan)
endif()
if(SAIGA_MODULE_CUDA)
include (Dependencies_cuda)
endif()
endif()
unset(PACKAGE_INCLUDES)
unset(LIB_TARGETS)
unset(LIBS)
############# INSTALL PATHS ###############
#This part is partly copied from the CMakeLists.txt of glbinding.
#If a relative path is given it is interpreted relative to the value of the CMAKE_INSTALL_PREFIX variable.
#if(UNIX)
set(INSTALL_INCLUDE "include/${LIB_NAME}")
set(INSTALL_BIN "bin")
set(INSTALL_SHARED "lib")
set(INSTALL_LIB "lib")
set(INSTALL_SHARE "share/${LIB_NAME}")
set(INSTALL_SHADER "share/${LIB_NAME}/shader")
set(INSTALL_DOC "share/${LIB_NAME}/doc")
set(INSTALL_SAMPLES "share/${LIB_NAME}/bin")
message(STATUS "\nCompiler Flags:")
message(STATUS "SAIGA_CXX_FLAGS: ${SAIGA_CXX_FLAGS}")
message(STATUS "SAIGA_PRIVATE_CXX_FLAGS: ${SAIGA_PRIVATE_CXX_FLAGS}")
message(STATUS "SAIGA_LD_FLAGS: ${SAIGA_LD_FLAGS}")
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
message(STATUS "CMAKE_CXX_FLAGS_DEBUG: ${CMAKE_CXX_FLAGS_DEBUG}")
message(STATUS "CMAKE_CXX_FLAGS_RELWITHDEBINFO: ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
message(STATUS "CMAKE_CXX_FLAGS_RELEASE: ${CMAKE_CXX_FLAGS_RELEASE}")
if(CUDA_FOUND)
message(STATUS "\nCUDA Compiler Flags:")
message(STATUS "CMAKE_CUDA_FLAGS: ${CMAKE_CUDA_FLAGS}")
message(STATUS "CMAKE_CUDA_FLAGS_DEBUG: ${CMAKE_CUDA_FLAGS_DEBUG}")
message(STATUS "CMAKE_CUDA_FLAGS_RELWITHDEBINFO: ${CMAKE_CUDA_FLAGS_RELWITHDEBINFO}")
message(STATUS "CMAKE_CUDA_FLAGS_RELEASE: ${CMAKE_CUDA_FLAGS_RELEASE}")
endif()
############# Generate config file ###############
set(SAIGA_PROJECT_SOURCE_DIR ${PROJECT_SOURCE_DIR})
set(SAIGA_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} )
if(SAIGA_DEBIAN_BUILD)
# Note during a debian build the actual install dir is something like /libsaiga0.0.8/debian/tmp/usr
# We set it here to /usr so the programs can find the shader later.
set(SAIGA_INSTALL_PREFIX /usr)
# The source is not included in the final package
set(SAIGA_PROJECT_SOURCE_DIR "-")
endif()
if(SAIGA_NO_INSTALL)
set(SAIGA_SHADER_PREFIX "${PROJECT_SOURCE_DIR}/shader")
set(SAIGA_INCLUDE_INSTALL_PREFIX "${PROJECT_SOURCE_DIR}/src")
set(SAIGA_LIB_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/bin")
set(SAIGA_BUILD_INCLUDE_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/include")
set(SAIGA_INSTALL_PREFIX "-")
set(SAIGA_CONFIG_CMAKE_FILE_NO_INSTALL "${CMAKE_CURRENT_BINARY_DIR}/SAIGAConfig.cmake")
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/SAIGAConfigNoInstall.cmake.in"
"${SAIGA_CONFIG_CMAKE_FILE_NO_INSTALL}"
@ONLY
)
else()
set(SAIGA_SHADER_PREFIX "${SAIGA_INSTALL_PREFIX}/share/saiga/shader")
set(SAIGA_INCLUDE_INSTALL_PREFIX "${SAIGA_INSTALL_PREFIX}/include")
set(SAIGA_BUILD_INCLUDE_INSTALL_PREFIX "${SAIGA_INSTALL_PREFIX}/include")
set(SAIGA_LIB_INSTALL_PREFIX "${SAIGA_INSTALL_PREFIX}/lib")
endif()
STRING(REGEX REPLACE "\\\\" "/" SAIGA_SHADER_PREFIX ${SAIGA_SHADER_PREFIX} )
STRING(REGEX REPLACE "\\\\" "/" SAIGA_INSTALL_PREFIX ${SAIGA_INSTALL_PREFIX} )
## Generate source file with git commit
include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC SAIGA_GIT_SHA1)
set(SAIGA_BUILDCONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}/include")
set(SAIGA_BUILDCONFIG_FILE "${SAIGA_BUILDCONFIG_DIR}/saiga/saiga_buildconfig.h")
set(SAIGA_MODULES_FILE "${SAIGA_BUILDCONFIG_DIR}/saiga/saiga_modules.h")
set(SAIGA_GIT_FILE "${SAIGA_BUILDCONFIG_DIR}/saiga/saiga_git_sha1.h")
set(SAIGA_CONFIGURED_FILES ${SAIGA_BUILDCONFIG_FILE} ${SAIGA_MODULES_FILE} ${SAIGA_GIT_FILE})
#INCLUDE_DIRECTORIES(${SAIGA_BUILDCONFIG_DIR})
configure_file (
"${CMAKE_CURRENT_SOURCE_DIR}/src/${LIB_NAME}/saiga_buildconfig.h.in"
"${SAIGA_BUILDCONFIG_FILE}"
)
configure_file (
"${CMAKE_CURRENT_SOURCE_DIR}/src/${LIB_NAME}/saiga_modules.h.in"
"${SAIGA_MODULES_FILE}"
)
configure_file (
"${CMAKE_CURRENT_SOURCE_DIR}/src/${LIB_NAME}/saiga_git_sha1.h.in"
"${SAIGA_GIT_FILE}"
@ONLY
)
set(SAIGA_CONFIG_CMAKE_FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/SAIGAConfig.cmake")
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/SAIGAConfig.cmake.in"
"${SAIGA_CONFIG_CMAKE_FILE}"
@ONLY
)
# Generate Version File
set(SAIGA_VERSION_CMAKE_FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/SAIGAConfigVersion.cmake")
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${SAIGA_VERSION_CMAKE_FILE}
VERSION ${SAIGA_VERSION}
COMPATIBILITY AnyNewerVersion
)
############# SOURCE ###############
add_subdirectory(src)
add_subdirectory(shader)
if(SAIGA_BUILD_SAMPLES)
message(STATUS " ")
add_subdirectory(samples)
message(STATUS " ")
else()
message(STATUS "\nNo samples.")
endif()
if(SAIGA_BUILD_TESTS)
message(STATUS " ")
set(GTEST_TARGETS gtest gtest_main)
add_subdirectory(tests)
message(STATUS " ")
else()
message(STATUS "\nNo tests.")
endif()
#set_target_properties (saiga PROPERTIES FOLDER lib)
############# INSTALL ###############
#install config file to share/
install(
FILES "${SAIGA_CONFIG_CMAKE_FILE}" "${SAIGA_VERSION_CMAKE_FILE}"
DESTINATION ${INSTALL_SHARE}
)
#install buildconfig include/
install(
FILES "${SAIGA_BUILDCONFIG_FILE}"
DESTINATION ${INSTALL_INCLUDE}
)
install(
FILES "${SAIGA_MODULES_FILE}"
DESTINATION ${INSTALL_INCLUDE}
)
install(
DIRECTORY ./src/saiga/
DESTINATION ${INSTALL_INCLUDE}
FILES_MATCHING PATTERN "*.h"
PATTERN "*.inl"
PATTERN "*.hpp"
)
############# UNINSTALL ###############
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/uninstall.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake/uninstall.cmake
IMMEDIATE @ONLY)
add_custom_target(uninstall_saiga
COMMAND ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_BINARY_DIR}/cmake/uninstall.cmake)
set_target_properties(uninstall_saiga PROPERTIES FOLDER CMakePredefinedTargets)
############# Doxygen ###############
# first we can indicate the documentation build as an option and set it to ON by default
# check if Doxygen is installed
find_package(Doxygen)
if (DOXYGEN_FOUND AND SAIGA_BUILD_DOC)
# set input and output files
set(DOXYGEN_IN ${CMAKE_CURRENT_LIST_DIR}/docs/Doxyfile.in)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
set(DOXYGEN_MAIN ${CMAKE_CURRENT_LIST_DIR}/docs/main.md)
# request to configure the file
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
message(STATUS "Doxygen found. Generate with 'make saiga_doc'.")
# note the option ALL which allows to build the docs together with the application
add_custom_target( saiga_doc
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM )
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html)
install(
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html
DESTINATION ${INSTALL_DOC}
FILES_MATCHING PATTERN "*"
)
endif()