-
Notifications
You must be signed in to change notification settings - Fork 27
/
CMakeLists.txt
364 lines (320 loc) · 12.7 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
cmake_minimum_required(VERSION 3.22)
project(gtsam_points VERSION 1.0.6 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
option(BUILD_TESTS "Build test" OFF)
option(BUILD_DEMO "Build demo programs" OFF)
option(BUILD_EXAMPLE "Build example programs" OFF)
option(BUILD_WITH_TBB "Build with TBB support" ON)
option(BUILD_WITH_OPENMP "Build with OpenMP support" ON)
option(BUILD_WITH_CUDA "Build with GPU support" OFF)
option(BUILD_WITH_CUDA_MULTIARCH "Build with CUDA multi-architecture support" OFF)
option(BUILD_WITH_MARCH_NATIVE "Build with -march=native" OFF)
option(ENABLE_CPPCHECK "Enable cppcheck" OFF)
option(ENABLE_COVERAGE "Enable coverage check" OFF)
if(BUILD_WITH_MARCH_NATIVE)
set(GTSAM_POINTS_WITH_MARCH_NATIVE 1)
add_compile_options(-march=native)
set(CMAKE_C_FLAGS "-march=native ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-march=native ${CMAKE_CXX_FLAGS}")
endif()
find_package(Boost REQUIRED COMPONENTS filesystem)
find_package(GTSAM REQUIRED)
find_package(Eigen3 REQUIRED)
if(BUILD_WITH_TBB)
find_package(TBB REQUIRED)
set(GTSAM_POINTS_USE_TBB 1)
endif()
if(BUILD_WITH_OPENMP)
find_package(OpenMP REQUIRED)
set(GTSAM_POINTS_USE_OPENMP 1)
endif()
if(${BUILD_WITH_CUDA} AND ${EIGEN3_VERSION_STRING} AND ${EIGEN3_VERSION_STRING} VERSION_LESS "3.3.90")
message(WARNING "Detected Eigen ${EIGEN3_VERSION_STRING} is not compatible with CUDA")
message(WARNING "Use Eigen 3.3.90 or later (3.4.0 is recommended)")
endif()
# GPU-related
if(BUILD_WITH_CUDA)
set(GTSAM_POINTS_USE_CUDA 1)
add_definitions(-DBUILD_GTSAM_POINTS_GPU)
find_package(CUDAToolkit REQUIRED)
enable_language(CUDA)
set(CUDA_STANDARD 17)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24.0")
if(BUILD_WITH_CUDA_MULTIARCH)
set(CMAKE_CUDA_ARCHITECTURES "all-major" CACHE STRING "CUDA architectures" FORCE)
elseif(NOT DEFINED CMAKE_CUDA_ARCHITECTURES OR CMAKE_CUDA_ARCHITECTURES STREQUAL "52")
set(CMAKE_CUDA_ARCHITECTURES "native" CACHE STRING "CUDA architectures" FORCE)
endif()
else()
if(BUILD_WITH_CUDA_MULTIARCH)
set(CMAKE_CUDA_ARCHITECTURES 75 80 87 89 90 CACHE STRING "CUDA architectures" FORCE)
else()
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES OR CMAKE_CUDA_ARCHITECTURES STREQUAL "52")
message(WARNING "CMAKE_CUDA_ARCHITECTURES is not defined. Set to 80 by default")
set(CMAKE_CUDA_ARCHITECTURES 80 CACHE STRING "CUDA architectures" FORCE)
endif()
endif()
endif()
message(STATUS "CMAKE_CUDA_ARCHITECTURES: ${CMAKE_CUDA_ARCHITECTURES}")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Wno-c99-extensions")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-relaxed-constexpr")
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
else()
# Suppress Eigen-related CUDA warnings
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcudafe --diag_suppress=177")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcudafe --diag_suppress=2739")
if(${CUDAToolkit_VERSION} VERSION_GREATER_EQUAL 11.2)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcudafe --diag_suppress=20011")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcudafe --diag_suppress=20014")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcudafe --diag_suppress=set_but_not_used")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcudafe --diag_suppress=esa_on_defaulted_function_ignored")
endif()
if(${CUDAToolkit_VERSION} VERSION_GREATER_EQUAL 11.6)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcudafe --diag_suppress=20236")
endif()
endif()
endif()
if(ENABLE_CPPCHECK)
set(CMAKE_CXX_CPPCHECK "cppcheck")
list(APPEND CMAKE_CXX_CPPCHECK
"--enable=warning"
"--inconclusive"
"--force"
"--inline-suppr"
"--suppressions-list=${CMAKE_SOURCE_DIR}/.cppcheck_suppressions.txt"
)
endif()
if(ENABLE_COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -coverage")
find_program(LCOV lcov REQUIRED)
find_program(GENHTML genhtml REQUIRED)
add_custom_target(coverage
COMMAND ${LCOV} --directory . --capture --output-file coverage.info
COMMAND ${GENHTML} --demangle-cpp -o coverage coverage.info
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
endif()
execute_process(
COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE GTSAM_POINTS_GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message(STATUS "GTSAM_POINTS_GIT_HASH=${GTSAM_POINTS_GIT_HASH}")
configure_file(include/gtsam_points/config.hpp.in include/gtsam_points/config.hpp)
###########
## Build ##
###########
add_library(gtsam_points SHARED
# util
src/gtsam_points/util/covariance_estimation.cpp
src/gtsam_points/util/normal_estimation.cpp
src/gtsam_points/util/bspline.cpp
src/gtsam_points/util/continuous_trajectory.cpp
src/gtsam_points/util/parallelism.cpp
# ann
src/gtsam_points/ann/kdtree.cpp
src/gtsam_points/ann/intensity_kdtree.cpp
src/gtsam_points/ann/ivox.cpp
src/gtsam_points/ann/incremental_covariance_container.cpp
src/gtsam_points/ann/incremental_covariance_voxelmap.cpp
# types
src/gtsam_points/types/point_cloud.cpp
src/gtsam_points/types/point_cloud_cpu.cpp
src/gtsam_points/types/gaussian_voxelmap_cpu.cpp
src/gtsam_points/types/gaussian_voxelmap_cpu_funcs.cpp
# factors
src/gtsam_points/factors/integrated_matching_cost_factor.cpp
src/gtsam_points/factors/integrated_icp_factor.cpp
src/gtsam_points/factors/integrated_gicp_factor.cpp
src/gtsam_points/factors/integrated_vgicp_factor.cpp
src/gtsam_points/factors/integrated_loam_factor.cpp
src/gtsam_points/factors/intensity_gradients.cpp
src/gtsam_points/factors/integrated_colored_gicp_factor.cpp
src/gtsam_points/factors/integrated_color_consistency_factor.cpp
src/gtsam_points/factors/integrated_ct_icp_factor.cpp
src/gtsam_points/factors/integrated_ct_gicp_factor.cpp
src/gtsam_points/factors/bundle_adjustment_factor_evm.cpp
src/gtsam_points/factors/bundle_adjustment_factor_lsq.cpp
# experimental
src/gtsam_points/factors/experimental/continuous_time_icp_factor.cpp
# optimizers
src/gtsam_points/optimizers/fast_scatter.cpp
src/gtsam_points/optimizers/linearization_hook.cpp
src/gtsam_points/optimizers/linear_system_builder.cpp
src/gtsam_points/optimizers/gaussian_factor_graph_solver.cpp
src/gtsam_points/optimizers/levenberg_marquardt_ext.cpp
src/gtsam_points/optimizers/levenberg_marquardt_optimization_status.cpp
src/gtsam_points/optimizers/isam2_ext.cpp
src/gtsam_points/optimizers/isam2_ext_impl.cpp
src/gtsam_points/optimizers/incremental_fixed_lag_smoother_ext.cpp
src/gtsam_points/optimizers/incremental_fixed_lag_smoother_ext_with_fallback.cpp
# src/gtsam_points/optimizers/dogleg_optimizer_ext.cpp
src/gtsam_points/optimizers/dogleg_optimizer_ext_impl.cpp
)
target_include_directories(gtsam_points PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/nanoflann/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(gtsam_points
Boost::boost
Boost::filesystem
Eigen3::Eigen
GTSAM::GTSAM
$<TARGET_NAME_IF_EXISTS:TBB::tbb>
$<TARGET_NAME_IF_EXISTS:OpenMP::OpenMP_CXX>
)
# GPU-related
if(BUILD_WITH_CUDA)
add_library(gtsam_points_cuda SHARED
# cuda-related
src/gtsam_points/cuda/check_error.cu
src/gtsam_points/cuda/check_error_cusolver.cu
src/gtsam_points/cuda/check_error_curand.cu
src/gtsam_points/cuda/cuda_memory.cu
src/gtsam_points/cuda/cuda_stream.cu
src/gtsam_points/cuda/cuda_buffer.cu
src/gtsam_points/cuda/cuda_device_sync.cu
src/gtsam_points/cuda/cuda_device_prop.cu
src/gtsam_points/cuda/cuda_graph.cu
src/gtsam_points/cuda/cuda_graph_exec.cu
# src/gtsam_points/cuda/gl_buffer_map.cu
src/gtsam_points/cuda/nonlinear_factor_set_gpu.cpp
src/gtsam_points/cuda/nonlinear_factor_set_gpu_create.cpp
src/gtsam_points/cuda/stream_roundrobin.cu
src/gtsam_points/cuda/stream_temp_buffer_roundrobin.cu
# types
src/gtsam_points/types/point_cloud.cu
src/gtsam_points/types/point_cloud_gpu.cu
src/gtsam_points/types/gaussian_voxelmap_gpu.cu
src/gtsam_points/types/gaussian_voxelmap_gpu_funcs.cu
# factors
src/gtsam_points/factors/integrated_vgicp_derivatives.cu
src/gtsam_points/factors/integrated_vgicp_derivatives_inliers.cu
src/gtsam_points/factors/integrated_vgicp_derivatives_compute.cu
src/gtsam_points/factors/integrated_vgicp_derivatives_linearize.cu
src/gtsam_points/factors/integrated_vgicp_factor_gpu.cpp
# util
src/gtsam_points/util/easy_profiler_cuda.cu
)
target_include_directories(gtsam_points_cuda PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(gtsam_points_cuda
CUDA::cudart
Boost::boost
Eigen3::Eigen
GTSAM::GTSAM
$<TARGET_NAME_IF_EXISTS:TBB::tbb>
$<TARGET_NAME_IF_EXISTS:OpenMP::OpenMP_CXX>
)
target_link_libraries(gtsam_points
gtsam_points_cuda
)
endif()
#Demo
if(BUILD_DEMO)
find_package(Iridescence REQUIRED)
file(GLOB demo_sources "src/demo/*.cpp")
foreach(demo_src IN LISTS demo_sources)
get_filename_component(demo_name ${demo_src} NAME_WE)
add_executable(${demo_name} ${demo_src})
target_link_libraries(${demo_name} gtsam_points Iridescence::Iridescence)
endforeach()
endif()
#Example
if(BUILD_EXAMPLE)
find_package(Iridescence REQUIRED)
file(GLOB example_sources "src/example/*.cpp")
foreach(example_src IN LISTS example_sources)
get_filename_component(example_name ${example_src} NAME_WE)
add_executable(${example_name} ${example_src})
target_link_libraries(${example_name} gtsam_points Iridescence::Iridescence)
endforeach()
endif()
# Test
if(BUILD_TESTS)
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
enable_testing()
include(GoogleTest)
file(GLOB test_sources "src/test/*.cpp")
foreach(test_src IN LISTS test_sources)
get_filename_component(test_name ${test_src} NAME_WE)
add_executable(${test_name} ${test_src})
target_link_libraries(${test_name} gtsam_points gtest_main)
target_include_directories(${test_name} PRIVATE ${Boost_INCLUDE_DIRS} src/test/include)
gtest_discover_tests(${test_name} WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
endforeach()
endif()
#############
## Install ##
#############
include(GNUInstallDirs)
install(
DIRECTORY include/ thirdparty/nanoflann/include/ ${CMAKE_CURRENT_BINARY_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
list(APPEND GTSAM_POINTS_LIBRARIES gtsam_points)
if(BUILD_WITH_CUDA)
list(APPEND GTSAM_POINTS_LIBRARIES gtsam_points_cuda)
endif()
install(TARGETS ${GTSAM_POINTS_LIBRARIES}
EXPORT gtsam_points-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
set(CMAKE_CONFIG_INSTALL_DIR
"${CMAKE_INSTALL_LIBDIR}/cmake/gtsam_points"
CACHE PATH "Install directory for CMake config files"
)
include(CMakePackageConfigHelpers)
install(EXPORT gtsam_points-targets
FILE gtsam_points-targets.cmake
NAMESPACE gtsam_points::
DESTINATION ${CMAKE_CONFIG_INSTALL_DIR}
)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/gtsam_points-config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/gtsam_points-config.cmake"
INSTALL_DESTINATION ${CMAKE_CONFIG_INSTALL_DIR}
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/gtsam_points-config-version.cmake"
VERSION ${VERSION}
COMPATIBILITY SameMajorVersion
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/gtsam_points-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/gtsam_points-config-version.cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindGTSAM.cmake"
DESTINATION ${CMAKE_CONFIG_INSTALL_DIR}
)
#############
## Package ##
#############
set(CPACK_GENERATOR "DEB")
set(CPACK_PACKAGE_NAME ${CMAKE_PROJECT_NAME})
set(CPACK_SET_DESTDIR TRUE)
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "k.koide <k.koide@aist.go.jp>")
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set(GNUInstallDirs)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A collection of GTSAM factors for point cloud registration")
set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE")
set(CPACK_PACKAGE_VENDOR "k.koide")
include(CPack)