From 45ee2dd2e1168b8f30b8770eb268496b841a7b8e Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Thu, 14 Aug 2014 15:05:25 -0700 Subject: [PATCH] extract decision of used middleware implementation into separate package --- rclcpp/CMakeLists.txt | 4 +- rclcpp/rclcpp-extras.cmake | 36 ---------------- ros_middleware_implementation/CMakeLists.txt | 14 +++++++ ...lable_ros_middleware_implementations.cmake | 10 +++++ ...efault_ros_middleware_implementation.cmake | 42 +++++++++++++++++++ ros_middleware_implementation/package.xml | 11 +++++ ...ros_middleware_implementation-extras.cmake | 12 ++++++ 7 files changed, 90 insertions(+), 39 deletions(-) delete mode 100644 rclcpp/rclcpp-extras.cmake create mode 100644 ros_middleware_implementation/CMakeLists.txt create mode 100644 ros_middleware_implementation/cmake/get_available_ros_middleware_implementations.cmake create mode 100644 ros_middleware_implementation/cmake/get_default_ros_middleware_implementation.cmake create mode 100644 ros_middleware_implementation/package.xml create mode 100644 ros_middleware_implementation/ros_middleware_implementation-extras.cmake diff --git a/rclcpp/CMakeLists.txt b/rclcpp/CMakeLists.txt index 20db4d1..6dd03e2 100644 --- a/rclcpp/CMakeLists.txt +++ b/rclcpp/CMakeLists.txt @@ -8,9 +8,7 @@ ament_export_dependencies(ros_middleware_interface) ament_export_include_directories(include) -ament_package( - CONFIG_EXTRAS "rclcpp-extras.cmake" -) +ament_package() install( DIRECTORY include/ diff --git a/rclcpp/rclcpp-extras.cmake b/rclcpp/rclcpp-extras.cmake deleted file mode 100644 index 2972d63..0000000 --- a/rclcpp/rclcpp-extras.cmake +++ /dev/null @@ -1,36 +0,0 @@ -# copied from rclcpp/rclcpp-extras.cmake - -ament_index_get_resources(_middleware_implementations "ros_middleware_implementation") -if("${_middleware_implementations}" STREQUAL "") - message(FATAL_ERROR "Could not find any ROS middleware implementation.") -endif() - -set(_middleware_implementation "") -# option() -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() - # TODO detemine "default" implementation based on the available ones - list(GET _middleware_implementations 0 _middleware_implementation) -endif() - -list(FIND _middleware_implementations "${_middleware_implementation}" _index) -if(_index EQUAL -1) - string(REPLACE ";" ", " _middleware_implementations_string "${_middleware_implementations}") - message(FATAL_ERROR "Could not find ROS middleware implementation '${_middleware_implementation}'. Choose one of the following: ${_middleware_implementations_string}") -endif() - -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}) diff --git a/ros_middleware_implementation/CMakeLists.txt b/ros_middleware_implementation/CMakeLists.txt new file mode 100644 index 0000000..495c483 --- /dev/null +++ b/ros_middleware_implementation/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 2.8.3) + +project(ros_middleware_implementation) + +find_package(ament_cmake REQUIRED) + +ament_package( + CONFIG_EXTRAS "ros_middleware_implementation-extras.cmake" +) + +install( + DIRECTORY cmake + DESTINATION share/${PROJECT_NAME} +) diff --git a/ros_middleware_implementation/cmake/get_available_ros_middleware_implementations.cmake b/ros_middleware_implementation/cmake/get_available_ros_middleware_implementations.cmake new file mode 100644 index 0000000..2a0ca70 --- /dev/null +++ b/ros_middleware_implementation/cmake/get_available_ros_middleware_implementations.cmake @@ -0,0 +1,10 @@ +# +# Get the package names of the available ROS middleware implemenations. +# +# :param var: the output variable name containing the package names +# :type var: list of strings +# +function(get_available_ros_middleware_implementations var) + ament_index_get_resources(middleware_implementations "ros_middleware_implementation") + set(${var} ${middleware_implementations} PARENT_SCOPE) +endfunction() diff --git a/ros_middleware_implementation/cmake/get_default_ros_middleware_implementation.cmake b/ros_middleware_implementation/cmake/get_default_ros_middleware_implementation.cmake new file mode 100644 index 0000000..d2b09bb --- /dev/null +++ b/ros_middleware_implementation/cmake/get_default_ros_middleware_implementation.cmake @@ -0,0 +1,42 @@ +# +# Get the package name of the default ROS middleware implemenation. +# +# Either selcting it using the variable ROS_MIDDLEWARE_IMPLEMENTATION or +# choosing a default from the available implementations. +# +# :param var: the output variable name containing the package name +# :type var: string +# +function(get_default_ros_middleware_implementation var) + get_available_ros_middleware_implementations(middleware_implementations) + + if("${middleware_implementations}" STREQUAL "") + message(FATAL_ERROR "Could not find any ROS middleware implementation.") + endif() + + # option() + 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() + # TODO detemine "default" implementation based on the available ones + list(GET middleware_implementations 0 middleware_implementation) + endif() + + # verify that the selection one is available + list(FIND middleware_implementations "${middleware_implementation}" _index) + if(_index EQUAL -1) + string(REPLACE ";" ", " middleware_implementations_string "${middleware_implementations}") + message(FATAL_ERROR "Could not find ROS middleware implementation '${middleware_implementation}'. Choose one of the following: ${middleware_implementations_string}") + endif() + 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 + ) + + set(${var} ${middleware_implementation} PARENT_SCOPE) +endfunction() diff --git a/ros_middleware_implementation/package.xml b/ros_middleware_implementation/package.xml new file mode 100644 index 0000000..6e9e9aa --- /dev/null +++ b/ros_middleware_implementation/package.xml @@ -0,0 +1,11 @@ + + + ros_middleware_implementation + 0.0.0 + The decision which ROS middleware implementation should be used for C++. + Dirk Thomas + Apache License 2.0 + + ament_cmake + ament_cmake + diff --git a/ros_middleware_implementation/ros_middleware_implementation-extras.cmake b/ros_middleware_implementation/ros_middleware_implementation-extras.cmake new file mode 100644 index 0000000..4f57cc4 --- /dev/null +++ b/ros_middleware_implementation/ros_middleware_implementation-extras.cmake @@ -0,0 +1,12 @@ +# copied from ros_middleware_implementation/ros_middleware_implementation-extras.cmake + +include("${ros_middleware_implementation_DIR}/get_available_ros_middleware_implementations.cmake") +include("${ros_middleware_implementation_DIR}/get_default_ros_middleware_implementation.cmake") + +get_default_ros_middleware_implementation(_middleware_implementation) +find_package("${_middleware_implementation}" REQUIRED) + +# TODO should never need definitions and include dirs? +list(APPEND ros_middleware_implementation_DEFINITIONS ${${_middleware_implementation}_DEFINITIONS}) +list(APPEND ros_middleware_implementation_INCLUDE_DIRS ${${_middleware_implementation}_INCLUDE_DIRS}) +list(APPEND ros_middleware_implementation_LIBRARIES ${${_middleware_implementation}_LIBRARIES})