-
Notifications
You must be signed in to change notification settings - Fork 19
/
CMakeLists.txt
313 lines (262 loc) · 11.4 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
cmake_minimum_required(VERSION 3.10)
project(ohm)
# Set CMAKE_CXX_STANDARD to the minimum if not externally set - e.g., from command line.
# We'll set it in such a way that it remains it the Cache and stays set.
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14 CACHE INTERNAL "C++ standard")
endif(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
# Ensure -fPIC is added.
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Read version from package.xml
file(READ package.xml ohm_VERSION)
string(REGEX MATCH "\\<version\\>(.*)\\</version\\>" ohm_VERSION ${ohm_VERSION})
string(REGEX REPLACE "\\<version\\>(.*)\\</version\\>" "\\1" ohm_VERSION ${ohm_VERSION})
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
include(utils)
# Work out if we are using VCPKG.
set(OHM_VCPKG FALSE)
if(CMAKE_TOOLCHAIN_FILE MATCHES ".*vcpkg\.cmake;?.*")
set(OHM_VCPKG TRUE)
endif(CMAKE_TOOLCHAIN_FILE MATCHES ".*vcpkg\.cmake;?.*")
# Setup core ohm build options.
# Default to building shared libs.
set(OHM_BUILD_SHARED_DEFAULT OFF)
if(DEFINED BUILD_SHARED_LIBS)
# But use BUILD_SHARED_LIBS as the default if it's specified (like from the command line).
set(OHM_BUILD_SHARED_DEFAULT ${BUILD_SHARED_LIBS})
endif(DEFINED BUILD_SHARED_LIBS)
option(OHM_BUILD_SHARED "Build shared ohm libraries?" ${OHM_BUILD_SHARED_DEFAULT})
# For details on OHM_BUILD_SHARED_SUPPRESS_WARNINGS, see usage in compilerSetup.cmake
option(OHM_BUILD_SHARED_SUPPRESS_WARNINGS
"Suppress warnings relating the DLL export symbols when building shared? Disables MSC warnings C4251 and C4275" ON)
option(OHM_PROFILE "Enable timing information messages for some queries." Off)
option(OHM_TES_DEBUG "Enable visual debugging code?" Off)
option(OHM_VALIDATION "Enable various validation tests in the occupancy map code. Has some performance impact." Off)
# OHM_FEATURE_CUDA is found in OhmCuda.cmake
option(OHM_LEAK_TRACK "Enable memory leak tracking?" OFF)
# Build options; what extensions are we going to build. These options are authoritative and flow down from here.
# For CUDA and OpenCL, we only need one, and we prefer CUDA based on what we find. However, vcpkg can guarantee we'll
# find one, so it because a dependent option.
option(OHM_BUILD_DOXYGEN "Build doxygen documentation?" Off)
ohm_feature(EIGEN "Use Eigen for more significant linear algebra algorithms (e.g., eigen decomposition)?" FIND Eigen3)
ohm_feature(HEIGHTMAP "Build heightmap library?")
ohm_feature(HEIGHTMAP_IMAGE "Build heightmap image conversion?" FIND OpenGL GLEW glfw3)
ohm_feature(PDAL "Build with PDAL reader support?" FIND pdal)
ohm_feature(THREADS "Enable CPU threading (using Thread Building Blocks)?" FIND tbb)
ohm_feature(TEST "Build unit tests?" FIND GTest)
# include CUDA config here to prime OHM_FEATURE_CUDA as we prefer CUDA over OpenCL.
# OHM_FEATURE_CUDA is in OhmCuda.cmake
include(OhmCuda)
set(OHM_FEATURE_OPENCL_DEFAULT ON)
if(OHM_FEATURE_CUDA)
set(OHM_FEATURE_OPENCL_DEFAULT OFF)
endif(OHM_FEATURE_CUDA)
ohm_feature(OPENCL "Build with OpenCL support?" FIND OpenCL DEFAULT OHM_FEATURE_OPENCL_DEFAULT)
# # Windows vcpkg does not provide CUDA.
# add_vcpkg_feature_if("cuda" "OHM_CUDA AND NOT WIN32")
# Migrate ohm specific setting for building shared libraries to the CMake global option.
set(BUILD_SHARED_LIBS ${OHM_BUILD_SHARED})
if(BUILD_SHARED_LIBS)
message(STATUS "Building shared ohm libraries.")
endif(BUILD_SHARED_LIBS)
# Setup clang-tidy
include(ClangTidy)
# Allow the use of folders to group targets in supporting environments.
# For example Visual Studio solution folders.
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_DEBUG_POSTFIX _d)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
foreach(CONF Debug;Release;MinSizeRel;RelWithDebInfo)
string(TOUPPER ${CONF} CONFU)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${CONFU} "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${CONFU} "${CMAKE_BINARY_DIR}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${CONFU} "${CMAKE_BINARY_DIR}/bin")
endforeach(CONF)
# Add memory leak tracking support.
include(LeakTrack)
# Configure installation prefixes.
# set(OHM_PREFIX_PACKAGE lib/cmake/${CMAKE_PROJECT_NAME})
set(OHM_PREFIX_PACKAGE share/${CMAKE_PROJECT_NAME}/cmake) # For catkin interoperation
# Prefix for include directories.
set(OHM_PREFIX_INCLUDE include/ohm)
# General, required library
# We use our own FindGLM to cater for differences between Ubuntu 18.04 and 20.04.
# From 20.04 on, we can just just find_config(glm CONFIG REQUIRED)
find_package(glm MODULE REQUIRED)
if(OHM_FEATURE_OPENCL)
find_package(OpenCL)
endif(OHM_FEATURE_OPENCL)
if(OpenCL_FOUND)
option(OHM_EMBED_GPU_CODE "Embed GPU code into the executable (OpenCL)? Otherwise GPU code files are loaded from disk (better for development)." ON)
set(OHM_OPENCL_SDK_VER 1.2 CACHE STRING "Select the OpenCL runtime API to use.")
set_property(CACHE OHM_OPENCL_SDK_VER PROPERTY STRINGS 1.2 2.0 2.1 2.2 3.0)
set(OHM_OPENCL_STD 2.0 CACHE STRING "Select the default OpenCL standard to compile GPU code against. Also runtime configurable. [max] uses the reported device allowing for 2.x requires features.")
set_property(CACHE OHM_OPENCL_STD PROPERTY STRINGS 1.2 2.0 3.0 max)
endif(OpenCL_FOUND)
# Identify any extensions required to compile with OpenCL 2.0 std.
set(OHM_OPENCL_2_FEATURES "" CACHE STRING "Features required for OpenCL 2.x. Fallback to 1.2 otherwise.")
# Look for CUDA to setup CUDA build options and work out which CMake CUDA paradigm we'll use.
if(OHM_FEATURE_CUDA)
if(NOT OHM_USE_DEPRECATED_CMAKE_CUDA)
find_package(CUDAToolkit REQUIRED)
else(NOT OHM_USE_DEPRECATED_CMAKE_CUDA)
# Need to find CUDA for deprecated project configuration
find_package(CUDA REQUIRED)
endif(NOT OHM_USE_DEPRECATED_CMAKE_CUDA)
endif(OHM_FEATURE_CUDA)
if(OHM_FEATURE_EIGEN)
find_package(Eigen3 CONFIG REQUIRED)
endif(OHM_FEATURE_EIGEN)
# Manage compiler warnings.
# Use CMAKE_MODULE_PATH and include(warnings) if warnings.cmake is moved.
include(compilerSetup)
# Now setup CUDA after knowing if we are building shared libraries or not.
cuda_setup()
# Setup default memory leak tracking suppressions and options (GCC/Clang AddressSanitizer).
set(OHM_LEAK_SUPPRESS_OCL_INIT
# OpenCL memory allocation overrides
"__interceptor_malloc"
"__interceptor_calloc"
# Intel OpenCL leaks
"libigdrcl"
"llvm::FPPassManager::runOnFunction"
"llvm::SmallVectorBase"
"libigc"
"basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_mutate"
)
set(OHM_LEAK_SUPPRESS_TBB_INIT
"libtbb"
)
set(OHM_LEAK_SUPPRESS_CUDA_INIT
)
set(OHM_ASAN_OPTIONS_CUDA_INIT "protect_shadow_gap=0")
set(OHM_LEAK_SUPPRESS_OCL "${OHM_LEAK_SUPPRESS_OCL_INIT}" CACHE STRING "Memory leak suppression list for OpenCL")
set(OHM_LEAK_SUPPRESS_TBB "${OHM_LEAK_SUPPRESS_TBB_INIT}" CACHE STRING "Memory leak suppression list for Intel Threading Building Blocks")
set(OHM_LEAK_SUPPRESS_CUDA "${OHM_LEAK_SUPPRESS_CUDA_INIT}" CACHE STRING "Memory leak suppression list for CUDA")
set(OHM_ASAN_OPTIONS_CUDA "${OHM_ASAN_OPTIONS_CUDA_INIT}" CACHE STRING "Address Sanitizer options for CUDA")
# Configure OHM_GPU as a value for configure_file
set(OHM_GPU_OPENCL 1)
set(OHM_GPU_CUDA 2)
set(OHM_GPU 0)
# Configure use of 3rd-Eye-Scene visual debugging (use for development only)
if(OHM_TES_DEBUG)
find_package(3es)
else(OHM_TES_DEBUG)
# Include path to 3esservermarcos.h which effectively disables all 3es macros.
set(3ES_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/3rdparty/3es-core")
endif(OHM_TES_DEBUG)
add_subdirectory(logutil)
if(OHM_FEATURE_OPENCL)
add_subdirectory(clu)
endif(OHM_FEATURE_OPENCL)
if(OHM_FEATURE_CUDA OR OHM_FEATURE_OPENCL)
add_subdirectory(gputil)
endif(OHM_FEATURE_CUDA OR OHM_FEATURE_OPENCL)
add_subdirectory(ohmutil)
add_subdirectory(slamio)
add_subdirectory(ohm)
if(OHM_FEATURE_CUDA OR OHM_FEATURE_OPENCL)
add_subdirectory(ohmgpu)
endif(OHM_FEATURE_CUDA OR OHM_FEATURE_OPENCL)
if(OHM_FEATURE_HEIGHTMAP)
add_subdirectory(ohmheightmap)
endif(OHM_FEATURE_HEIGHTMAP)
if(OHM_FEATURE_HEIGHTMAP_IMAGE)
# Experimental
add_subdirectory(ohmheightmapimage)
endif(OHM_FEATURE_HEIGHTMAP_IMAGE)
add_subdirectory(ohmtools)
add_subdirectory(ohmapp)
add_subdirectory(utils)
if(OHM_FEATURE_TEST)
enable_testing()
add_subdirectory(tests)
endif(OHM_FEATURE_TEST)
clang_tidy_global()
export(EXPORT ${CMAKE_PROJECT_NAME}-config-targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}-config-targets.cmake"
NAMESPACE ohm::
)
install(EXPORT ${CMAKE_PROJECT_NAME}-config-targets
FILE ${CMAKE_PROJECT_NAME}-config-targets.cmake
NAMESPACE ohm::
DESTINATION ${OHM_PREFIX_PACKAGE}
)
# Setup import scripts.
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}-version.cmake"
VERSION ${ohm_VERSION}
COMPATIBILITY AnyNewerVersion
)
# Installation of the package configuration file.
configure_file(cmake/${CMAKE_PROJECT_NAME}-packages.cmake "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}-packages.cmake")
configure_file(cmake/${CMAKE_PROJECT_NAME}-config.cmake "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}-config.cmake" @ONLY)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}-packages.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}-version.cmake"
DESTINATION ${OHM_PREFIX_PACKAGE}
COMPONENT Devel)
# Install MSVC runtime libraries. This will also affect the CPack installation.
include(InstallRequiredSystemLibraries)
# Doxygen setup.
if(OHM_BUILD_DOXYGEN)
# Include Doxygen helper functions. This also finds the Doxygen package.
include(doxygen)
set(DOXYGEN_DIRS
gputil
ohm
ohmtools
ohmutil
slamio
)
set(DOXYGE_EXCLUDE_DIRS
clu/3rdparty
gputil/cl
gputil/cuda
ohm/cl
ohm/gpu
ohm/private
ohmgpu/private
ohmutil/3rdparty
slamio/miniply
slamio/pdal
)
if(OHM_FEATURE_CUDA OR OHM_FEATURE_OPENCL)
list(APPEND DOXYGEN_DIRS ohmgpu)
endif(OHM_FEATURE_CUDA OR OHM_FEATURE_OPENCL)
if(OHM_FEATURE_OPENCL)
list(APPEND DOXYGEN_DIRS clu)
endif(OHM_FEATURE_OPENCL)
list(APPEND DOXYGEN_DIRS docs)
if(DOXYGEN_FOUND)
# Create a target to build the documentation.
# Here we also setup various documentation variables passed through to the doxyfile configuration.
# Each named argument below describes the Doxygen variable it sets.
doxygen_create(
# DOXYFILE cmake/doxyfile.in # Doxyfile to configure.
PROJECT ${CMAKE_PROJECT_NAME} # PROJECT_NAME
VERSION ${ohm_VERSION} # PROJECT_NUMBER
OUTPUT_DIR html # HTML_OUPTUT
# CSS <style>.css # HTML_STYLESHEET
PUBLISHER "CSIRO" # DOCSET_PUBLISHER_NAME
PUBLISHER_ID au.csiro # DOCSET_PUBLISHER_ID
PROJECT_ID au.csiro.ohm # DOCSET_BUNDLE_ID, QHP_NAMESPACE, ECLIPSE_DOC_ID
PATHS # INPUT (RECURSIVE is on)
${DOXYGEN_DIRS}
EXCLUDE_PATHS # EXCLUDE
${DOXYGE_EXCLUDE_DIRS}
# Where to find source code examples.
# EXAMPLE_PATHS <paths> # EXAMPLE_PATH
# Where to find images.
# IMAGE_PATHS <paths> # IMAGE_PATH
)
# Setup installation of the generated documentation: source, destination.
doxygen_install(${CMAKE_CURRENT_BINARY_DIR}/html ohm)
endif(DOXYGEN_FOUND)
endif(OHM_BUILD_DOXYGEN)