-
Notifications
You must be signed in to change notification settings - Fork 7
/
CMakeLists.txt
342 lines (271 loc) · 9.31 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
cmake_minimum_required(VERSION 3.16)
project(rmagine
LANGUAGES CXX C
VERSION 2.2.9)# TODO update this version when merging into main-branch
option(BUILD_TOOLS "Build tools" ON)
option(BUILD_TESTS "Build tests" ON)
option(BUILD_EXAMPLES "Build examples" OFF)
option(BUILD_DOCS "Build documentation" OFF)
include(GNUInstallDirs)
set(rmagine_DEFINITIONS "-DRMAGINE_VERSION=\"${rmagine_VERSION}\"")
list(APPEND rmagine_DEFINITIONS "-DRMAGINE_VERSION_MAJOR=${rmagine_VERSION_MAJOR}")
list(APPEND rmagine_DEFINITIONS "-DRMAGINE_VERSION_MINOR=${rmagine_VERSION_MINOR}")
list(APPEND rmagine_DEFINITIONS "-DRMAGINE_VERSION_PATCH=${rmagine_VERSION_PATCH}")
## Compile as C++11, supported in ROS Kinetic and newer
add_compile_options(-std=c++17)
set(CMAKE_CXX_STANDARD 17)
message(STATUS "CMake Version: ${CMAKE_VERSION}")
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.9)
message(STATUS ">= 3.9 - Enabling Link Time Optimization")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
# DEFAULT RELEASE
if (NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
endif()
endif()
set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS ON)
set_property(GLOBAL PROPERTY USE_FOLDERS 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_TMP_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tmp)
set(CMAKE_MODULE_PATH
${rmagine_SOURCE_DIR}/cmake
${CMAKE_MODULE_PATH}
)
# printing in color
if(NOT WIN32)
string(ASCII 27 Esc)
set(ColourReset "${Esc}[m")
set(ColourBold "${Esc}[1m")
set(Red "${Esc}[31m")
set(Green "${Esc}[32m")
set(Yellow "${Esc}[33m")
set(Blue "${Esc}[34m")
set(Magenta "${Esc}[35m")
set(Cyan "${Esc}[36m")
set(White "${Esc}[37m")
set(BoldRed "${Esc}[1;31m")
set(BoldGreen "${Esc}[1;32m")
set(BoldYellow "${Esc}[1;33m")
set(BoldBlue "${Esc}[1;34m")
set(BoldMagenta "${Esc}[1;35m")
set(BoldCyan "${Esc}[1;36m")
set(BoldWhite "${Esc}[1;37m")
endif()
################################
## REQUIRED DEPS
find_package(Boost REQUIRED)
find_package(Eigen3 REQUIRED)
############################
## EMBREE: CPU Raycasting ##
############################
# supported Embree VERSIONS: Embree 4 (Tested until versio 4.2)
find_package(embree 4)
if(embree_FOUND)
# NO INCLUDE?
if(NOT embree_LIBRARY)
if(EMBREE_LIBRARY)
set(embree_LIBRARY ${EMBREE_LIBRARY})
elseif(Embree_LIBRARY)
set(embree_LIBRARY ${Embree_LIBRARY})
else()
set(embree_LIBRARY embree)
endif()
endif()
else()
message(STATUS "Embree not found")
endif(embree_FOUND)
####################
## ASSIMP: MeshIO ##
####################
find_package(assimp REQUIRED)
#######################
## OpenMP: Threading ##
#######################
find_package(OpenMP REQUIRED)
if(OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif(OPENMP_FOUND)
########################################
## Optional Deps
# for ouster config loading
find_package(PkgConfig REQUIRED)
pkg_check_modules(JSONCPP jsoncpp)
if(TARGET PkgConfig::jsoncpp) # for downwards compatibility
set(JSONCPP_INCLUDDE_DIRS "")
set(JSONCPP_LIBRARIES PkgConfig::jsoncpp)
endif()
######################################
## CUDA: For Optix ##
######################################
# I am aware find_package(CUDA) is deprecated.
# - TODO: support find_package(CUDAToolkit) as well
# -- Example: https://github.com/ceres-solver/ceres-solver/blob/master/CMakeLists.txt
# - TODO: this becomes quite messy. make a seperate file from this
# default flags are not set when including cuda
if (NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt)
if(NOT CUDA_NVCC_FLAGS_DEBUG)
set(CUDA_NVCC_FLAGS_DEBUG "-g" CACHE STRING "" FORCE)
endif()
if(NOT CUDA_NVCC_FLAGS_MINSIZEREL)
set(CUDA_NVCC_FLAGS_MINSIZEREL "-Os -DNDEBUG" CACHE STRING "" FORCE)
endif()
if(NOT CUDA_NVCC_FLAGS_RELEASE)
set(CUDA_NVCC_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "" FORCE)
endif()
if(NOT CUDA_NVCC_FLAGS_RELWITHDEBINFO)
set(CUDA_NVCC_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG" CACHE STRING "" FORCE)
endif()
endif()
# set(CUDA_STANDARD 14)
include(CheckLanguage)
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
message(STATUS "Cuda language available!")
find_package(CUDAToolkit QUIET)
if(CUDAToolkit_FOUND)
message(STATUS "Found Cuda Toolkit!")
enable_language(CUDA)
set(CUDA_FOUND True)
set(CUDA_LIBRARIES CUDA::cudart)
set(CUDA_cusolver_LIBRARY CUDA::cusolver)
set(CUDA_cublas_LIBRARY CUDA::cublas)
set(CUDA_DRIVER_LIBRARY CUDA::cuda_driver)
set(CUDA_INCLUDE_DIRS "") # is in target instead
else()
find_package(CUDA)
if(CUDA_FOUND)
message(STATUS "Found Cuda!")
enable_language(CUDA)
set(CUDA_DRIVER_LIBRARY cuda)
else()
message(STATUS "Neither CudaToolkit nor CUDA found!")
endif(CUDA_FOUND)
endif(CUDAToolkit_FOUND)
endif(CMAKE_CUDA_COMPILER)
######################################
## OptiX: RTX Raycasting ##
######################################
find_package(OptiX)
if(OptiX_FOUND)
list(APPEND rmagine_DEFINITIONS "-DRMAGINE_WITH_OPTIX")
endif()
###########
## Build ##
###########
## Specify additional locations of header files
## Your package locations should be listed before other locations
# include_directories(
# include
# )
add_definitions(${rmagine_DEFINITIONS})
set(RMAGINE_LIBRARIES)
set(RMAGINE_STATIC_LIBRARIES)
### RMAGINE CORE LIB
add_subdirectory(src/rmagine_core)
### RMAGINE OUSTER LIB
if(JSONCPP_FOUND)
add_subdirectory(src/rmagine_ouster)
endif(JSONCPP_FOUND)
### RMAGINE EMBREE LIB
if(embree_FOUND)
add_subdirectory(src/rmagine_embree)
endif(embree_FOUND)
### RMAGINE CUDA LIB
if(CUDA_FOUND)
add_subdirectory(src/rmagine_cuda)
if(OptiX_FOUND)
add_subdirectory(src/rmagine_optix)
endif(OptiX_FOUND)
endif(CUDA_FOUND)
message(STATUS "${BoldCyan}Components build:${ColourReset}")
foreach(LIBRARY ${RMAGINE_LIBRARIES})
message(STATUS "- ${BoldGreen}${LIBRARY}${ColourReset}")
endforeach()
#### TESTS
if(BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif(BUILD_TESTS)
#### TOOLS
if(BUILD_TOOLS)
add_subdirectory(apps/rmagine_benchmark)
add_subdirectory(apps/rmagine_synthetic)
add_subdirectory(apps/rmagine_map_info)
add_subdirectory(apps/rmagine_version)
endif(BUILD_TOOLS)
if(BUILD_EXAMPLES)
if(embree_FOUND)
add_subdirectory(apps/rmagine_examples/rmagine_embree_scene)
endif(embree_FOUND)
if(OptiX_FOUND)
add_subdirectory(apps/rmagine_examples/rmagine_optix_scene)
endif(OptiX_FOUND)
endif(BUILD_EXAMPLES)
# CMAKE FIND SCRIPT
include(CMakePackageConfigHelpers)
#### INSTALL
# 1. Headers
# install(DIRECTORY include/rmagine
# DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# 2. Libraries
# install(TARGETS rmagine-cuda rmagine-optix EXPORT rmagineTargets)
# 3. Static Libraries
# install(TARGETS rmagine-cuda-static rmagine-optix-static EXPORT rmagineTargets)
# install(EXPORT rmagineTargets
# FILE rmagineTargets.cmake
# NAMESPACE rmagine::
# DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/rmagine)
# CMAKE FIND SCRIPT
configure_package_config_file(cmake/rmagine-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/rmagine-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/rmagine-${rmagine_VERSION}
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/rmagine-config-version.cmake
COMPATIBILITY SameMajorVersion
)
## INSTALL
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/rmagine-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/rmagine-config-version.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/rmagine-${rmagine_VERSION}
COMPONENT core
)
install(FILES package.xml
DESTINATION share/rmagine-${rmagine_VERSION}
COMPONENT core
)
# Uninstall
# https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#can-i-do-make-uninstall-with-cmake
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/rmagine-uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/rmagine-uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/rmagine-uninstall.cmake
COMMENT "Uninstall rmagine libraries and all header files")
endif()
###############################################################################
# DOCUMENTATION
###############################################################################
if(BUILD_DOCS)
find_package(Doxygen REQUIRED)
message(STATUS "Build Documentation with 'make doc'")
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Doxyfile.in
${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY )
add_custom_target( doc ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM )
endif(BUILD_DOCS)
#########################
# PACKAGE GENERATION
#########################
include(cmake/rmagine-deb.cmake)
include(CPack)