forked from clydemcqueen/opencv_cam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
167 lines (142 loc) · 3.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
cmake_minimum_required(VERSION 3.5)
project(opencv_cam)
# Default to C++14
if (NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif ()
if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif ()
# Try for OpenCV 4.X, but settle for whatever is installed
find_package(OpenCV 4 QUIET)
if (NOT OpenCV_FOUND)
find_package(OpenCV REQUIRED)
endif ()
message(STATUS "Found OpenCV version ${OpenCV_VERSION}")
find_package(ament_cmake REQUIRED)
find_package(camera_calibration_parsers REQUIRED)
find_package(class_loader REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_components REQUIRED)
find_package(ros2_shared REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(image_transport REQUIRED)
# Package includes not needed for CMake >= 2.8.11
include_directories(
include
${ros2_shared_INCLUDE_DIRS}
)
# Create ament index resource which references the libraries in the binary dir
set(node_plugins "")
#=============
# OpenCV camera node
#=============
add_library(
opencv_cam_node SHARED
src/opencv_cam_node.cpp
)
target_compile_definitions(
opencv_cam_node
PRIVATE "COMPOSITION_BUILDING_DLL"
)
ament_target_dependencies(
opencv_cam_node
camera_calibration_parsers
class_loader
OpenCV
rclcpp
rclcpp_components
sensor_msgs
ros2_shared
image_transport
)
rclcpp_components_register_nodes(opencv_cam_node "opencv_cam::OpencvCamNode")
set(node_plugins "${node_plugins}opencv_cam::OpencvCamNode;$<TARGET_FILE:opencv_cam_node>\n")
#=============
# Test subscriber node
#=============
add_library(
subscriber_node SHARED
src/subscriber_node.cpp
)
target_compile_definitions(
subscriber_node
PRIVATE "COMPOSITION_BUILDING_DLL"
)
ament_target_dependencies(
subscriber_node
class_loader
rclcpp
rclcpp_components
sensor_msgs
)
rclcpp_components_register_nodes(subscriber_node "opencv_cam::ImageSubscriberNode")
set(node_plugins "${node_plugins}opencv_cam::ImageSubscriberNode;$<TARGET_FILE:subscriber_node>\n")
#=============
# OpenCV camera main, IPC=true
#=============
add_executable(
opencv_cam_main
src/opencv_cam_main.cpp
)
target_link_libraries(
opencv_cam_main
opencv_cam_node
)
ament_target_dependencies(
opencv_cam_main
rclcpp
)
#=============
# Manual composition of camera and subscriber nodes, IPC=true
#=============
add_executable(
ipc_test_main
src/ipc_test_main.cpp
)
target_link_libraries(
ipc_test_main
opencv_cam_node
subscriber_node
)
ament_target_dependencies(
ipc_test_main
rclcpp
)
#=============
# Export
# Best practice, see https://discourse.ros.org/t/ament-best-practice-for-sharing-libraries/3602
#=============
ament_export_dependencies(class_loader)
ament_export_include_directories(include)
ament_export_targets(export_opencv_cam_node export_subscriber_node)
ament_export_libraries(gscam_node subscriber_node)
ament_package()
#=============
# Install
#=============
# Install nodes
install(
TARGETS opencv_cam_node
EXPORT export_opencv_cam_node
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
install(
TARGETS subscriber_node
EXPORT export_subscriber_node
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
# Install executables
install(
TARGETS opencv_cam_main ipc_test_main
DESTINATION lib/${PROJECT_NAME}
)
# Install various directories
install(
DIRECTORY launch
DESTINATION share/${PROJECT_NAME}
)