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

Example of single package containing both ros1 and ros2 code #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions src/bar_ros/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.5.0)
project(bar_ros)

find_package(catkin QUIET)
find_package(ament_cmake QUIET)
Comment on lines +4 to +5

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note that both could be found in situations where both ROS 1 and ROS 2 have been sourced (fi when the ros1bridge is being used).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something you would do when building or only when running things?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am assuming this should not be done when building so I could added a check if both are found it would error.

Copy link

@gavanderhoorn gavanderhoorn Jan 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something you would do when building or only when running things?

Both. For custom messages or services the bridge needs to be rebuilt. That would be something users will want to do I believe in many cases.

I am assuming this should not be done when building so I could added a check if both are found it would error.

If with "this" you are referring to "sourceing both" then it would be done both at runtime and at build time.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is the case then will there be package name conflicts between ros1 and ros2 packages with the same name?


if (catkin_FOUND)
include(ros1/ros.cmake)
elseif(ament_cmake_FOUND)
include(ros2/ros.cmake)
else()
message(FATAL_ERROR "ROS build tool not found.")
endif()
24 changes: 24 additions & 0 deletions src/bar_ros/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<package format="3">
<name>bar_ros</name>
<version>0.0.1</version>
<description>The bar package</description>

<maintainer email="[email protected]">rre</maintainer>
<license>BSD</license>

<buildtool_depend condition="$ROS_VERSION == 1">catkin</buildtool_depend>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this 'condition' attribute currently supported?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<depend condition="$ROS_VERSION == 1">roscpp</depend>

<buildtool_depend condition="$ROS_VERSION == 2">ament_cmake</buildtool_depend>
<depend condition="$ROS_VERSION == 2">rclcpp</depend>
<test_depend condition="$ROS_VERSION == 2">ament_lint_auto</test_depend>
<test_depend condition="$ROS_VERSION == 2">ament_lint_common</test_depend>

<depend>lib_foo</depend>

<export>
<build_type condition="$ROS_VERSION == 1">catkin</build_type>
<build_type condition="$ROS_VERSION == 2">ament_cmake</build_type>
</export>
</package>
29 changes: 29 additions & 0 deletions src/bar_ros/ros1/ros.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
find_package(catkin REQUIRED COMPONENTS
roscpp
)

find_package(lib_foo REQUIRED)

catkin_package(
# INCLUDE_DIRS include
# LIBRARIES bar_ros1
# CATKIN_DEPENDS lib_foo roscpp
# DEPENDS system_lib
)

include_directories(
# include
${catkin_INCLUDE_DIRS}
${lib_foo_INCLUDE_DIRS}
)

add_executable(${PROJECT_NAME}_node ros1/src/bar_node.cpp)
target_link_libraries(${PROJECT_NAME}_node
${catkin_LIBRARIES}
${lib_foo_LIBRARIES}
)
install(TARGETS ${PROJECT_NAME}_node
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
File renamed without changes.
39 changes: 39 additions & 0 deletions src/bar_ros/ros2/ros.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()

# 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()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(lib_foo REQUIRED)

include_directories(include ${lib_foo_INCLUDE_DIRS})

add_executable(${PROJECT_NAME}_node ros2/src/bar_node.cpp)
ament_target_dependencies(${PROJECT_NAME}_node rclcpp)
target_link_libraries(${PROJECT_NAME}_node ${lib_foo_LIBRARIES})

install(TARGETS ${PROJECT_NAME}_node DESTINATION lib/${PROJECT_NAME})

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# uncomment the line when a copyright and license is not present in all source files
#set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# uncomment the line when this package is not in a git repo
#set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()

ament_package()
File renamed without changes.
205 changes: 0 additions & 205 deletions src/bar_ros1/CMakeLists.txt

This file was deleted.

60 changes: 0 additions & 60 deletions src/bar_ros1/package.xml

This file was deleted.

Loading