-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
369 lines (308 loc) · 10.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
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
cmake_minimum_required(VERSION 3.5)
project(ros_gz_bridge)
# 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")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic")
endif()
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_components REQUIRED)
find_package(yaml_cpp_vendor REQUIRED)
# TODO(CH3): Deprecated. Remove on tock.
if("$ENV{GZ_VERSION}" STREQUAL "" AND NOT "$ENV{IGNITION_VERSION}" STREQUAL "")
message(DEPRECATION "Environment variable [IGNITION_VERSION] is deprecated. Use [GZ_VERSION] instead.")
set(ENV{GZ_VERSION} $ENV{IGNITION_VERSION})
endif()
# Edifice
if("$ENV{GZ_VERSION}" STREQUAL "edifice")
find_package(ignition-transport10 REQUIRED)
find_package(ignition-msgs7 REQUIRED)
set(GZ_TARGET_PREFIX ignition)
set(GZ_MSGS_VER ${ignition-msgs7_VERSION_MAJOR})
set(GZ_TRANSPORT_VER ${ignition-transport10_VERSION_MAJOR})
message(STATUS "Compiling against Ignition Edifice")
# Garden
elseif("$ENV{GZ_VERSION}" STREQUAL "garden")
find_package(gz-transport12 REQUIRED)
find_package(gz-msgs9 REQUIRED)
set(GZ_TARGET_PREFIX gz)
set(GZ_MSGS_VER ${gz-msgs9_VERSION_MAJOR})
set(GZ_TRANSPORT_VER ${gz-transport12_VERSION_MAJOR})
message(STATUS "Compiling against Gazebo Garden")
elseif("$ENV{GZ_VERSION}" STREQUAL "harmonic")
find_package(gz-transport13 REQUIRED)
find_package(gz-msgs10 REQUIRED)
set(GZ_TARGET_PREFIX gz)
set(GZ_MSGS_VER ${gz-msgs10_VERSION_MAJOR})
set(GZ_TRANSPORT_VER ${gz-transport13_VERSION_MAJOR})
message(STATUS "Compiling against Gazebo Harmonic")
# Default to Fortress
else()
find_package(ignition-transport11 REQUIRED)
find_package(ignition-msgs8 REQUIRED)
set(GZ_TARGET_PREFIX ignition)
set(GZ_MSGS_VER ${ignition-msgs8_VERSION_MAJOR})
set(GZ_TRANSPORT_VER ${ignition-transport11_VERSION_MAJOR})
message(STATUS "Compiling against Ignition Fortress")
endif()
set(GZ_MSGS_VERSION_MAJOR ${${GZ_TARGET_PREFIX}-msgs${GZ_MSGS_VER}_VERSION_MAJOR})
set(GZ_MSGS_VERSION_MINOR ${${GZ_TARGET_PREFIX}-msgs${GZ_MSGS_VER}_VERSION_MINOR})
set(GZ_MSGS_VERSION_PATCH ${${GZ_TARGET_PREFIX}-msgs${GZ_MSGS_VER}_VERSION_PATCH})
set(GZ_MSGS_VERSION_FULL ${GZ_MSGS_VERSION_MAJOR}.${GZ_MSGS_VERSION_MINOR}.${GZ_MSGS_VERSION_PATCH})
set(BRIDGE_MESSAGE_TYPES
builtin_interfaces
actuator_msgs
geometry_msgs
asv_interfaces
nav_msgs
rcl_interfaces
ros_gz_interfaces
rosgraph_msgs
sensor_msgs
std_msgs
tf2_msgs
trajectory_msgs
vision_msgs
)
set(generated_path "${CMAKE_BINARY_DIR}/generated")
set(generated_files "${generated_path}/get_factory.cpp")
list(APPEND generated_files "${generated_path}/get_mappings.cpp")
set(convert_files "src/convert/utils.cpp")
foreach(package_name ${BRIDGE_MESSAGE_TYPES})
find_package(${package_name} QUIET REQUIRED)
message(STATUS "Found ${package_name}: ${${package_name}_VERSION} (${${package_name}_DIR})")
list(APPEND generated_files "${generated_path}/factories/${package_name}.cpp")
list(APPEND generated_files "${generated_path}/factories/${package_name}.hpp")
list(APPEND convert_files "src/convert/${package_name}.cpp")
endforeach()
set(target_dependencies
"bin/ros_gz_bridge_generate_factories"
"resource/get_factory.cpp.em"
"resource/get_mappings.cpp.em"
"resource/pkg_factories.cpp.em"
"resource/pkg_factories.hpp.em"
"ros_gz_bridge/__init__.py"
"ros_gz_bridge/mappings.py")
find_package(Python3 REQUIRED COMPONENTS Interpreter)
add_custom_command(
OUTPUT ${generated_files}
COMMAND Python3::Interpreter
ARGS bin/ros_gz_bridge_generate_factories
--output-path "${generated_path}" --template-dir resource
--gz-msgs-ver "${GZ_MSGS_VERSION_FULL}"
DEPENDS ${target_dependencies}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating factories for interface types")
set(bridge_lib
ros_gz_bridge
)
add_library(${bridge_lib}
SHARED
src/bridge_config.cpp
src/bridge_handle.cpp
src/bridge_handle_ros_to_gz.cpp
src/bridge_handle_gz_to_ros.cpp
src/factory_interface.cpp
src/service_factory_interface.cpp
src/service_factories/ros_gz_interfaces.cpp
src/ros_gz_bridge.cpp
${convert_files}
${generated_files}
)
target_link_libraries(${bridge_lib}
${GZ_TARGET_PREFIX}-msgs${GZ_MSGS_VER}::core
${GZ_TARGET_PREFIX}-transport${GZ_TRANSPORT_VER}::core
)
ament_target_dependencies(${bridge_lib}
rclcpp
rclcpp_components
yaml_cpp_vendor
${BRIDGE_MESSAGE_TYPES}
)
target_include_directories(${bridge_lib}
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>"
PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/generated>"
)
target_link_libraries(${bridge_lib}
${GZ_TARGET_PREFIX}-msgs${GZ_MSGS_VER}::core
${GZ_TARGET_PREFIX}-transport${GZ_TRANSPORT_VER}::core
)
rclcpp_components_register_node(
${bridge_lib}
PLUGIN ros_gz_bridge::RosGzBridge
EXECUTABLE bridge_node)
install(TARGETS ${bridge_lib} EXPORT export_${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
install(
DIRECTORY include/
DESTINATION include/${PROJECT_NAME}
)
set(bridge_executables
parameter_bridge
static_bridge
bridge_types
)
foreach(bridge ${bridge_executables})
add_executable(${bridge}
src/${bridge}.cpp
)
target_link_libraries(${bridge}
${bridge_lib}
)
ament_target_dependencies(${bridge}
"rclcpp"
${BRIDGE_MESSAGE_TYPES}
)
install(TARGETS ${bridge}
RUNTIME DESTINATION lib/${PROJECT_NAME}
)
endforeach()
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
find_package(ament_cmake_gtest REQUIRED)
find_package(launch_testing_ament_cmake REQUIRED)
ament_find_gtest()
ament_add_gtest(test_rcl_interfaces
${PROJECT_SOURCE_DIR}/src/convert/rcl_interfaces.cpp
${PROJECT_SOURCE_DIR}/src/convert/rcl_interfaces_TEST.cpp
)
target_link_libraries(test_rcl_interfaces
${GZ_TARGET_PREFIX}-msgs${GZ_MSGS_VER}::core
${rcl_interfaces_TARGETS}
gtest
gtest_main
)
target_include_directories(test_rcl_interfaces
PRIVATE
${PROJECT_SOURCE_DIR}/include
)
ament_add_gtest(test_ros_gz_interfaces
${PROJECT_SOURCE_DIR}/src/convert/ros_gz_interfaces.cpp
${PROJECT_SOURCE_DIR}/src/convert/ros_gz_interfaces_TEST.cpp
)
target_link_libraries(test_ros_gz_interfaces
${bridge_lib}
${ros_gz_interfaces_TARGETS}
gtest
gtest_main
)
target_include_directories(test_ros_gz_interfaces
PRIVATE
${PROJECT_SOURCE_DIR}/include
)
add_library(test_utils
test/utils/gz_test_msg.cpp
test/utils/ros_test_msg.cpp
)
target_include_directories(test_utils
PUBLIC test ${GTEST_INCLUDE_DIRS} include
)
target_link_libraries(test_utils
${GTEST_LIBRARIES}
${GZ_TARGET_PREFIX}-msgs${GZ_MSGS_VER}::core
${GZ_TARGET_PREFIX}-transport${GZ_TRANSPORT_VER}::core
)
ament_target_dependencies(test_utils
rclcpp
${BRIDGE_MESSAGE_TYPES}
ros_gz_interfaces
rosgraph_msgs
sensor_msgs
std_msgs
tf2_msgs
trajectory_msgs
vision_msgs
)
set(generated_path "${CMAKE_BINARY_DIR}/generated/test")
set(generated_files
"${generated_path}/gz_publisher.cpp"
"${generated_path}/gz_subscriber.cpp"
"${generated_path}/ros_publisher.cpp"
)
set(ros_subscriber_files
"test/subscribers/ros_subscriber.cpp"
)
foreach(package_name ${BRIDGE_MESSAGE_TYPES})
list(APPEND generated_files "${generated_path}/${package_name}_subscriber.cpp")
list(APPEND ros_subscriber_files "${generated_path}/${package_name}_subscriber.cpp")
endforeach()
set(target_dependencies
"bin/ros_gz_bridge_generate_factories"
"test/resource/gz_publisher.cpp.em"
"test/resource/gz_subscriber.cpp.em"
"test/resource/ros_publisher.cpp.em"
"test/resource/ros_pkg_subscriber.cpp.em"
"ros_gz_bridge/__init__.py"
"ros_gz_bridge/mappings.py")
add_custom_command(
OUTPUT ${generated_files}
COMMAND Python3::Interpreter
ARGS bin/ros_gz_bridge_generate_tests
--output-path "${generated_path}" --template-dir test/resource/
--gz-msgs-ver "${GZ_MSGS_VERSION_FULL}"
DEPENDS ${target_dependencies}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating test helpers")
add_executable(test_gz_publisher ${generated_path}/gz_publisher.cpp)
target_link_libraries(test_gz_publisher test_utils)
add_executable(test_ros_publisher ${generated_path}/ros_publisher.cpp)
target_link_libraries(test_ros_publisher test_utils)
add_executable(test_gz_subscriber ${generated_path}/gz_subscriber.cpp)
target_link_libraries(test_gz_subscriber test_utils)
add_executable(test_gz_server test/serverclient/gz_server.cpp)
target_link_libraries(test_gz_server test_utils)
add_executable(test_ros_client test/serverclient/ros_client.cpp)
target_link_libraries(test_ros_client test_utils)
add_executable(test_ros_subscriber ${ros_subscriber_files})
target_link_libraries(test_ros_subscriber test_utils)
target_include_directories(test_ros_subscriber
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test/subscribers)
install(TARGETS
test_ros_publisher
test_ros_subscriber
test_gz_publisher
test_gz_subscriber
test_gz_server
test_ros_client
DESTINATION lib/${PROJECT_NAME}
)
add_launch_test(test/launch/test_ros_subscriber.launch.py
TIMEOUT 200
ARGS "gz_msgs_ver:=${GZ_MSGS_VERSION_FULL}"
)
add_launch_test(test/launch/test_gz_subscriber.launch.py
TIMEOUT 200
ARGS "gz_msgs_ver:=${GZ_MSGS_VERSION_FULL}"
)
add_launch_test(test/launch/test_gz_server.launch.py
TIMEOUT 200
)
ament_add_gtest(${PROJECT_NAME}_bridge_config test/bridge_config.cpp
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
target_include_directories(${PROJECT_NAME}_bridge_config PRIVATE src)
ament_target_dependencies(${PROJECT_NAME}_bridge_config rclcpp)
target_link_libraries(${PROJECT_NAME}_bridge_config ${bridge_lib})
endif()
# Export old-style CMake variables
ament_export_include_directories("include/${PROJECT_NAME}")
ament_export_libraries(${bridge_lib})
# Export modern CMake targets
ament_export_targets(export_${PROJECT_NAME})
# specific order: dependents before dependencies
ament_export_dependencies(rclcpp)
ament_export_dependencies(rclcpp_components)
ament_export_dependencies(${GZ_TARGET_PREFIX}-msgs${GZ_MSGS_VER})
ament_export_dependencies(${GZ_TARGET_PREFIX}-transport${GZ_TRANSPORT_VER})
ament_export_dependencies(yaml_cpp_vendor)
ament_export_dependencies(${BRIDGE_MESSAGE_TYPES})
ament_package()