From 14a36811e25993255cea6ddd47d82378ea0ed210 Mon Sep 17 00:00:00 2001 From: Patrick Roncagliolo Date: Tue, 9 Apr 2024 09:58:50 +0200 Subject: [PATCH] Make Player a `rosbag2` component --- rosbag2/CMakeLists.txt | 58 ++++++++++++++++++++++++ rosbag2/src/rosbag2/component_player.cpp | 14 ++++++ 2 files changed, 72 insertions(+) create mode 100644 rosbag2/src/rosbag2/component_player.cpp diff --git a/rosbag2/CMakeLists.txt b/rosbag2/CMakeLists.txt index 407d502b35..e2e493286c 100644 --- a/rosbag2/CMakeLists.txt +++ b/rosbag2/CMakeLists.txt @@ -1,5 +1,63 @@ cmake_minimum_required(VERSION 3.5) project(rosbag2) +# Default to C99 +if(NOT CMAKE_C_STANDARD) + set(CMAKE_C_STANDARD 99) +endif() + +# Default to C++17 +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD_REQUIRED ON) +endif() + +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wall -Wextra -Wpedantic) +endif() +if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND MSVC) + # /bigobj is needed to avoid error C1128: + # https://msdn.microsoft.com/en-us/library/8578y171.aspx + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj") +endif() + +# Windows supplies macros for min and max by default. We should only use min and max from stl +if(WIN32) + add_definitions(-DNOMINMAX) +endif() + find_package(ament_cmake REQUIRED) +find_package(rclcpp_components REQUIRED) +find_package(rosbag2_transport REQUIRED) + +add_library(${PROJECT_NAME} SHARED + src/rosbag2/component_player.cpp +) + +target_link_libraries(${PROJECT_NAME} + rclcpp::rclcpp + ${rclcpp_components_TARGETS} + rosbag2_transport::rosbag2_transport +) + +rclcpp_components_register_node(${PROJECT_NAME} + PLUGIN "rosbag2::Player" + EXECUTABLE player +) + +install( + TARGETS ${PROJECT_NAME} + EXPORT export_${PROJECT_NAME} + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin +) + +ament_export_libraries(${PROJECT_NAME}) + +ament_export_dependencies( + rclcpp_components + rosbag2_transport +) + ament_package() diff --git a/rosbag2/src/rosbag2/component_player.cpp b/rosbag2/src/rosbag2/component_player.cpp new file mode 100644 index 0000000000..82235b0158 --- /dev/null +++ b/rosbag2/src/rosbag2/component_player.cpp @@ -0,0 +1,14 @@ +#include "rosbag2_transport/player.hpp" + +namespace rosbag2 { +class Player : public rosbag2_transport::Player { + using rosbag2_transport::Player::Player; +}; +} + +#include "rclcpp_components/register_node_macro.hpp" + +// Register the component with class_loader. +// This acts as a sort of entry point, allowing the component to be +// discoverable when its library is being loaded into a running process. +RCLCPP_COMPONENTS_REGISTER_NODE(rosbag2::Player) \ No newline at end of file