Skip to content

Commit

Permalink
make rmw_implementation a meta rmw implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dirk-thomas committed Jan 5, 2017
1 parent 4e9f8a3 commit 52a46ba
Show file tree
Hide file tree
Showing 4 changed files with 631 additions and 28 deletions.
54 changes: 51 additions & 3 deletions rmw_implementation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
cmake_minimum_required(VERSION 3.5)

# must be not NONE since some rmw implementation require compiler checks
project(rmw_implementation)

if(NOT WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra")
endif()

find_package(ament_cmake REQUIRED)
# provides FindPoco.cmake and Poco on platforms without it
find_package(poco_vendor)
find_package(Poco COMPONENTS Foundation)
find_package(rmw_implementation_cmake REQUIRED)

if(BUILD_TESTING)
Expand All @@ -13,17 +19,59 @@ endif()

get_default_rmw_implementation(RMW_IMPLEMENTATION)

get_available_rmw_implementations(impls)
get_available_rmw_implementations(RMW_IMPLEMENTATIONS)
message(STATUS "")
message(STATUS "Found these rmw implementations:")
foreach(impl IN LISTS impls)
foreach(impl IN LISTS RMW_IMPLEMENTATIONS)
message(STATUS " '${impl}'")
endforeach()

message(STATUS "")
message(STATUS "Using default rmw implementation: '${RMW_IMPLEMENTATION}'")
message(STATUS "")

# if only a single rmw impl. is available or poco is not available
# this package will directly reference the default rmw impl.
if(NOT RMW_IMPLEMENTATIONS MATCHES ";" OR NOT Poco_FOUND)
set(RMW_IMPLEMENTATION_SUPPORTS_POCO FALSE)

else()
set(RMW_IMPLEMENTATION_SUPPORTS_POCO TRUE)
find_package(rmw REQUIRED)

message(STATUS "Support runtime override with any of the available rmw implementations")
message(STATUS "")
link_directories(${Poco_LIBRARY_DIR})
add_library(${PROJECT_NAME} SHARED
src/functions.cpp)
ament_target_dependencies(${PROJECT_NAME}
"Poco"
"rmw")
target_compile_definitions(${PROJECT_NAME}
PUBLIC "DEFAULT_RMW_IMPLEMENTATION=${RMW_IMPLEMENTATION}")
target_link_libraries(${PROJECT_NAME})
configure_rmw_library(${PROJECT_NAME})

ament_export_libraries(${PROJECT_NAME})
if(NOT WIN32)
ament_export_libraries(pthread)
endif()

install(
TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
endif()

register_rmw_implementation(
"c:rosidl_typesupport_c"
"cpp:rosidl_typesupport_cpp"
)

# necessary since get_available_rmw_implementations excludes rmw_implementation
list(APPEND RMW_IMPLEMENTATIONS "rmw_implementation")
ament_package(
CONFIG_EXTRAS "rmw_implementation-extras.cmake.in"
)
4 changes: 4 additions & 0 deletions rmw_implementation/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

<buildtool_depend>ament_cmake</buildtool_depend>

<build_depend>rmw</build_depend>

<depend>libpoco-dev</depend>
<depend>poco_vendor</depend>
<depend>rmw_implementation_cmake</depend>
<depend>rmw_connext_cpp</depend>
<depend>rmw_connext_dynamic_cpp</depend>
Expand Down
75 changes: 50 additions & 25 deletions rmw_implementation/rmw_implementation-extras.cmake.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2015 Open Source Robotics Foundation, Inc.
# Copyright 2014-2016 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.
Expand All @@ -16,38 +16,63 @@

find_package(rmw_implementation_cmake REQUIRED)
set(default_rmw_implementation "@RMW_IMPLEMENTATION@")
set(available_rmw_implementations "@RMW_IMPLEMENTATIONS@")

if(NOT "${RMW_IMPLEMENTATION}" STREQUAL "")
set(requested_default_rmw_implementation ${RMW_IMPLEMENTATION})
if(NOT requested_default_rmw_implementation STREQUAL default_rmw_implementation)
message(FATAL_ERROR
"The default RMW implementation has been specified as "
"'${requested_default_rmw_implementation}' through CMake,"
"however the default RMW implementation which will be used is "
"'${default_rmw_implementation}', which was specified when the "
"'rmw_implementation' package was built.")
set(requested_rmw_implementation ${RMW_IMPLEMENTATION})
if(@RMW_IMPLEMENTATION_SUPPORTS_POCO@)
if(NOT requested_rmw_implementation IN_LIST available_rmw_implementations)
message(FATAL_ERROR
"The RMW implementation has been specified as "
"'${requested_rmw_implementation}' through CMake, "
"however it is not in the list of supported rmw implementations, "
"which was specified when the 'rmw_implementation' package was built.")
endif()
else()
if(NOT requested_rmw_implementation STREQUAL default_rmw_implementation)
message(FATAL_ERROR
"The RMW implementation has been specified as "
"'${requested_rmw_implementation}' through CMake, "
"however this needs to match the RMW implementation "
"'${default_rmw_implementation}', "
"which was specified when the 'rmw_implementation' package was built.")
endif()
endif()
endif()

if(NOT "$ENV{RMW_IMPLEMENTATION}" STREQUAL "")
set(requested_default_rmw_implementation $ENV{RMW_IMPLEMENTATION})
if(NOT requested_default_rmw_implementation STREQUAL default_rmw_implementation)
message(FATAL_ERROR
"The default RMW implementation has been specified as "
"'${requested_default_rmw_implementation}' "
"through the environment variable 'RMW_IMPLEMENTATION', "
"however the default RMW implementation which will be used is "
"'${default_rmw_implementation}', which was specified when the "
"'rmw_implementation' package was built.")
set(requested_rmw_implementation $ENV{RMW_IMPLEMENTATION})
if(@RMW_IMPLEMENTATION_SUPPORTS_POCO@)
if(NOT requested_rmw_implementation IN_LIST available_rmw_implementations)
message(FATAL_ERROR
"The RMW implementation has been specified as "
"'${requested_rmw_implementation}' through the environment variable "
"'RMW_IMPLEMENTATION', "
"however it is not in the list of supported rmw implementations, "
"which was specified when the 'rmw_implementation' package was built.")
endif()
else()
if(NOT requested_rmw_implementation STREQUAL default_rmw_implementation)
message(FATAL_ERROR
"The RMW implementation has been specified as "
"'${requested_rmw_implementation}' "
"through the environment variable 'RMW_IMPLEMENTATION', "
"however this needs to match the RMW implementation "
"'${default_rmw_implementation}', "
"which was specified when the 'rmw_implementation' package was built.")
endif()
endif()
endif()


set(RMW_IMPLEMENTATION "${default_rmw_implementation}")
message(STATUS "Using RMW implementation '${RMW_IMPLEMENTATION}' as default")
find_package("${RMW_IMPLEMENTATION}" REQUIRED)
if(@RMW_IMPLEMENTATION_SUPPORTS_POCO@)
set(selected_rmw_implementation "@PROJECT_NAME@")
else()
set(selected_rmw_implementation "${default_rmw_implementation}")
message(STATUS "Using RMW implementation '${selected_rmw_implementation}' as default")
endif()
find_package("${selected_rmw_implementation}" REQUIRED)

# TODO should never need definitions and include dirs?
list(APPEND rmw_implementation_DEFINITIONS ${${RMW_IMPLEMENTATION}_DEFINITIONS})
list(APPEND rmw_implementation_INCLUDE_DIRS ${${RMW_IMPLEMENTATION}_INCLUDE_DIRS})
list(APPEND rmw_implementation_LIBRARIES ${${RMW_IMPLEMENTATION}_LIBRARIES})
list(APPEND rmw_implementation_DEFINITIONS ${${selected_rmw_implementation}_DEFINITIONS})
list(APPEND rmw_implementation_INCLUDE_DIRS ${${selected_rmw_implementation}_INCLUDE_DIRS})
list(APPEND rmw_implementation_LIBRARIES ${${selected_rmw_implementation}_LIBRARIES})
Loading

0 comments on commit 52a46ba

Please sign in to comment.