forked from Dsobh/ros1_bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
404 lines (341 loc) · 13.6 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
cmake_minimum_required(VERSION 3.5)
project(ros1_bridge)
# 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)
endif()
find_package(rmw REQUIRED)
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rmw_implementation_cmake REQUIRED)
find_package(std_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(tf2_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(control_msgs REQUIRED)
find_package(trajectory_msgs REQUIRED)
find_package(rclcpp_action REQUIRED)
find_package(rcl_interfaces REQUIRED)
# find ROS 1 packages
set(cmake_extras_files cmake/find_ros1_package.cmake cmake/find_ros1_interface_packages.cmake)
include(cmake/find_ros1_package.cmake)
find_package(PkgConfig)
if(NOT PKG_CONFIG_FOUND)
message(WARNING "Failed to find PkgConfig, skipping...")
# call ament_package() to avoid ament_tools treating this as a plain CMake pkg
ament_package()
return()
endif()
find_ros1_package(roscpp)
if(NOT ros1_roscpp_FOUND)
message(WARNING "Failed to find ROS 1 roscpp, skipping...")
# call ament_package() to avoid ament_tools treating this as a plain CMake pkg
ament_package(
CONFIG_EXTRAS ${cmake_extras_files}
)
return()
endif()
find_ros1_package(std_msgs REQUIRED)
find_ros1_package(sensor_msgs REQUIRED)
find_ros1_package(nav_msgs REQUIRED)
find_ros1_package(tf2_msgs REQUIRED)
find_ros1_package(geometry_msgs REQUIRED)
find_ros1_package(control_msgs REQUIRED)
find_ros1_package(trajectory_msgs REQUIRED)
find_ros1_package(actionlib REQUIRED)
find_ros1_package(rosgraph_msgs REQUIRED)
# find ROS 1 packages with messages / services
include(cmake/find_ros1_interface_packages.cmake)
find_ros1_interface_packages(ros1_message_packages)
set(prefixed_ros1_message_packages "")
foreach(ros1_message_package ${ros1_message_packages})
# TODO(karsten1987): This is currently a workaround to work with ROS 2 classloader
# rather than ROS 1 classloader.
if(NOT "${ros1_message_package}" STREQUAL "nodelet")
find_ros1_package(${ros1_message_package} REQUIRED)
list(APPEND prefixed_ros1_message_packages "ros1_${ros1_message_package}")
endif()
endforeach()
set(TEST_ROS1_BRIDGE FALSE)
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
find_package(diagnostic_msgs REQUIRED)
find_ros1_package(diagnostic_msgs)
find_ros1_package(roslaunch)
ament_lint_auto_find_test_dependencies()
if(ros1_diagnostic_msgs_FOUND AND ros1_roslaunch_FOUND)
# ensure that the ROS 2 diagnostic_msgs was found by find_package
# and not the ROS 1 package
set(_ros1_diagnostic_msgs_DIR "${ros1_diagnostic_msgs_PREFIX}/share/diagnostic_msgs/cmake")
if("${diagnostic_msgs_DIR}" STREQUAL "${_ros1_diagnostic_msgs_DIR}")
# invalidate the cached result to retry finding the package next time
unset(diagnostic_msgs_DIR CACHE)
message(FATAL_ERROR "Failed to find ROS 2 package 'diagnostic_msgs'")
endif()
set(TEST_ROS1_BRIDGE TRUE)
endif()
endif()
ament_export_include_directories(include)
ament_export_libraries(${PROJECT_NAME})
ament_python_install_package(${PROJECT_NAME})
ament_package(
CONFIG_EXTRAS ${cmake_extras_files}
)
set(generated_path "${CMAKE_BINARY_DIR}/generated")
set(generated_files "${generated_path}/get_factory.cpp")
list(APPEND generated_files "${generated_path}/get_mappings.cpp")
# generate per interface compilation units to keep the memory usage low
ament_index_get_resources(ros2_interface_packages "rosidl_interfaces")
# actionlib_msgs is deprecated, but we will quiet the warning until the bridge has support for
# ROS actions: https://github.com/ros2/design/issues/195
set(actionlib_msgs_DEPRECATED_QUIET TRUE)
foreach(package_name ${ros2_interface_packages})
find_package(${package_name} QUIET REQUIRED)
message(STATUS "Found ${package_name}: ${${package_name}_VERSION} (${${package_name}_DIR})")
if(NOT "${package_name}" STREQUAL "builtin_interfaces")
list(APPEND generated_files "${generated_path}/${package_name}_factories.cpp")
list(APPEND generated_files "${generated_path}/${package_name}_factories.hpp")
foreach(interface_file ${${package_name}_IDL_FILES})
file(TO_CMAKE_PATH "${interface_file}" interface_name)
get_filename_component(interface_basename "${interface_name}" NAME_WE)
# skipping actions and request and response messages of services
if(NOT "${interface_name}" MATCHES "^(msg|srv)/" OR "${interface_basename}" MATCHES "_(Request|Response)$")
continue()
endif()
string(REPLACE "/" "__" interface_name "${interface_name}")
get_filename_component(interface_name "${interface_name}" NAME_WE)
list(APPEND generated_files "${generated_path}/${package_name}__${interface_name}__factories.cpp")
endforeach()
endif()
endforeach()
set(target_dependencies
"bin/ros1_bridge_generate_factories"
"resource/get_factory.cpp.em"
"resource/get_mappings.cpp.em"
"resource/interface_factories.cpp.em"
"resource/pkg_factories.cpp.em"
"resource/pkg_factories.hpp.em"
"ros1_bridge/__init__.py")
add_custom_command(
OUTPUT ${generated_files}
COMMAND ${PYTHON_EXECUTABLE} bin/ros1_bridge_generate_factories
--output-path "${generated_path}" --template-dir resource
DEPENDS ${target_dependencies}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating factories for interface types")
if(NOT WIN32)
# ignore warning in ROS 1 message headers
set_source_files_properties(${generated_files}
PROPERTIES COMPILE_FLAGS "-Wno-unused-parameter")
endif()
include_directories(include ${generated_path})
function(custom_executable target)
cmake_parse_arguments(
ARG "ROS1_DEPENDENCIES" "" "TARGET_DEPENDENCIES" ${ARGN})
add_executable(${target}
${ARG_UNPARSED_ARGUMENTS})
ament_target_dependencies(${target}
"rclcpp"
${ARG_TARGET_DEPENDENCIES})
if(ARG_ROS1_DEPENDENCIES)
ament_target_dependencies(${target}
"ros1_roscpp"
"ros1_std_msgs"
"ros1_sensor_msgs"
"ros1_nav_msgs"
"ros1_tf2_msgs"
"ros1_geometry_msgs"
"ros1_control_msgs"
"ros1_trajectory_msgs"
"ros1_actionlib"
"rosgraph_msgs")
endif()
if(ARG_DEPENDENCIES)
add_dependencies(${target} ${ARG_DEPENDENCIES})
endif()
install(TARGETS ${target}
DESTINATION lib/${PROJECT_NAME})
endfunction()
custom_executable(simple_bridge_1_to_2 "src/simple_bridge_1_to_2.cpp"
ROS1_DEPENDENCIES
TARGET_DEPENDENCIES "std_msgs")
custom_executable(simple_bridge_1_to_2_scan "src/simple_bridge_1_to_2_scan.cpp"
ROS1_DEPENDENCIES
TARGET_DEPENDENCIES "std_msgs" "sensor_msgs")
custom_executable(simple_bridge_1_to_2_odom "src/simple_bridge_1_to_2_odom.cpp"
ROS1_DEPENDENCIES
TARGET_DEPENDENCIES "std_msgs" "nav_msgs")
custom_executable(simple_bridge_1_to_2_tf "src/simple_bridge_1_to_2_tf.cpp"
ROS1_DEPENDENCIES
TARGET_DEPENDENCIES "std_msgs" "tf2_msgs")
custom_executable(simple_bridge_2_to_1_twist "src/simple_bridge_2_to_1_twist.cpp"
ROS1_DEPENDENCIES
TARGET_DEPENDENCIES "std_msgs" "geometry_msgs" "nav_msgs")
# custom_executable(simple_bridge_1_to_2_twist "src/simple_bridge_1_to_2_twist.cpp"
# ROS1_DEPENDENCIES
# TARGET_DEPENDENCIES "std_msgs" "geometry_msgs" "nav_msgs")
custom_executable(simple_bridge_1_to_2_image "src/simple_bridge_1_to_2_image.cpp"
ROS1_DEPENDENCIES
TARGET_DEPENDENCIES "std_msgs" "sensor_msgs")
custom_executable(simple_bridge_1_to_2_imu "src/simple_bridge_1_to_2_imu.cpp"
ROS1_DEPENDENCIES
TARGET_DEPENDENCIES "std_msgs" "sensor_msgs")
custom_executable(simple_bridge_1_to_2_sonar "src/simple_bridge_1_to_2_sonar.cpp"
ROS1_DEPENDENCIES
TARGET_DEPENDENCIES "std_msgs" "sensor_msgs")
custom_executable(simple_bridge_1_to_2_compressed "src/simple_bridge_1_to_2_compressed.cpp"
ROS1_DEPENDENCIES
TARGET_DEPENDENCIES "std_msgs" "sensor_msgs")
custom_executable(simple_bridge_1_to_2_point_cloud "src/simple_bridge_1_to_2_point_cloud.cpp"
ROS1_DEPENDENCIES
TARGET_DEPENDENCIES "std_msgs" "sensor_msgs")
custom_executable(simple_bridge_1_to_2_camera_info "src/simple_bridge_1_to_2_camera_info.cpp"
ROS1_DEPENDENCIES
TARGET_DEPENDENCIES "std_msgs" "sensor_msgs")
custom_executable(simple_bridge_1_to_2_joint_trajectory_controller_state "src/simple_bridge_1_to_2_joint_trajectory_controller_state.cpp"
ROS1_DEPENDENCIES
TARGET_DEPENDENCIES "std_msgs" "control_msgs" "trajectory_msgs")
custom_executable(simple_bridge_2_to_1 "src/simple_bridge_2_to_1.cpp"
ROS1_DEPENDENCIES
TARGET_DEPENDENCIES "std_msgs"
)
custom_executable(simple_bridge_2_to_1_joint_trajectory "src/simple_bridge_2_to_1_joint_trajectory.cpp"
ROS1_DEPENDENCIES
TARGET_DEPENDENCIES "std_msgs" "trajectory_msgs"
)
custom_executable(simple_bridge "src/simple_bridge.cpp"
ROS1_DEPENDENCIES
TARGET_DEPENDENCIES "std_msgs")
custom_executable(moveit_2_to_1 "src/action_bridge_follow_joint_trajectory_2_1.cpp"
ROS1_DEPENDENCIES
TARGET_DEPENDENCIES "rclcpp_action" "control_msgs")
custom_executable(simple_bridge_1_to_2_log "src/simple_bridge_1_to_2_log.cpp"
ROS1_DEPENDENCIES
TARGET_DEPENDENCIES "rcl_interfaces" "rosgraph_msgs")
custom_executable(simple_bridge_1_to_2_jointState "src/simple_bridge_1_to_2_joint_state.cpp"
ROS1_DEPENDENCIES
TARGET_DEPENDENCIES "sensor_msgs")
custom_executable(head_controller "src/action_bridge_head_controller.cpp"
ROS1_DEPENDENCIES
TARGET_DEPENDENCIES "rclcpp_action" "control_msgs")
custom_executable(torso_controller "src/action_bridge_torso_controller.cpp"
ROS1_DEPENDENCIES
TARGET_DEPENDENCIES "rclcpp_action" "control_msgs")
custom_executable(gripper_controller "src/action_bridge_gripper_controller.cpp"
ROS1_DEPENDENCIES
TARGET_DEPENDENCIES "rclcpp_action" "control_msgs")
add_library(${PROJECT_NAME} SHARED
"src/builtin_interfaces_factories.cpp"
"src/convert_builtin_interfaces.cpp"
"src/bridge.cpp"
${generated_files})
ament_target_dependencies(${PROJECT_NAME}
${prefixed_ros1_message_packages}
${ros2_interface_packages}
"rclcpp"
"ros1_roscpp"
"ros1_std_msgs"
"ros1_sensor_msgs"
"ros1_nav_msgs"
"ros1_tf2_msgs"
"ros1_geometry_msgs"
"ros1_control_msgs"
"ros1_rosgraph_msgs")
install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
custom_executable(static_bridge
"src/static_bridge.cpp"
ROS1_DEPENDENCIES
TARGET_DEPENDENCIES ${ros2_interface_packages})
target_link_libraries(static_bridge
${PROJECT_NAME})
custom_executable(parameter_bridge
"src/parameter_bridge.cpp"
ROS1_DEPENDENCIES
TARGET_DEPENDENCIES ${message_packages})
target_link_libraries(parameter_bridge
${PROJECT_NAME})
custom_executable(dynamic_bridge
"src/dynamic_bridge.cpp"
ROS1_DEPENDENCIES
TARGET_DEPENDENCIES ${ros2_interface_packages})
target_link_libraries(dynamic_bridge
${PROJECT_NAME})
if(TEST_ROS1_BRIDGE)
custom_executable(test_ros2_client_cpp "test/test_ros2_client.cpp")
ament_target_dependencies("test_ros2_client_cpp${target_suffix}" "ros1_roscpp" "diagnostic_msgs")
custom_executable(test_ros2_server_cpp "test/test_ros2_server.cpp")
ament_target_dependencies("test_ros2_server_cpp${target_suffix}" "ros1_roscpp" "diagnostic_msgs")
set(TEST_BRIDGE_DYNAMIC_BRIDGE "$<TARGET_FILE:dynamic_bridge>")
set(TEST_BRIDGE_ROS2_CLIENT "$<TARGET_FILE:test_ros2_client_cpp>")
set(TEST_BRIDGE_ROS2_SERVER "$<TARGET_FILE:test_ros2_server_cpp>")
endif()
macro(targets)
set(TEST_BRIDGE_RMW ${rmw_implementation})
configure_file(
test/test_topics_across_dynamic_bridge.py.in
test_topics_across_dynamic_bridge${target_suffix}.py.genexp
@ONLY
)
file(GENERATE
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/test_topics_across_dynamic_bridge${target_suffix}_$<CONFIG>.py"
INPUT "${CMAKE_CURRENT_BINARY_DIR}/test_topics_across_dynamic_bridge${target_suffix}.py.genexp"
)
add_launch_test(
"${CMAKE_CURRENT_BINARY_DIR}/test_topics_across_dynamic_bridge${target_suffix}_$<CONFIG>.py"
TARGET test_topics_across_dynamic_bridge${target_suffix}
ENV RMW_IMPLEMENTATION=${rmw_implementation}
TIMEOUT 60)
configure_file(
test/test_services_across_dynamic_bridge.py.in
test_services_across_dynamic_bridge${target_suffix}.py.genexp
@ONLY
)
file(GENERATE
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/test_services_across_dynamic_bridge${target_suffix}_$<CONFIG>.py"
INPUT "${CMAKE_CURRENT_BINARY_DIR}/test_services_across_dynamic_bridge${target_suffix}.py.genexp"
)
add_launch_test(
"${CMAKE_CURRENT_BINARY_DIR}/test_services_across_dynamic_bridge${target_suffix}_$<CONFIG>.py"
TARGET test_services_across_dynamic_bridge${target_suffix}
ENV RMW_IMPLEMENTATION=${rmw_implementation}
TIMEOUT 60)
endmacro()
if(TEST_ROS1_BRIDGE)
find_package(launch_testing_ament_cmake REQUIRED)
add_executable(test_ros1_client "test/test_ros1_client.cpp")
ament_target_dependencies(test_ros1_client "ros1_diagnostic_msgs" "ros1_roscpp")
add_executable(test_ros1_server "test/test_ros1_server.cpp")
ament_target_dependencies(test_ros1_server "ros1_diagnostic_msgs" "ros1_roscpp")
set(TEST_BRIDGE_ROS1_ENV "${ros1_roslaunch_PREFIX}/env.sh")
set(TEST_BRIDGE_ROSCORE "${ros1_roslaunch_PREFIX}/bin/roscore")
set(TEST_BRIDGE_ROS1_CLIENT "$<TARGET_FILE:test_ros1_client>")
set(TEST_BRIDGE_ROS1_SERVER "$<TARGET_FILE:test_ros1_server>")
call_for_each_rmw_implementation(targets)
endif()
install(
PROGRAMS bin/ros1_bridge_generate_factories
DESTINATION lib/${PROJECT_NAME}/generate_factories
)
install(
DIRECTORY cmake
DESTINATION share/${PROJECT_NAME}
)
install(
DIRECTORY include/
DESTINATION include
)
install(
DIRECTORY resource
DESTINATION share/${PROJECT_NAME}
)
install(
DIRECTORY launch
DESTINATION share/${PROJECT_NAME}
)