-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
460 lines (353 loc) · 12.8 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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
cmake_minimum_required(VERSION 3.22.0)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CUDA_STANDARD 20)
set(CMAKE_BUILD_TYPE Release)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(LINUX TRUE)
endif()
########################################################
project(pointcaster LANGUAGES CXX CUDA)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
option(WITH_K4A "Enable Azure Kinect support" ON)
option(WITH_MQTT "Enable MQTT client support" ON)
option(WITH_MIDI "Enable MIDI support" ON)
option(WITH_OSC "Enable OSC client/server support" ON)
option(WITH_THREAD_SANITIZER "Enable thread sanitizer on Debug configuration builds" OFF)
option(WITH_ADDRESS_SANITIZER "Enable address sanitizer on Debug configuration builds" OFF)
option(WITH_MARCH_NATIVE "Enable -march=native builds" ON)
option(WITH_POINTCASTER "Build main application" ON)
option(WITH_RECEIVER_LIB "Build pointreceiver client library" OFF)
if(WIN32)
option(RECEIVER_LIB_SHARED "Build pointreceiver client library with dynamic linkage" ON)
else()
option(RECEIVER_LIB_SHARED "Build pointreceiver client library with dynamic linkage" OFF)
endif()
option(WITH_TESTS "Build tests" OFF)
option(GENERATE_REFLECTIONS ON)
option(WITH_TRACY "Enable profiling using Tracy" OFF)
option(TRACY_ENABLE "Enable profiling using Tracy" OFF)
if (WITH_TRACY)
set(TRACY_ENABLE ON CACHE BOOL "Enable profiling using Tracy" FORCE)
endif()
find_program(MOLD_LINKER_FOUND mold)
if (LINUX AND MOLD_LINKER_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fuse-ld=mold")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fuse-ld=mold")
endif()
if(LINUX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive -Wfatal-errors")
endif()
if (WIN32)
# stop win socket conflicts with includes from networking libraries
add_compile_definitions(WIN32_LEAN_AND_MEAN)
endif()
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION $<$<CONFIG:Release>:TRUE>)
if (WIN32 AND WITH_POINTCASTER)
# set(Boost_INCLUDE_DIR ${_VCPKG_INSTALLED_DIR}/x64-windows-static-md/include)
set(Boost_INCLUDE_DIR ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include)
endif()
if (GENERATE_REFLECTIONS)
set(REFLECTED_TYPES
src/session.h
src/point_cloud_renderer_config.h
src/analysis/analyser_2d_config.h
src/camera/camera_config.h
src/devices/device_config.h
src/devices/usb_config.h
src/midi/midi_device_config.h
src/osc/osc_client_config.h
src/osc/osc_server_config.h
src/mqtt/mqtt_client_config.h
src/radio/radio_config.h
src/client_sync/sync_server.h
src/tween/tween_config.h
src/operators/operator_host_config.h
src/operators/rake_operator.h
src/operators/noise_operator.h
src/operators/rotate_operator.h
src/operators/sample_filter_operator.h
src/operators/range_filter_operator.h
src/operators/denoise/denoise_operator.h
)
foreach(HEADER IN LISTS REFLECTED_TYPES)
cmake_path(GET HEADER STEM FILE_NAME)
cmake_path(GET HEADER PARENT_PATH FILE_DIR)
list(APPEND GENERATED_HEADERS "${FILE_DIR}/${FILE_NAME}.gen.h")
endforeach()
add_custom_command(
OUTPUT ${GENERATED_HEADERS}
COMMAND python ${CMAKE_SOURCE_DIR}/scripts/generate_reflections.py ${REFLECTED_TYPES}
DEPENDS ${REFLECTED_TYPES}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Generating reflection information"
VERBATIM
)
add_custom_target(generate_reflections ALL DEPENDS ${GENERATED_HEADERS})
list(APPEND POINTCASTER_DEPENDENCIES generate_reflections)
endif()
find_package(ZeroMQ CONFIG REQUIRED)
list(APPEND LINK_LIBS libzmq libzmq-static)
if (WIN32)
# zmq windows dependency:
list(APPEND PLATFORM_LIBS bcrypt)
endif()
if (WITH_POINTCASTER)
# ----- Geometry -----
find_package(Eigen3 CONFIG REQUIRED)
list(APPEND LINK_LIBS Eigen3::Eigen)
find_path(EARCUT_HPP_INCLUDE_DIRS "mapbox/earcut.hpp")
list(APPEND INCLUDE_DIRS ${EARCUT_HPP_INCLUDE_DIRS})
find_path(CUDA_NOISE_INCLUDE_DIRS "cuda_noise.cuh")
list(APPEND INCLUDE_DIRS ${CUDA_NOISE_INCLUDE_DIRS})
# ----- Point clouds -----
find_package(bob-pointclouds CONFIG REQUIRED)
list(APPEND LINK_LIBS bob::pointclouds)
find_package(draco CONFIG REQUIRED)
list(APPEND LINK_LIBS draco::draco)
# ----- Networking -----
if (WITH_MQTT)
find_package(PahoMqttCpp CONFIG REQUIRED)
list(APPEND LINK_LIBS PahoMqttCpp::paho-mqttpp3-static uuid)
find_package(msgpack-cxx CONFIG REQUIRED)
list(APPEND LINK_LIBS msgpack-cxx)
list(APPEND OPTIONAL_SRC src/mqtt/mqtt_client.cc)
add_compile_definitions(WITH_MQTT)
endif()
# ----- Control -----
if (WITH_MIDI)
find_package(libremidi CONFIG REQUIRED)
list(APPEND LINK_LIBS libremidi)
list(APPEND POINTCASTER_SRC src/midi/midi_device.cc)
add_compile_definitions(WITH_MIDI)
# look for installed Tobias Erichsen's libRtpMidiSDK
find_library(RTPMIDI_LIB
NAMES RtpMidi libRtpMidi
HINTS
"/opt/libRtpMidiSDK/targets/Linux/x64"
"C:/Program Files (x86)/Tobias Erichsen/libRtpMidiSDK/targets/Microsoft/Windows/x64")
if (RTPMIDI_LIB)
message(STATUS "Found libRtpMidiSDK: ${RTPMIDI_LIB}")
get_filename_component(RTPMIDI_LIB_DIR ${RTPMIDI_LIB} DIRECTORY)
if (LINUX)
set(RTPMIDI_INCLUDES "${RTPMIDI_LIB_DIR}/../../..")
elseif(WIN32)
set(RTPMIDI_INCLUDES "${RTPMIDI_LIB_DIR}/../../../..")
endif()
find_package(mdns_cpp CONFIG REQUIRED)
list(APPEND LINK_LIBS mdns_cpp::mdns_cpp)
list(APPEND POINTCASTER_SRC
src/midi/rtpmidi_device.cc src/midi/rtp_peer.cc)
list(APPEND LINK_LIBS ${RTPMIDI_LIB})
list(APPEND INCLUDE_DIRS ${RTPMIDI_INCLUDES})
add_compile_definitions(WITH_RTP_MIDI)
else()
message(STATUS "libRtpMidiSDK was not found. Network MIDI will be disabled.")
endif()
endif()
if (WITH_OSC)
message(STATUS "Configuring with OSC client/server support")
find_package(liblo CONFIG REQUIRED)
list(APPEND LINK_LIBS liblo::liblo_static)
list(APPEND POINTCASTER_SRC
src/osc/osc_client.cc src/osc/osc_server.cc)
add_compile_definitions(WITH_OSC)
endif()
# ----- Dear ImGui lib -----
find_package(imgui CONFIG REQUIRED)
add_library(ImGui::ImGui ALIAS imgui::imgui)
list(APPEND LINK_LIBS imgui::imgui)
add_definitions(-DIMGUI_DEFINE_MATH_OPERATORS)
list(APPEND THIRDPARTY_SRC thirdparty/imnodes/imnodes.cpp)
list(APPEND INCLUDE_DIRS thirdparty/imnodes)
# ----- Magnum 3D engine -----
find_package(Corrade CONFIG REQUIRED Main)
list(APPEND LINK_LIBS Corrade::Main)
find_package(Magnum CONFIG REQUIRED
GL MeshTools Primitives SceneGraph
Shaders Trade Sdl2Application)
list(APPEND LINK_LIBS
Magnum::Application Magnum::GL
Magnum::Magnum Magnum::MeshTools
Magnum::Primitives Magnum::SceneGraph
Magnum::Shaders Magnum::Trade)
find_package(MagnumIntegration CONFIG REQUIRED
ImGui Eigen)
list(APPEND LINK_LIBS
MagnumIntegration::ImGui MagnumIntegration::Eigen)
# ----- Sensor driver libraries -----
if (NOT WIN32)
find_package(PkgConfig REQUIRED)
pkg_check_modules(libusb REQUIRED IMPORTED_TARGET libusb-1.0)
list(APPEND LINK_LIBS PkgConfig::libusb)
endif()
# Azure Kinect
if (WITH_K4A)
find_package(k4a CONFIG REQUIRED)
list(APPEND OPTIONAL_LIBS k4a::k4a)
list(APPEND OPTIONAL_SRC
src/devices/k4a/k4a_device.cc
src/devices/k4a/k4a_driver.cc
src/devices/k4a/k4a_driver.cu)
find_package(k4abt REQUIRED)
list(APPEND OPTIONAL_LIBS k4a::k4abt)
add_compile_definitions(WITH_K4A)
if (WIN32)
add_compile_definitions(NOMINMAX)
endif()
endif()
# ----- Orbbec -----
find_package(OrbbecSDK REQUIRED CONFIG)
list(APPEND LINK_LIBS ${OrbbecSDK_LIBS})
list(APPEND OPTIONAL_SRC
src/devices/orbbec/orbbec_device.cc
src/devices/orbbec/orbbec_device.cu)
# ----- OpenCV -----
if (WIN32)
find_package(OpenCV REQUIRED HINTS "/Users/matth/Downloads/opencv/build")
else()
find_package(OpenCV CONFIG REQUIRED)
endif()
list(APPEND LINK_LIBS ${OpenCV_LIBS})
list(APPEND INCLUDE_DIRS ${OpenCV_INCLUDE_DIRS})
# ----- PCL -----
find_package(PCL CONFIG REQUIRED)
list(APPEND LINK_LIBS ${PCL_LIBRARIES})
# ----- TBB -----
find_package(TBB CONFIG REQUIRED)
list(APPEND LINK_LIBS TBB::tbb TBB::tbbmalloc)
# ----- CUDA -----
find_package(CUDAToolkit REQUIRED)
find_package(Thrust CONFIG REQUIRED)
thrust_create_target(Thrust)
list(APPEND LINK_LIBS Thrust)
# ----- Utility libs -----
find_package(fmt CONFIG REQUIRED)
list(APPEND LINK_LIBS fmt::fmt)
find_package(spdlog CONFIG REQUIRED)
list(APPEND LINK_LIBS spdlog::spdlog_header_only)
find_package(serdepp CONFIG REQUIRED)
list(APPEND LINK_LIBS serdepp::serdepp)
find_package(toml11 CONFIG REQUIRED)
list(APPEND LINK_LIBS toml11::toml11)
find_path(ZPP_BITS_INCLUDE_DIRS "zpp_bits.h")
list(APPEND INCLUDE_DIRS ${ZPP_BITS_INCLUDE_DIRS})
find_package(Tweeny CONFIG REQUIRED)
list(APPEND LINK_LIBS tweeny)
find_package(unofficial-concurrentqueue CONFIG REQUIRED)
list(APPEND LINK_LIBS unofficial::concurrentqueue::concurrentqueue)
# ----- Profiling -----
find_package(Tracy CONFIG REQUIRED)
if (TRACY_ENABLE)
list(APPEND LINK_LIBS Tracy::TracyClient)
add_compile_definitions(TRACY_ENABLE)
add_compile_definitions(TRACY_ON_DEMAND)
endif()
# ----- Pointcaster application -----
set(SOURCE_FILES
src/pointcaster.cc
src/devices/device.cc
src/devices/usb.cc
src/camera/camera_controller.cc
src/analysis/analyser_2d.cc
src/radio/radio.cc
src/client_sync/sync_server.cc
src/snapshots.cc
src/point_cloud_renderer.cc
src/sphere_renderer.cc
src/shaders/particle_sphere.cc
src/shaders/texture_display.cc
src/gui/widgets.cc
src/gui/range_slider.cc
src/gui/drag_slider.cc
src/parameters.cc
src/path.cc
src/uuid.cc
src/wtf/wtf.cc
src/tween/tween_manager.cc
src/publisher/publisher.cc
src/publisher/publisher_utils.cc
src/graph/operator_graph.cc
src/operators/session_operator_host.cc
src/operators/session_operator_host.cu
src/operators/noise_operator.cc
src/operators/rotate_operator.cc
src/operators/rake_operator.cc
src/operators/sample_filter_operator.cc
src/operators/range_filter_operator.cc
src/operators/denoise/kdtree.cu
src/operators/denoise/denoise_operator.cc
src/operators/pcl/cluster_extraction_operator.cc
${THIRDPARTY_SRC}
${POINTCASTER_SRC}
${OPTIONAL_SRC})
# ----- Resources -----
corrade_add_resource(RESOURCES resources.conf)
if (WIN32)
list(APPEND SOURCE_FILES resources/windows-dpi.manifest)
endif()
add_executable(pointcaster ${SOURCE_FILES} ${RESOURCES})
# ----- Pointcaster build properties
set_target_properties(pointcaster PROPERTIES
UNITY_BUILD OFF
UNITY_BUILD_MODE BATCH
CUDA_SEPARABLE_COMPILATION ON
CUDA_RESOLVE_DEVICE_SYMBOLS ON
CUDA_PROPAGATE_HOST_FLAGS OFF
CUDA_ARCHITECTURES "75;86;89"
# CUDA_ARCHITECTURES "86"
)
if (POINTCASTER_DEPENDENCIES)
add_dependencies(pointcaster ${POINTCASTER_DEPENDENCIES})
endif()
target_include_directories(pointcaster PRIVATE
${INCLUDE_DIRS} ${OPTIONAL_INCLUDE_DIRS}
${PLATFORM_INCLUDE_DIRS})
target_link_libraries(pointcaster PRIVATE
${LINK_LIBS} ${OPTIONAL_LIBS} ${PLATFORM_LIBS})
# optimisations
if (LINUX)
if (WITH_MARCH_NATIVE)
target_compile_options(pointcaster
PRIVATE "-march=native")
endif()
target_compile_options(pointcaster
PRIVATE "$<$<CONFIG:Release>:-O3>")
endif()
# platform specific
if (WIN32)
target_compile_options(pointcaster PRIVATE /bigobj /utf-8)
target_compile_options(pointcaster PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:
-forward-slash-prefix-opts >)
endif()
# debugging related options
if (WITH_THREAD_SANITIZER)
target_compile_options(pointcaster PRIVATE "$<$<CONFIG:DEBUG>:-fsanitize=thread>")
target_link_options(pointcaster PRIVATE "$<$<CONFIG:DEBUG>:-fsanitize=thread>")
elseif(WITH_ADDRESS_SANITIZER)
target_compile_options(pointcaster PRIVATE "$<$<CONFIG:DEBUG>:-fsanitize=address>")
target_link_options(pointcaster PRIVATE "$<$<CONFIG:DEBUG>:-fsanitize=address>")
endif()
endif()
# ----- Pointreceiver library -----
if (WITH_RECEIVER_LIB)
add_subdirectory(pointreceiver)
endif()
# ----- Post-build actions -----
if (WIN32 AND WITH_K4A)
# shared k4abt binaries must be moved into executable directory manually
# (this lib can't be static)
file (GLOB K4ABT_BINS "${K4ABT_ROOT}/sdk/windows-desktop/amd64/release/bin/*")
foreach(K4ABT_BIN ${K4ABT_BINS})
add_custom_command(TARGET pointcaster POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${K4ABT_BIN} $<TARGET_FILE_DIR:pointcaster>)
endforeach()
endif()
if (LINUX)
# copy compile_commands.json for lsp integration on linux
add_custom_target(copy-compile-commands ALL
${CMAKE_COMMAND} -E copy_if_different
${CMAKE_BINARY_DIR}/compile_commands.json
${CMAKE_CURRENT_LIST_DIR})
endif()