-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
222 lines (176 loc) · 7.5 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
cmake_minimum_required(VERSION 3.5)
# Without enabling languages, find_package(depthai) fails when it is found in the system
# It then tries to run find_package(Threads) and that causes an error.
# Can't define the project(..) here as well, because it then makes hunter to fail
enable_language(C)
enable_language(C CXX)
set(CMAKE_BUILD_TYPE Release)
# all these settings are needed to properly compile depthai-core as subdirectory
set(BUILD_SHARED_LIBS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
message(STATUS "-*-*-*- trying to find depthai library -*-*-*-")
find_package(depthai QUIET)
if(depthai_FOUND)
message(STATUS "-*-*-*- depthai found -*-*-*-")
else()
message(STATUS "-*-*-*- depthai not found -*-*-*-")
add_definitions(-DSPDLOG_ACTIVE_LEVEL=6)
add_definitions(-DSPDLOG_HEADER_ONLY=1)
add_definitions(-DFMT_HEADER_ONLY=1)
set(HUNTER_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE}) # makes possible to compile also Debug build
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/depthai-core ${CMAKE_CURRENT_BINARY_DIR}/depthai-core EXCLUDE_FROM_ALL)
endif()
option(BUILD_GSTREAMER "enable building gstreamer" OFF)
if(DEFINED ENV{BUILD_GSTREAMER})
set(BUILD_GSTREAMER "$ENV{BUILD_GSTREAMER}")
endif()
project(depthai_ctrl LANGUAGES CXX C)
find_package(backward_ros REQUIRED)
# add_compile_options(-g)
# # pkg-config configurations path.
# if(NOT DEFINED ENV{PKG_CONFIG_PATH})
# set(ENV{PKG_CONFIG_PATH} "/usr/lib/x86_64-linux-gnu/pkgconfig/")
# else()
# string(FIND "/usr/lib/x86_64-linux-gnu/pkgconfig/" $ENV{PKG_CONFIG_PATH} POS_INC_PATH)
# if(${POS_INC_PATH} STREQUAL "-1")
# set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/lib/x86_64-linux-gnu/pkgconfig/")
# endif()
# endif()
# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic
)
endif()
set(opencv_version 4)
find_package(OpenCV ${opencv_version} QUIET COMPONENTS imgproc highgui)
if(NOT OpenCV_FOUND)
message(STATUS "----------------Did not find OpenCV 4, trying OpenCV 3--------------")
set(opencv_version 3)
find_package(OpenCV ${opencv_version} REQUIRED COMPONENTS imgproc highgui)
endif()
find_package(ament_cmake REQUIRED)
# find_package(libyaml_vendor REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(yaml REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_components REQUIRED)
find_package(image_transport REQUIRED)
find_package(camera_info_manager REQUIRED)
find_package(std_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(stereo_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(vision_msgs REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(cv_bridge REQUIRED)
set(_opencv_version 4)
find_package(OpenCV 4 QUIET COMPONENTS imgproc highgui)
if(NOT OpenCV_FOUND)
message(STATUS "----------------Did not find OpenCV 4, trying OpenCV 3--------------")
set(_opencv_version 3)
find_package(OpenCV 3 REQUIRED COMPONENTS imgproc highgui)
endif()
if (BUILD_GSTREAMER)
pkg_check_modules(GST REQUIRED IMPORTED_TARGET gstreamer-1.0)
include_directories(SYSTEM ${GST_INCLUDE_DIRS})
link_directories(${GST_LIBRARY_DIRS})
endif()
include_directories(include)
set(camera_dependencies
rclcpp
sensor_msgs
stereo_msgs
geometry_msgs
std_msgs
vision_msgs
rclcpp_components
camera_info_manager
cv_bridge
image_transport
)
FILE(GLOB LIB_SRC
"src/ImageConverter.cpp"
"src/ImgDetectionConverter.cpp"
"src/ImuConverter.cpp"
)
add_library(depthai_bridge SHARED ${LIB_SRC})
ament_target_dependencies(depthai_bridge PUBLIC ${camera_dependencies})
target_link_libraries(depthai_bridge PUBLIC depthai-core opencv_imgproc opencv_highgui)
message(STATUS "--------------------------$ENV{ROS_DISTRO} ---")
message(STATUS $ENV{ROS_DISTRO})
# if($ENV{ROS_DISTRO} STREQUAL "galactic" OR ($ENV{ROS_DISTRO} STREQUAL "rolling" AND "${ubuntu_version}" STREQUAL "20.04\n"))
# target_compile_definitions(depthai_bridge PRIVATE IS_GALACTIC)
# endif()
# if($ENV{ROS_DISTRO} STREQUAL "humble")
target_compile_definitions(depthai_bridge PRIVATE IS_HUMBLE)
# endif()
# DepthAI Camera as Component library
add_library(depthai_camera SHARED src/depthai_camera.cpp)
ament_target_dependencies(depthai_camera PUBLIC ${camera_dependencies})
target_link_libraries(depthai_camera PUBLIC depthai-core opencv_imgproc opencv_highgui depthai_bridge)
# DepthAI Camera as separate node
add_executable(camera_node src/camera_node.cpp)
ament_target_dependencies(camera_node PUBLIC rclcpp rclcpp_components)
target_link_libraries(camera_node PUBLIC depthai_camera)
add_dependencies(camera_node depthai_camera)
rclcpp_components_register_nodes(depthai_camera PLUGIN "${PROJECT_NAME}::DepthAICamera" EXECUTABLE depthai_camera)
if (BUILD_GSTREAMER)
# DepthAI GStreamer as Component library
add_library(gstreamer_interface SHARED src/gstreamer_interface.cpp)
ament_target_dependencies(gstreamer_interface PUBLIC rclcpp std_msgs sensor_msgs)
target_link_libraries(gstreamer_interface PUBLIC ${GST_LIBRARIES} gstapp-1.0)
# DepthAI GStreamer as Component library
add_library(depthai_gstreamer SHARED src/depthai_gstreamer.cpp)
ament_target_dependencies(depthai_gstreamer PUBLIC rclcpp std_msgs sensor_msgs rclcpp_components)
target_link_libraries(depthai_gstreamer PUBLIC ${GST_LIBRARIES} gstapp-1.0 gstreamer_interface)
# DepthAI GStreamer as separate node
add_executable(gstreamer_node src/gstreamer_node.cpp)
ament_target_dependencies(gstreamer_node PUBLIC rclcpp rclcpp_components)
target_link_libraries(gstreamer_node PUBLIC depthai_gstreamer)
# Combined DepthAI node
add_executable(depthai_ctrl src/depthai_ctrl.cpp)
ament_target_dependencies(depthai_ctrl PUBLIC rclcpp rclcpp_components)
target_link_libraries(depthai_ctrl PUBLIC depthai_camera depthai_gstreamer)
add_dependencies(depthai_ctrl depthai_gstreamer depthai_camera)
add_dependencies(gstreamer_node depthai_gstreamer)
rclcpp_components_register_nodes(depthai_gstreamer PLUGIN "${PROJECT_NAME}::DepthAIGStreamer" EXECUTABLE depthai_gstreamer)
endif()
# Disable tests as its obsolete
# if (BUILD_TESTING)
# enable_testing()
# find_package(ament_lint_auto REQUIRED)
# find_package(ament_cmake_gtest CONFIG REQUIRED)
# add_executable(depthai_camera_test test/depthai_camera_test.cpp)
# add_executable(depthai_gstreamer_test test/depthai_gstreamer_test.cpp)
# ament_target_dependencies(depthai_camera_test rclcpp rclcpp_components)
# ament_target_dependencies(depthai_gstreamer_test PUBLIC rclcpp rclcpp_components)
# target_link_libraries(depthai_camera_test depthai_camera gtest pthread)
# target_link_libraries(depthai_gstreamer_test PUBLIC depthai_gstreamer gstreamer_interface ${GST_LIBRARIES} gstapp-1.0 gstrtspserver-1.0 gtest pthread)
# add_dependencies(depthai_camera_test depthai_camera)
# add_dependencies(depthai_gstreamer_test depthai_gstreamer)
# add_test(depthai_camera_test depthai_camera_test)
# add_test(depthai_gstreamer_test depthai_gstreamer_test)
# endif (BUILD_TESTING)
if (BUILD_GSTREAMER)
install(TARGETS depthai_gstreamer gstreamer_interface
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
install(TARGETS
gstreamer_node depthai_ctrl
DESTINATION lib/${PROJECT_NAME})
endif()
install(TARGETS depthai_camera depthai_bridge
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
install(TARGETS
camera_node
DESTINATION lib/${PROJECT_NAME})
install(DIRECTORY launch params urdf
DESTINATION share/${PROJECT_NAME}
)
ament_package()