diff --git a/rclcpp/CMakeLists.txt b/rclcpp/CMakeLists.txt index 88cddf4..20db4d1 100644 --- a/rclcpp/CMakeLists.txt +++ b/rclcpp/CMakeLists.txt @@ -3,36 +3,14 @@ cmake_minimum_required(VERSION 2.8.3) project(rclcpp) find_package(ament_cmake REQUIRED) -find_package(ros_middleware_interface REQUIRED) ament_export_dependencies(ros_middleware_interface) -set(_dds_vendor "$ENV{ROS_DDS_IMPLEMENTATION}") -set(_dds_type "$ENV{ROS_DDS_TYPE}") - -if(NOT "${_dds_type}" STREQUAL "dynamic" AND NOT "${_dds_type}" STREQUAL "static") - message(FATAL_ERROR "Set the environment variable 'ROS_DDS_TYPE' to either 'dynamic' or 'static'.") -endif() - -if("${_dds_vendor}" STREQUAL "connext") - if("${_dds_type}" STREQUAL "dynamic") - ament_export_dependencies(ros_dds_connext_dynamic) - elseif("${_dds_type}" STREQUAL "static") - ament_export_dependencies(rosidl_typesupport_connext_cpp ros_middleware_connext_cpp) - endif() -elseif("${_dds_vendor}" STREQUAL "opensplice") - if("${_dds_type}" STREQUAL "dynamic") - message(FATAL_ERROR "The DDS implementation '${_dds_vendor}' does not support the type '${_dds_type}'.") - elseif("${_dds_type}" STREQUAL "static") - ament_export_dependencies(rosidl_typesupport_opensplice_cpp) - endif() -else() - message(FATAL_ERROR "Set the environment variable 'ROS_DDS_IMPLEMENTATION' to either 'connext' or 'opensplice'.") -endif() - ament_export_include_directories(include) -ament_package() +ament_package( + CONFIG_EXTRAS "rclcpp-extras.cmake" +) install( DIRECTORY include/ diff --git a/rclcpp/include/rclcpp/Node.h b/rclcpp/include/rclcpp/Node.h index 7043bb8..418eb78 100644 --- a/rclcpp/include/rclcpp/Node.h +++ b/rclcpp/include/rclcpp/Node.h @@ -6,6 +6,8 @@ #include "ros_middleware_interface/functions.h" #include "ros_middleware_interface/handles.h" +#include "ros_middleware_interface/get_type_support_handle.h" + namespace rclcpp { @@ -21,7 +23,7 @@ public: template Publisher* create_publisher(const char * topic_name) { - const rosidl_generator_cpp::MessageTypeSupportHandle & type_support_handle = rosidl_generator_cpp::MessageTypeSupport::get_type_support_handle(); + const rosidl_generator_cpp::MessageTypeSupportHandle & type_support_handle = ::ros_middleware_interface::get_type_support_handle(); ros_middleware_interface::PublisherHandle publisher_handle = ::ros_middleware_interface::create_publisher(node_handle_, type_support_handle, topic_name); return new Publisher(publisher_handle); } diff --git a/rclcpp/package.xml b/rclcpp/package.xml index 25fa3f6..39bb7d8 100644 --- a/rclcpp/package.xml +++ b/rclcpp/package.xml @@ -8,8 +8,5 @@ ament_cmake - ros_middleware_interface - rosidl_default_generators - - ros_dds_connext_dynamic + ros_middleware_interface diff --git a/rclcpp/rclcpp-extras.cmake b/rclcpp/rclcpp-extras.cmake new file mode 100644 index 0000000..8f428c5 --- /dev/null +++ b/rclcpp/rclcpp-extras.cmake @@ -0,0 +1,36 @@ +# copied from rclcpp/rclcpp-extras.cmake + +# option() +set(_middleware_implementation "") +if(NOT "${ROS_MIDDLEWARE_IMPLEMENTATION}" STREQUAL "") + set(_middleware_implementation "${ROS_MIDDLEWARE_IMPLEMENTATION}") +elseif(NOT "$ENV{ROS_MIDDLEWARE_IMPLEMENTATION}" STREQUAL "") + set(_middleware_implementation "$ENV{ROS_MIDDLEWARE_IMPLEMENTATION}") +else() + # detemine "default" implementation based on the available ones + set(_middleware_implementation "ros_middleware_connext_cpp") + if("${_middleware_implementation}" STREQUAL "") + message(FATAL_ERROR "No middleware implementation available.") + endif() +endif() + +message("rclcpp_DEFINITIONS ${rclcpp_DEFINITIONS}") +message("rclcpp_INCLUDE_DIRS ${rclcpp_INCLUDE_DIRS}") +message("rclcpp_LIBRARIES ${rclcpp_LIBRARIES}") + +message(STATUS "Using middleware implementation: ${_middleware_implementation}") +find_package("${_middleware_implementation}" REQUIRED) + +# persist implementation decision in cache +set( + ROS_MIDDLEWARE_IMPLEMENTATION "${_middleware_implementation}" + CACHE STRING "Select ROS middleware implementation to link against" FORCE +) + +list(APPEND rclcpp_DEFINITIONS ${${ROS_MIDDLEWARE_IMPLEMENTATION}_DEFINITIONS}) +list(APPEND rclcpp_INCLUDE_DIRS ${${ROS_MIDDLEWARE_IMPLEMENTATION}_INCLUDE_DIRS}) +list(APPEND rclcpp_LIBRARIES ${${ROS_MIDDLEWARE_IMPLEMENTATION}_LIBRARIES}) + +message("rclcpp_DEFINITIONS ${rclcpp_DEFINITIONS}") +message("rclcpp_INCLUDE_DIRS ${rclcpp_INCLUDE_DIRS}") +message("rclcpp_LIBRARIES ${rclcpp_LIBRARIES}")