From 116fcfb0019d029a4bc311cf968edbad397eb393 Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Thu, 22 Feb 2024 13:43:40 -0600 Subject: [PATCH] Correctly export ros_gz_bridge for downstream targets (#503) Signed-off-by: Michael Carroll --- ros_gz_bridge/CMakeLists.txt | 37 ++++++++++++------- test_ros_gz_bridge/CMakeLists.txt | 29 +++++++++++++++ test_ros_gz_bridge/package.xml | 28 ++++++++++++++ test_ros_gz_bridge/src/test_ros_gz_bridge.cpp | 36 ++++++++++++++++++ 4 files changed, 117 insertions(+), 13 deletions(-) create mode 100644 test_ros_gz_bridge/CMakeLists.txt create mode 100644 test_ros_gz_bridge/package.xml create mode 100644 test_ros_gz_bridge/src/test_ros_gz_bridge.cpp diff --git a/ros_gz_bridge/CMakeLists.txt b/ros_gz_bridge/CMakeLists.txt index 596dfd80..7df2399b 100644 --- a/ros_gz_bridge/CMakeLists.txt +++ b/ros_gz_bridge/CMakeLists.txt @@ -119,7 +119,7 @@ add_custom_command( COMMENT "Generating factories for interface types") set(bridge_lib - ros_gz_bridge_lib + ros_gz_bridge ) add_library(${bridge_lib} @@ -149,8 +149,12 @@ ament_target_dependencies(${bridge_lib} ) target_include_directories(${bridge_lib} - PUBLIC include - PRIVATE src ${generated_path} + PUBLIC + "$" + "$" + PRIVATE + "$" + "$" ) target_link_libraries(${bridge_lib} @@ -163,19 +167,16 @@ rclcpp_components_register_node( PLUGIN ros_gz_bridge::RosGzBridge EXECUTABLE bridge_node) -install(TARGETS ${bridge_lib} +install(TARGETS ${bridge_lib} EXPORT export_${PROJECT_NAME} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin) install( DIRECTORY include/ - DESTINATION include + DESTINATION include/${PROJECT_NAME} ) -ament_export_include_directories(include) -ament_export_libraries(${bridge_lib}) - set(bridge_executables parameter_bridge static_bridge @@ -194,7 +195,7 @@ foreach(bridge ${bridge_executables}) ${BRIDGE_MESSAGE_TYPES} ) install(TARGETS ${bridge} - DESTINATION lib/${PROJECT_NAME} + RUNTIME DESTINATION lib/${PROJECT_NAME} ) endforeach() @@ -349,9 +350,19 @@ if(BUILD_TESTING) endif() -ament_export_dependencies( - rclcpp - ${BRIDGE_MESSAGE_TYPES} -) +# Export old-style CMake variables +ament_export_include_directories("include/${PROJECT_NAME}") +ament_export_libraries(${bridge_lib}) + +# Export modern CMake targets +ament_export_targets(export_${PROJECT_NAME}) + +# specific order: dependents before dependencies +ament_export_dependencies(rclcpp) +ament_export_dependencies(rclcpp_components) +ament_export_dependencies(${GZ_TARGET_PREFIX}-msgs${GZ_MSGS_VER}) +ament_export_dependencies(${GZ_TARGET_PREFIX}-transport${GZ_TRANSPORT_VER}) +ament_export_dependencies(yaml_cpp_vendor) +ament_export_dependencies(${BRIDGE_MESSAGE_TYPES}) ament_package() diff --git a/test_ros_gz_bridge/CMakeLists.txt b/test_ros_gz_bridge/CMakeLists.txt new file mode 100644 index 00000000..9a3bb8a8 --- /dev/null +++ b/test_ros_gz_bridge/CMakeLists.txt @@ -0,0 +1,29 @@ +cmake_minimum_required(VERSION 3.5) + +project(test_ros_gz_bridge) + +# Default to C++14 +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 17) +endif() +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic") +endif() + +find_package(ament_cmake REQUIRED) +find_package(ros_gz_bridge REQUIRED) + + +if(BUILD_TESTING) + find_package(ament_lint_auto REQUIRED) + ament_lint_auto_find_test_dependencies() + + find_package(ament_cmake_gtest REQUIRED) + find_package(launch_testing_ament_cmake REQUIRED) + ament_find_gtest() + + ament_add_gtest(test_ros_gz_bridge src/test_ros_gz_bridge.cpp) + target_link_libraries(test_ros_gz_bridge ros_gz_bridge::ros_gz_bridge) +endif() + +ament_package() diff --git a/test_ros_gz_bridge/package.xml b/test_ros_gz_bridge/package.xml new file mode 100644 index 00000000..124b8044 --- /dev/null +++ b/test_ros_gz_bridge/package.xml @@ -0,0 +1,28 @@ + + + + test_ros_gz_bridge + 0.246.0 + Bridge communication between ROS and Gazebo Transport + Aditya Pande + Alejandro Hernandez + + Apache 2.0 + + Michael Carroll + + ament_cmake + + ros_gz_bridge + + ament_cmake_gtest + ament_lint_auto + ament_lint_common + launch_testing_ament_cmake + launch_ros + launch_testing + + + ament_cmake + + diff --git a/test_ros_gz_bridge/src/test_ros_gz_bridge.cpp b/test_ros_gz_bridge/src/test_ros_gz_bridge.cpp new file mode 100644 index 00000000..a32ca8e5 --- /dev/null +++ b/test_ros_gz_bridge/src/test_ros_gz_bridge.cpp @@ -0,0 +1,36 @@ +// Copyright 2024 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. + +#include + +#include + +class test_ros_gz_bridge : public ::testing::Test +{ +public: + static void SetUpTestCase() + { + rclcpp::init(0, nullptr); + } + + static void TearDownTestCase() + { + rclcpp::shutdown(); + } +}; + +TEST_F(test_ros_gz_bridge, SpawnNode) +{ + ros_gz_bridge::RosGzBridge node; +}