-
Notifications
You must be signed in to change notification settings - Fork 18
/
CMakeLists.txt
244 lines (208 loc) · 8.53 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
cmake_minimum_required(VERSION 3.18) # 3.18 To automatically detect CUDA_ARCHITECTURES
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CUDA_STANDARD 17)
# Build Release by default; CMAKE_BUILD_TYPE needs to be set before project(...)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel" FORCE)
endif(NOT CMAKE_BUILD_TYPE)
# Use debug postfix 'd' by default.
if(NOT CMAKE_DEBUG_POSTFIX)
set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING
"Choose the debug postfix used when building Debug configuration")
endif()
project(RobotecGPULidar C CXX CUDA)
# Logging default settings (can be changed via API call)
set(RGL_LOG_STDOUT ON CACHE BOOL
"Enables logging to STDOUT")
set(RGL_LOG_LEVEL INFO CACHE STRING
"Specifies minimal severity of log message to be printed (TRACE, DEBUG, INFO, WARN, ERROR, CRITICAL, OFF)")
set(RGL_LOG_FILE "" CACHE STRING # STRING prevents from expanding relative paths
"Defines a file path to store RGL log")
set(RGL_AUTO_TAPE_PATH "" CACHE STRING # STRING prevents from expanding relative paths
"If non-empty, defines a path for the automatic tape (started on the first API call)")
# Library configuration
set(RGL_BUILD_STATIC OFF CACHE BOOL
"Builds RobotecGPULidar as a statically linkable library instead of a shared one")
# Test configuration
set(RGL_BUILD_TESTS ON CACHE BOOL
"Enables building test. GTest will be automatically downloaded")
set(RGL_BUILD_TAPED_TESTS OFF CACHE BOOL
"Enables building taped test.")
# Tools configuration
set(RGL_BUILD_TOOLS ON CACHE BOOL "Enables building RGL executable tools")
# Extensions configuration
set(RGL_BUILD_PCL_EXTENSION OFF CACHE BOOL
"Enables building PCL extension.")
set(RGL_BUILD_ROS2_EXTENSION OFF CACHE BOOL
"Enables building ROS2 extension. It requires installed and sourced ROS2.")
set(RGL_BUILD_UDP_EXTENSION OFF CACHE BOOL
"Enables building UDP extension.")
set(RGL_BUILD_WEATHER_EXTENSION OFF CACHE BOOL
"Enables building weather simulation extension.")
# Hide automatically generated CTest targets
set_property(GLOBAL PROPERTY CTEST_TARGETS_ADDED 1)
# Fix Windows problems
if (WIN32)
add_definitions(-DNOMINMAX) # http://www.suodenjoki.dk/us/archive/2010/min-max.htm
add_definitions(-D_USE_MATH_DEFINES)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) # https://www.kitware.com//create-dlls-on-windows-without-declspec-using-new-cmake-export-all-feature/
endif()
if (WIN32 AND RGL_BUILD_TESTS)
# Sometimes, for convenience, tests reference non-public symbols from the library
# By default, those symbols are not visible and not annotated with __declspec(dllexport)
# However, there's a CMake workaround for such scenarios, described further at
# https://www.kitware.com//create-dlls-on-windows-without-declspec-using-new-cmake-export-all-feature/
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
endif()
# `External` dependencies
add_subdirectory(external)
find_package(CUDAToolkit REQUIRED)
find_program(BIN2C bin2c DOC "Path to the cuda-sdk bin2c executable.")
if (NOT DEFINED ENV{OptiX_INSTALL_DIR})
message(FATAL_ERROR "Required environment variable OptiX_INSTALL_DIR is empty, aborting build")
endif()
# Includes
include_directories(include)
include_directories($ENV{OptiX_INSTALL_DIR}/include)
include_directories(${spdlog_SOURCE_DIR}/include)
include_directories(${YAML_CPP_SOURCE_DIR}/include)
# Compile OptiX device programs (pipeline) and embed the binary in a library as a char[]
add_library(optixProgramsPtx OBJECT src/gpu/optixPrograms.cu)
target_include_directories(optixProgramsPtx PRIVATE src include)
set_target_properties(optixProgramsPtx PROPERTIES CUDA_PTX_COMPILATION ON)
add_custom_command(
OUTPUT optixProgramsPtx.c
COMMAND ${BIN2C} -c --padd 0 --type char --name optixProgramsPtx $<TARGET_OBJECTS:optixProgramsPtx> > optixProgramsPtx.c
DEPENDS optixProgramsPtx $<TARGET_OBJECTS:optixProgramsPtx> # Should work with just optixProgramsPtx, but CMake..
VERBATIM)
add_library(optixPrograms optixProgramsPtx.c)
set(RGL_SOURCE_FILES
src/api/apiCommon.cpp
src/api/apiCore.cpp
src/tape/TapePlayer.cpp
src/tape/TapeRecorder.cpp
src/tape/PlaybackState.cpp
src/Logger.cpp
src/Optix.cpp
src/gpu/helpersKernels.cu
src/gpu/gaussianNoiseKernels.cu
src/gpu/nodeKernels.cu
src/gpu/sceneKernels.cu
src/scene/Scene.cpp
src/scene/Mesh.cpp
src/scene/Entity.cpp
src/scene/Texture.cpp
src/scene/ASBuildScratchpad.cpp
src/scene/animator/ExternalAnimator.cpp
src/scene/animator/SkeletonAnimator.cpp
src/graph/GraphRunCtx.cpp
src/graph/Node.cpp
src/graph/GaussianNoiseAngularHitpointNode.cpp
src/graph/GaussianNoiseAngularRayNode.cpp
src/graph/GaussianNoiseDistanceNode.cpp
src/graph/CompactByFieldPointsNode.cpp
src/graph/FormatPointsNode.cpp
src/graph/RaytraceNode.cpp
src/graph/TransformPointsNode.cpp
src/graph/TransformRaysNode.cpp
src/graph/FromArrayPointsNode.cpp
src/graph/FromMat3x4fRaysNode.cpp
src/graph/FilterGroundPointsNode.cpp
src/graph/RadarPostprocessPointsNode.cpp
src/graph/RadarTrackObjectsNode.cpp
src/graph/SetRangeRaysNode.cpp
src/graph/SetRaysRingIdsRaysNode.cpp
src/graph/SetTimeOffsetsRaysNode.cpp
src/graph/SpatialMergePointsNode.cpp
src/graph/TemporalMergePointsNode.cpp
src/graph/YieldPointsNode.cpp
)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
if (RGL_BUILD_STATIC)
add_library(RobotecGPULidar STATIC ${RGL_SOURCE_FILES})
target_compile_definitions(RobotecGPULidar PUBLIC RGL_STATIC)
set(RGL_SPDLOG_VARIANT spdlog_header_only)
else ()
add_library(RobotecGPULidar SHARED ${RGL_SOURCE_FILES})
set(RGL_SPDLOG_VARIANT spdlog)
endif ()
set_property(TARGET RobotecGPULidar PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET RobotecGPULidar PROPERTY CUDA_SEPARABLE_COMPILATION ON)
target_compile_definitions(RobotecGPULidar PUBLIC RGL_BUILD_PCL_EXTENSION=$<BOOL:${RGL_BUILD_PCL_EXTENSION}>)
target_compile_definitions(RobotecGPULidar PUBLIC RGL_BUILD_ROS2_EXTENSION=$<BOOL:${RGL_BUILD_ROS2_EXTENSION}>)
target_compile_definitions(RobotecGPULidar PUBLIC RGL_BUILD_UDP_EXTENSION=$<BOOL:${RGL_BUILD_UDP_EXTENSION}>)
target_compile_definitions(RobotecGPULidar PUBLIC RGL_BUILD_WEATHER_EXTENSION=$<BOOL:${RGL_BUILD_WEATHER_EXTENSION}>)
if (RGL_BUILD_PCL_EXTENSION)
add_subdirectory(extensions/pcl)
endif()
if (RGL_BUILD_ROS2_EXTENSION)
if (WIN32) # Workaround for compilation on Windows. fastcdr must be found from the top-level of cmake.
find_package(fastcdr REQUIRED)
endif()
add_subdirectory(extensions/ros2)
endif()
if (RGL_BUILD_UDP_EXTENSION)
add_subdirectory(extensions/udp)
endif()
if (RGL_BUILD_WEATHER_EXTENSION)
add_subdirectory(extensions/weather)
endif()
target_include_directories(RobotecGPULidar
PUBLIC include
PRIVATE src
)
target_link_libraries(RobotecGPULidar PRIVATE
${RGL_SPDLOG_VARIANT}
yaml-cpp
optixPrograms
cmake_git_version_tracking
)
target_link_libraries(RobotecGPULidar PUBLIC
CUDA::nvml
CUDA::cudart_static
CUDA::cuda_driver
CUDA::nvToolsExt
)
# Create a CMake list with available log levels (rgl_log_level_t)
set(RGL_AVAILABLE_LOG_LEVELS
RGL_LOG_LEVEL_ALL
RGL_LOG_LEVEL_TRACE
RGL_LOG_LEVEL_DEBUG
RGL_LOG_LEVEL_INFO
RGL_LOG_LEVEL_WARN
RGL_LOG_LEVEL_ERROR
RGL_LOG_LEVEL_CRITICAL
RGL_LOG_LEVEL_OFF
)
# Check if RGL_LOG_LEVEL is a valid variable
if (NOT ("RGL_LOG_LEVEL_${RGL_LOG_LEVEL}" IN_LIST RGL_AVAILABLE_LOG_LEVELS))
message(FATAL_ERROR "Incorrect RGL_LOG_LEVEL value: ${RGL_LOG_LEVEL}")
endif()
if (WIN32 AND (RGL_AUTO_TAPE_PATH OR RGL_BUILD_TAPED_TESTS))
message(FATAL_ERROR "(Auto)Tape not supported on Windows")
endif()
# Pass #define-s to RGL compilation
target_compile_definitions(RobotecGPULidar
PUBLIC RGL_LOG_STDOUT=$<BOOL:${RGL_LOG_STDOUT}>
PUBLIC RGL_LOG_FILE="${RGL_LOG_FILE}"
PUBLIC RGL_LOG_LEVEL=RGL_LOG_LEVEL_${RGL_LOG_LEVEL}
PUBLIC RGL_AUTO_TAPE_PATH="${RGL_AUTO_TAPE_PATH}"
PRIVATE RGL_BUILD # Used in headers to differentiate whether it is parsed as library or client's code, affects __declspec on Windows.
)
# Enable relative paths in the build RPATH for executables
set(CMAKE_BUILD_RPATH_USE_ORIGIN ON)
# Include tests
if (RGL_BUILD_TESTS OR RGL_BUILD_TAPED_TESTS)
enable_testing()
if (RGL_BUILD_TESTS)
add_subdirectory(test)
endif()
if (RGL_BUILD_TAPED_TESTS)
add_subdirectory(test/taped_test)
endif()
endif()
# Include tools
if (RGL_BUILD_TOOLS)
add_subdirectory(tools)
endif()