Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find ROS1 message packages #67

Merged
merged 17 commits into from
Jun 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ endif()

find_ros1_package(std_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})
find_ros1_package(${ros1_message_package} REQUIRED)
list(APPEND prefixed_ros1_message_packages "ros1_${ros1_message_package}")
endforeach()

set(TEST_ROS1_BRIDGE FALSE)
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
Expand All @@ -58,8 +68,8 @@ set(generated_files "${generated_path}/get_factory.cpp")
list(APPEND generated_files "${generated_path}/get_mappings.cpp")

# generate per package compilation units to keep the memory usage low
ament_index_get_resources(message_packages "rosidl_interfaces")
foreach(message_package ${message_packages})
ament_index_get_resources(ros2_message_packages "rosidl_interfaces")
foreach(message_package ${ros2_message_packages})
find_package(${message_package} REQUIRED)
list(APPEND generated_files "${generated_path}/${message_package}_factories.cpp")
endforeach()
Expand Down Expand Up @@ -115,7 +125,8 @@ add_library(${PROJECT_NAME} SHARED
"src/convert_builtin_interfaces.cpp"
${generated_files})
ament_target_dependencies(${PROJECT_NAME}
${message_packages}
${prefixed_ros1_message_packages}
${ros2_message_packages}
"rclcpp"
"ros1_roscpp"
"ros1_std_msgs")
Expand All @@ -128,14 +139,14 @@ install(TARGETS ${PROJECT_NAME}
custom_executable(static_bridge
"src/static_bridge.cpp"
ROS1_DEPENDENCIES
TARGET_DEPENDENCIES ${message_packages})
TARGET_DEPENDENCIES ${ros2_message_packages})
target_link_libraries(static_bridge
${PROJECT_NAME})

custom_executable(dynamic_bridge
"src/dynamic_bridge.cpp"
ROS1_DEPENDENCIES
TARGET_DEPENDENCIES ${message_packages})
TARGET_DEPENDENCIES ${ros2_message_packages})
target_link_libraries(dynamic_bridge
${PROJECT_NAME})

Expand Down
66 changes: 66 additions & 0 deletions cmake/find_ros1_interface_packages.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright 2017 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

function(find_ros1_interface_packages var)
# rosmsg/rossrv require the ROS 1 packages to be first in the PYTHONPATH
# therefore we temporarily remove every ROS 2 path from the PYTHONPATH
file(TO_CMAKE_PATH "$ENV{AMENT_PREFIX_PATH}" AMENT_PREFIX_PATH)
set(_ORIG_PYTHONPATH "$ENV{PYTHONPATH}")
file(TO_CMAKE_PATH "${_ORIG_PYTHONPATH}" PYTHONPATH)
set(PYTHONPATH_WITHOUT_ROS2 "")
foreach(python_path IN LISTS PYTHONPATH)
set(match FALSE)
foreach(ament_prefix_path IN LISTS AMENT_PREFIX_PATH)
if(python_path MATCHES "^${ament_prefix_path}/")
set(match TRUE)
break()
endif()
endforeach()
if(NOT match)
list(APPEND PYTHONPATH_WITHOUT_ROS2 "${python_path}")
endif()
endforeach()
file(TO_NATIVE_PATH "${PYTHONPATH_WITHOUT_ROS2}" PYTHONPATH_WITHOUT_ROS2)
if(NOT WIN32)
string(REPLACE ";" ":" PYTHONPATH_WITHOUT_ROS2 "${PYTHONPATH_WITHOUT_ROS2}")
endif()
set(ENV{PYTHONPATH} "${PYTHONPATH_WITHOUT_ROS2}")

# find all known ROS1 message/service packages
execute_process(
COMMAND "rosmsg" "list"
OUTPUT_VARIABLE rosmsg_output
ERROR_VARIABLE rosmsg_error
)
execute_process(
COMMAND "rossrv" "list"
OUTPUT_VARIABLE rossrv_output
ERROR_VARIABLE rossrv_error
)

# restore PYTHONPATH
set(ENV{PYTHONPATH} ${_ORIG_PYTHONPATH})

if(NOT rosmsg_error STREQUAL "" OR NOT rossrv_error STREQUAL "")
message(FATAL_ERROR "${rosmsg_error}\n${rossrv_error}\nFailed to call rosmsg/rossrv")
endif()

set(ros1_message_packages "")
string(REPLACE "\n" ";" ros1_interfaces "${rosmsg_output}\n${rossrv_output}")
foreach(interface_package ${ros1_interfaces})
string(REGEX REPLACE "/.*$" "" interface_package "${interface_package}")
list_append_unique(ros1_message_packages ${interface_package})
endforeach()
set(${var} ${ros1_message_packages} PARENT_SCOPE)
endfunction()