Skip to content

Commit

Permalink
feat: support ros2 build
Browse files Browse the repository at this point in the history
Signed-off-by: wep21 <daisuke.nishimatsu1021@gmail.com>
  • Loading branch information
wep21 authored and at-wat committed Oct 13, 2023
1 parent bdb4e6c commit 2f703b6
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 23 deletions.
77 changes: 59 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,61 @@
cmake_minimum_required(VERSION 2.8.3)
cmake_minimum_required(VERSION 3.5)
project(mcl_3dl_msgs)

set(MESSAGE_DEPENDS
std_msgs
)

find_package(catkin REQUIRED COMPONENTS message_generation ${MESSAGE_DEPENDS})

add_service_files(
FILES
ResizeParticle.srv
LoadPCD.srv
)
add_message_files(
FILES
Status.msg
)
generate_messages(DEPENDENCIES ${MESSAGE_DEPENDS})
catkin_package(CATKIN_DEPENDS message_runtime ${MESSAGE_DEPENDS})
find_package(ros_environment REQUIRED)

set(ROS_VERSION $ENV{ROS_VERSION})

if(${ROS_VERSION} EQUAL 1)

set(MESSAGE_DEPENDS
std_msgs
)

find_package(catkin REQUIRED COMPONENTS message_generation ${MESSAGE_DEPENDS})

add_service_files(
FILES
ResizeParticle.srv
LoadPCD.srv
)
add_message_files(
FILES
Status.msg
)
generate_messages(DEPENDENCIES ${MESSAGE_DEPENDS})
catkin_package(CATKIN_DEPENDS message_runtime ${MESSAGE_DEPENDS})

elseif(${ROS_VERSION} EQUAL 2)

if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 17)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

find_package(ament_cmake REQUIRED)
find_package(builtin_interfaces REQUIRED)
find_package(std_msgs REQUIRED)
find_package(rosidl_default_generators REQUIRED)

rosidl_generate_interfaces(${PROJECT_NAME}
msg/Status.msg
srv/LoadPCD.srv
srv/ResizeParticle.srv
DEPENDENCIES std_msgs
ADD_LINTER_TESTS
)

ament_export_dependencies(rosidl_default_runtime)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
endif()

ament_package()

endif()
24 changes: 19 additions & 5 deletions package.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<package format="2">
<package format="3">
<name>mcl_3dl_msgs</name>
<version>0.6.0</version>
<description>The mcl_3dl message definition package</description>
Expand All @@ -8,11 +8,25 @@
<license>BSD</license>
<author email="atsushi.w@ieee.org">Atsushi Watanabe</author>

<buildtool_depend>catkin</buildtool_depend>
<buildtool_depend condition="$ROS_VERSION == 2">catkin</buildtool_depend>
<buildtool_depend condition="$ROS_VERSION == 2">ament_cmake</buildtool_depend>

<build_depend>message_generation</build_depend>
<build_export_depend>message_runtime</build_export_depend>
<exec_depend>message_runtime</exec_depend>
<build_depend condition="$ROS_VERSION == 1">message_generation</build_depend>
<build_depend condition="$ROS_VERSION == 2">rosidl_default_generators</build_depend>
<build_depend>ros_environment</build_depend>

<depend>std_msgs</depend>

<exec_depend condition="$ROS_VERSION == 1">message_runtime</exec_depend>
<exec_depend condition="$ROS_VERSION == 2">rosidl_default_runtime</exec_depend>

<test_depend condition="$ROS_VERSION == 2">ament_lint_auto</test_depend>
<test_depend condition="$ROS_VERSION == 2">ament_lint_common</test_depend>

<member_of_group condition="$ROS_VERSION == 2">rosidl_interface_packages</member_of_group>

<export>
<build_type condition="$ROS_VERSION == 1">catkin</build_type>
<build_type condition="$ROS_VERSION == 2">ament_cmake</build_type>
</export>
</package>

0 comments on commit 2f703b6

Please sign in to comment.