-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
376 lines (312 loc) · 10.9 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
cmake_minimum_required(VERSION 3.5)
project(trifinger_object_tracking)
# Specify C++ Standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED on)
# libraries need to be position independent otherwise building Python modules
# fails
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# generate compile_commands.json by default (needed for LSP)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# stop build on first error
string(APPEND CMAKE_CXX_FLAGS " -Wall -Wextra -Wfatal-errors -Werror=return-type")
# always enable optimization, otherwise object tracking is too slow
string(APPEND CMAKE_CXX_FLAGS " -O3")
# pybind11 needs to be first, otherwise other packages which also search for
# Python can cause an 'Unknown CMake command "python3_add_library"' error.
# Probably related to how Python is found, see
# https://github.com/pybind/pybind11/issues/3996
find_package(pybind11 REQUIRED)
find_package(ament_cmake REQUIRED)
find_package(mpi_cmake_modules REQUIRED)
find_package(pybind11_opencv REQUIRED)
find_package(cli_utils REQUIRED)
find_package(serialization_utils REQUIRED)
find_package(time_series REQUIRED)
find_package(trifinger_cameras REQUIRED)
find_package(robot_interfaces REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(LAPACK REQUIRED)
find_package(BLAS REQUIRED)
find_package(OpenCV REQUIRED)
find_package(Armadillo REQUIRED)
if (${HAS_PYLON_DRIVERS})
add_definitions(-DPylon_FOUND)
endif()
ament_python_install_package(${PROJECT_NAME} PACKAGE_DIR python/${PROJECT_NAME})
add_library(cv_sub_images src/cv_sub_images.cpp)
target_include_directories(cv_sub_images PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
${OpenCV_INCLUDE_DIRS}
)
target_link_libraries(cv_sub_images ${OpenCV_LIBS})
add_library(cube_detector
src/cube_detector.cpp
src/color_segmenter.cpp
src/pose_detector.cpp
src/utils.cpp
src/cube_model.cpp
src/cube_v1/xgboost_classifier.cpp
src/cube_v2/xgboost_classifier.cpp
src/cuboid_2x2x8/xgboost_classifier.cpp
)
target_include_directories(cube_detector PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
${ARMADILLO_INCLUDE_DIRS}
${BLAS_INCLUDE_DIRS}
)
target_link_libraries(cube_detector
${OpenCV_LIBS}
${ARMADILLO_LIBRARIES}
${BLAS_LIBRARIES}
${LAPACK_LIBRARIES}
pthread
Eigen3::Eigen
serialization_utils::serialization_utils
cv_sub_images
trifinger_cameras::camera_calibration_parser
)
add_library(cube_visualizer
src/cube_visualizer.cpp
)
target_include_directories(cube_visualizer PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(cube_visualizer
cube_detector
)
# TODO frontend should be in separate library
add_library(simulation_object_tracker
src/object_tracker_data.cpp
src/base_object_tracker_backend.cpp
src/simulation_object_tracker_backend.cpp
src/object_tracker_frontend.cpp
)
target_include_directories(simulation_object_tracker PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(simulation_object_tracker
robot_interfaces::robot_interfaces
)
# using pybind11 types, therefore visibility needs to be hidden
set_target_properties(simulation_object_tracker
PROPERTIES CXX_VISIBILITY_PRESET hidden)
add_library(fake_object_tracker
src/object_tracker_data.cpp
src/base_object_tracker_backend.cpp
src/fake_object_tracker_backend.cpp
)
target_include_directories(fake_object_tracker PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(fake_object_tracker
robot_interfaces::robot_interfaces
)
if (${HAS_PYLON_DRIVERS})
add_library(tricamera_object_tracking_driver
src/tricamera_object_tracking_driver.cpp)
target_include_directories(tricamera_object_tracking_driver PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(tricamera_object_tracking_driver
robot_interfaces::robot_interfaces
trifinger_cameras::tricamera_driver
cube_detector
)
# Set library names to variables, so we can use the variable instead of the
# direct name below. In case, Pylon drivers are not built, the variables
# will be empty and thus not cause trouble when used for linking etc.
set(tricamera_object_tracking_driver tricamera_object_tracking_driver)
endif()
add_library(pybullet_tricamera_object_tracker_driver
src/pybullet_tricamera_object_tracker_driver.cpp)
target_include_directories(pybullet_tricamera_object_tracker_driver PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(pybullet_tricamera_object_tracker_driver
pybind11::pybind11
pybind11_opencv::pybind11_opencv
robot_interfaces::robot_interfaces
serialization_utils::serialization_utils
trifinger_cameras::pybullet_tricamera_driver
cube_detector
)
# using pybind11 types, therefore visibility needs to be hidden
set_target_properties(pybullet_tricamera_object_tracker_driver
PROPERTIES CXX_VISIBILITY_PRESET hidden)
add_library(lightblue_segmenter
src/xgb_single_color/lightblue_rgb.cpp
src/xgb_single_color/segment_image.cpp
)
target_include_directories(lightblue_segmenter PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(lightblue_segmenter
${OpenCV_LIBS}
)
# Python Bindings
add_pybind11_module(py_object_tracker srcpy/py_object_tracker.cpp
LINK_LIBRARIES
Eigen3::Eigen
pybind11_opencv::pybind11_opencv
simulation_object_tracker
fake_object_tracker
cube_detector
)
add_pybind11_module(py_tricamera_types srcpy/py_tricamera_types.cpp
LINK_LIBRARIES
pybind11_opencv::pybind11_opencv
${tricamera_object_tracking_driver}
pybullet_tricamera_object_tracker_driver
cube_visualizer
)
add_pybind11_module(py_lightblue_segmenter srcpy/py_lightblue_segmenter.cpp
LINK_LIBRARIES
pybind11_opencv::pybind11_opencv
lightblue_segmenter
)
add_executable(single_observation src/single_observation.cpp)
target_include_directories(single_observation PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(single_observation
cube_detector
cli_utils::program_options
)
add_executable(run_on_logfile src/run_on_logfile.cpp)
target_include_directories(run_on_logfile PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
${OpenCV_INCLUDE_DIRS}
)
target_link_libraries(run_on_logfile
robot_interfaces::robot_interfaces
cube_detector
cli_utils::program_options
)
add_executable(benchmark_with_logfile src/benchmark_with_logfile.cpp)
target_include_directories(benchmark_with_logfile PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(benchmark_with_logfile
robot_interfaces::robot_interfaces
cube_detector
cli_utils::program_options
)
add_executable(demo_lightblue_segmenter_cpp demos/demo_lightblue_segmenter.cpp)
target_include_directories(demo_lightblue_segmenter_cpp PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(demo_lightblue_segmenter_cpp
lightblue_segmenter
)
# Installation
ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET)
# install headers
install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION include/${PROJECT_NAME})
install(
TARGETS
cv_sub_images
cube_detector
cube_visualizer
simulation_object_tracker
fake_object_tracker
${tricamera_object_tracking_driver}
pybullet_tricamera_object_tracker_driver
single_observation
run_on_logfile
benchmark_with_logfile
demo_lightblue_segmenter_cpp
EXPORT export_${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION lib/${PROJECT_NAME}
)
install_scripts(
scripts/analyze_durations.py
scripts/create_background_data.py
scripts/debayering_tests.py
scripts/follow_cube.py
scripts/get_xgb_dump.py
scripts/plot_log_timestamps.py
scripts/record_debug_images.py
scripts/train_xgb_tree.py
scripts/tricamera_log_analyzer.py
scripts/tricamera_log_converter.py
scripts/tricamera_log_extract.py
scripts/tricamera_log_extract_object_poses.py
scripts/tricamera_log_viewer.py
scripts/view_masks.py
DESTINATION lib/${PROJECT_NAME}
)
install(
PROGRAMS
demos/demo_cameras.py
demos/demo_lightblue_segmenter.py
demos/run_on_logfile.py
DESTINATION lib/${PROJECT_NAME}
)
if (BUILD_TESTING)
find_package(ament_cmake_gtest REQUIRED)
find_package(ament_cmake_pytest REQUIRED)
find_package(ament_index_cpp REQUIRED)
# install test images
install(
DIRECTORY test/images
DESTINATION share/${PROJECT_NAME}/test
)
ament_add_gtest(test_test_utils test/test_test_utils.cpp)
target_link_libraries(test_test_utils ${OpenCV_LIBS} Eigen3::Eigen)
install(TARGETS test_test_utils DESTINATION lib/${PROJECT_NAME})
ament_add_gtest(test_color_segmenter test/test_color_segmenter.cpp)
target_link_libraries(test_color_segmenter cube_detector)
ament_target_dependencies(test_color_segmenter
ament_index_cpp
)
install(TARGETS test_color_segmenter DESTINATION lib/${PROJECT_NAME})
ament_add_gtest(test_cube_model test/test_cube_model.cpp src/cube_model.cpp)
target_include_directories(test_cube_model PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
install(TARGETS test_cube_model DESTINATION lib/${PROJECT_NAME})
ament_add_gtest(test_pose_detector test/test_pose_detector.cpp)
target_link_libraries(test_pose_detector cube_detector)
ament_target_dependencies(test_pose_detector
ament_index_cpp
)
install(TARGETS test_pose_detector DESTINATION lib/${PROJECT_NAME})
ament_add_gtest(test_cube_detector test/test_cube_detector.cpp)
target_link_libraries(test_cube_detector cube_detector)
ament_target_dependencies(test_cube_detector
ament_index_cpp
)
install(TARGETS test_cube_detector DESTINATION lib/${PROJECT_NAME})
ament_add_pytest_test(test_lightblue_segmenter_py
test/test_lightblue_segmenter.py
)
endif()
# Build the sphinx documentation
add_documentation()
ament_export_include_directories(include)
ament_export_libraries(
cv_sub_images
cube_detector
simulation_object_tracker
fake_object_tracker
${tricamera_object_tracking_driver}
pybullet_tricamera_object_tracker_driver
)
ament_package()