Skip to content

Commit 52a46ba

Browse files
committed
make rmw_implementation a meta rmw implementation
1 parent 4e9f8a3 commit 52a46ba

File tree

4 files changed

+631
-28
lines changed

4 files changed

+631
-28
lines changed

rmw_implementation/CMakeLists.txt

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
cmake_minimum_required(VERSION 3.5)
22

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

5+
if(NOT WIN32)
6+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra")
7+
endif()
8+
69
find_package(ament_cmake REQUIRED)
10+
# provides FindPoco.cmake and Poco on platforms without it
11+
find_package(poco_vendor)
12+
find_package(Poco COMPONENTS Foundation)
713
find_package(rmw_implementation_cmake REQUIRED)
814

915
if(BUILD_TESTING)
@@ -13,17 +19,59 @@ endif()
1319

1420
get_default_rmw_implementation(RMW_IMPLEMENTATION)
1521

16-
get_available_rmw_implementations(impls)
22+
get_available_rmw_implementations(RMW_IMPLEMENTATIONS)
1723
message(STATUS "")
1824
message(STATUS "Found these rmw implementations:")
19-
foreach(impl IN LISTS impls)
25+
foreach(impl IN LISTS RMW_IMPLEMENTATIONS)
2026
message(STATUS " '${impl}'")
2127
endforeach()
2228

2329
message(STATUS "")
2430
message(STATUS "Using default rmw implementation: '${RMW_IMPLEMENTATION}'")
2531
message(STATUS "")
2632

33+
# if only a single rmw impl. is available or poco is not available
34+
# this package will directly reference the default rmw impl.
35+
if(NOT RMW_IMPLEMENTATIONS MATCHES ";" OR NOT Poco_FOUND)
36+
set(RMW_IMPLEMENTATION_SUPPORTS_POCO FALSE)
37+
38+
else()
39+
set(RMW_IMPLEMENTATION_SUPPORTS_POCO TRUE)
40+
find_package(rmw REQUIRED)
41+
42+
message(STATUS "Support runtime override with any of the available rmw implementations")
43+
message(STATUS "")
44+
link_directories(${Poco_LIBRARY_DIR})
45+
add_library(${PROJECT_NAME} SHARED
46+
src/functions.cpp)
47+
ament_target_dependencies(${PROJECT_NAME}
48+
"Poco"
49+
"rmw")
50+
target_compile_definitions(${PROJECT_NAME}
51+
PUBLIC "DEFAULT_RMW_IMPLEMENTATION=${RMW_IMPLEMENTATION}")
52+
target_link_libraries(${PROJECT_NAME})
53+
configure_rmw_library(${PROJECT_NAME})
54+
55+
ament_export_libraries(${PROJECT_NAME})
56+
if(NOT WIN32)
57+
ament_export_libraries(pthread)
58+
endif()
59+
60+
install(
61+
TARGETS ${PROJECT_NAME}
62+
ARCHIVE DESTINATION lib
63+
LIBRARY DESTINATION lib
64+
RUNTIME DESTINATION bin
65+
)
66+
endif()
67+
68+
register_rmw_implementation(
69+
"c:rosidl_typesupport_c"
70+
"cpp:rosidl_typesupport_cpp"
71+
)
72+
73+
# necessary since get_available_rmw_implementations excludes rmw_implementation
74+
list(APPEND RMW_IMPLEMENTATIONS "rmw_implementation")
2775
ament_package(
2876
CONFIG_EXTRAS "rmw_implementation-extras.cmake.in"
2977
)

rmw_implementation/package.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010
<buildtool_depend>ament_cmake</buildtool_depend>
1111

12+
<build_depend>rmw</build_depend>
13+
14+
<depend>libpoco-dev</depend>
15+
<depend>poco_vendor</depend>
1216
<depend>rmw_implementation_cmake</depend>
1317
<depend>rmw_connext_cpp</depend>
1418
<depend>rmw_connext_dynamic_cpp</depend>
Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2014-2015 Open Source Robotics Foundation, Inc.
1+
# Copyright 2014-2016 Open Source Robotics Foundation, Inc.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -16,38 +16,63 @@
1616

1717
find_package(rmw_implementation_cmake REQUIRED)
1818
set(default_rmw_implementation "@RMW_IMPLEMENTATION@")
19+
set(available_rmw_implementations "@RMW_IMPLEMENTATIONS@")
1920

2021
if(NOT "${RMW_IMPLEMENTATION}" STREQUAL "")
21-
set(requested_default_rmw_implementation ${RMW_IMPLEMENTATION})
22-
if(NOT requested_default_rmw_implementation STREQUAL default_rmw_implementation)
23-
message(FATAL_ERROR
24-
"The default RMW implementation has been specified as "
25-
"'${requested_default_rmw_implementation}' through CMake,"
26-
"however the default RMW implementation which will be used is "
27-
"'${default_rmw_implementation}', which was specified when the "
28-
"'rmw_implementation' package was built.")
22+
set(requested_rmw_implementation ${RMW_IMPLEMENTATION})
23+
if(@RMW_IMPLEMENTATION_SUPPORTS_POCO@)
24+
if(NOT requested_rmw_implementation IN_LIST available_rmw_implementations)
25+
message(FATAL_ERROR
26+
"The RMW implementation has been specified as "
27+
"'${requested_rmw_implementation}' through CMake, "
28+
"however it is not in the list of supported rmw implementations, "
29+
"which was specified when the 'rmw_implementation' package was built.")
30+
endif()
31+
else()
32+
if(NOT requested_rmw_implementation STREQUAL default_rmw_implementation)
33+
message(FATAL_ERROR
34+
"The RMW implementation has been specified as "
35+
"'${requested_rmw_implementation}' through CMake, "
36+
"however this needs to match the RMW implementation "
37+
"'${default_rmw_implementation}', "
38+
"which was specified when the 'rmw_implementation' package was built.")
39+
endif()
2940
endif()
3041
endif()
3142

3243
if(NOT "$ENV{RMW_IMPLEMENTATION}" STREQUAL "")
33-
set(requested_default_rmw_implementation $ENV{RMW_IMPLEMENTATION})
34-
if(NOT requested_default_rmw_implementation STREQUAL default_rmw_implementation)
35-
message(FATAL_ERROR
36-
"The default RMW implementation has been specified as "
37-
"'${requested_default_rmw_implementation}' "
38-
"through the environment variable 'RMW_IMPLEMENTATION', "
39-
"however the default RMW implementation which will be used is "
40-
"'${default_rmw_implementation}', which was specified when the "
41-
"'rmw_implementation' package was built.")
44+
set(requested_rmw_implementation $ENV{RMW_IMPLEMENTATION})
45+
if(@RMW_IMPLEMENTATION_SUPPORTS_POCO@)
46+
if(NOT requested_rmw_implementation IN_LIST available_rmw_implementations)
47+
message(FATAL_ERROR
48+
"The RMW implementation has been specified as "
49+
"'${requested_rmw_implementation}' through the environment variable "
50+
"'RMW_IMPLEMENTATION', "
51+
"however it is not in the list of supported rmw implementations, "
52+
"which was specified when the 'rmw_implementation' package was built.")
53+
endif()
54+
else()
55+
if(NOT requested_rmw_implementation STREQUAL default_rmw_implementation)
56+
message(FATAL_ERROR
57+
"The RMW implementation has been specified as "
58+
"'${requested_rmw_implementation}' "
59+
"through the environment variable 'RMW_IMPLEMENTATION', "
60+
"however this needs to match the RMW implementation "
61+
"'${default_rmw_implementation}', "
62+
"which was specified when the 'rmw_implementation' package was built.")
63+
endif()
4264
endif()
4365
endif()
4466

45-
46-
set(RMW_IMPLEMENTATION "${default_rmw_implementation}")
47-
message(STATUS "Using RMW implementation '${RMW_IMPLEMENTATION}' as default")
48-
find_package("${RMW_IMPLEMENTATION}" REQUIRED)
67+
if(@RMW_IMPLEMENTATION_SUPPORTS_POCO@)
68+
set(selected_rmw_implementation "@PROJECT_NAME@")
69+
else()
70+
set(selected_rmw_implementation "${default_rmw_implementation}")
71+
message(STATUS "Using RMW implementation '${selected_rmw_implementation}' as default")
72+
endif()
73+
find_package("${selected_rmw_implementation}" REQUIRED)
4974

5075
# TODO should never need definitions and include dirs?
51-
list(APPEND rmw_implementation_DEFINITIONS ${${RMW_IMPLEMENTATION}_DEFINITIONS})
52-
list(APPEND rmw_implementation_INCLUDE_DIRS ${${RMW_IMPLEMENTATION}_INCLUDE_DIRS})
53-
list(APPEND rmw_implementation_LIBRARIES ${${RMW_IMPLEMENTATION}_LIBRARIES})
76+
list(APPEND rmw_implementation_DEFINITIONS ${${selected_rmw_implementation}_DEFINITIONS})
77+
list(APPEND rmw_implementation_INCLUDE_DIRS ${${selected_rmw_implementation}_INCLUDE_DIRS})
78+
list(APPEND rmw_implementation_LIBRARIES ${${selected_rmw_implementation}_LIBRARIES})

0 commit comments

Comments
 (0)