-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
|
||
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() |
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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this 'condition' attribute currently supported? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. It's part of REP-149: Package Manifest Format Three Specification. |
||
<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> |
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} | ||
) |
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() |
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
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
source
d (fi when theros1bridge
is being used).There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
If with "this" you are referring to "
source
ing both" then it would be done both at runtime and at build time.There was a problem hiding this comment.
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?