extract decision of used middleware implementation into separate package

This commit is contained in:
Dirk Thomas 2014-08-14 15:05:25 -07:00
parent 0559fafcd0
commit 45ee2dd2e1
7 changed files with 90 additions and 39 deletions

View file

@ -8,9 +8,7 @@ ament_export_dependencies(ros_middleware_interface)
ament_export_include_directories(include) ament_export_include_directories(include)
ament_package( ament_package()
CONFIG_EXTRAS "rclcpp-extras.cmake"
)
install( install(
DIRECTORY include/ DIRECTORY include/

View file

@ -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})

View file

@ -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}
)

View file

@ -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()

View file

@ -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()

View file

@ -0,0 +1,11 @@
<?xml version="1.0"?>
<package format="2">
<name>ros_middleware_implementation</name>
<version>0.0.0</version>
<description>The decision which ROS middleware implementation should be used for C++.</description>
<maintainer email="dthomas@osrfoundation.org">Dirk Thomas</maintainer>
<license>Apache License 2.0</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_export_depend>ament_cmake</buildtool_export_depend>
</package>

View file

@ -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})