diff --git a/rmw_implementation/CMakeLists.txt b/rmw_implementation/CMakeLists.txt index 1f69a8bb..28201fdb 100644 --- a/rmw_implementation/CMakeLists.txt +++ b/rmw_implementation/CMakeLists.txt @@ -29,11 +29,19 @@ message(STATUS "") message(STATUS "Default rmw implementation: '${RMW_IMPLEMENTATION}'") message(STATUS "") +get_available_rmw_implementations(available_rmw_implementations) +list(LENGTH available_rmw_implementations count_available_rmw_implementations) +if(count_available_rmw_implementations EQUAL 1) + set(rmw_implementation_baked_default ON) +else() + set(rmw_implementation_baked_default OFF) +endif() + option(RMW_IMPLEMENTATION_BAKED "\ Use only the RMW implementation specified at build time, \ ignoring runtime value of the 'RMW_IMPLEMENTATION' environment variable \ and the 'RMW_IMPLEMENTATION' CMake option" - OFF) + ${rmw_implementation_baked_default}) if(RMW_IMPLEMENTATION_BAKED) message(STATUS "Dynamic loading disabled; directly referencing '${RMW_IMPLEMENTATION}'") diff --git a/rmw_implementation/rmw_implementation-extras.cmake.in b/rmw_implementation/rmw_implementation-extras.cmake.in index 1dd32195..90b4c9ec 100644 --- a/rmw_implementation/rmw_implementation-extras.cmake.in +++ b/rmw_implementation/rmw_implementation-extras.cmake.in @@ -16,8 +16,27 @@ find_package(rmw_implementation_cmake REQUIRED) -if(RMW_IMPLEMENTATION_BAKED) +if(NOT "${RMW_IMPLEMENTATION}" STREQUAL "") + set(requested_rmw_implementation "${RMW_IMPLEMENTATION}") + set(requested_rmw_implementation_from "CMake") +elseif(NOT "$ENV{RMW_IMPLEMENTATION}" STREQUAL "") + set(requested_rmw_implementation "$ENV{RMW_IMPLEMENTATION}") + set(requested_rmw_implementation_from "environment variable 'RMW_IMPLEMENTATION'") +else() + set(requested_rmw_implementation "@RMW_IMPLEMENTATION@") + set(requested_rmw_implementation_from "the default when @PROJECT_NAME@ was built") +endif() + +if(@RMW_IMPLEMENTATION_BAKED@) message(STATUS "Using RMW implementation '@RMW_IMPLEMENTATION@'") + if(NOT requested_rmw_implementation STREQUAL @RMW_IMPLEMENTATION@) + message(ERROR + "The RMW implementation has been specified as " + "'${requested_rmw_implementation}' via ${requested_rmw_implementation_from}, " + "but rmw_implementation was built without dynamic linking enabled. We will use " + "'@RMW_IMPLEMENTATION@'". + ) + endif() find_package("@RMW_IMPLEMENTATION@" REQUIRED) # TODO should never need definitions and include dirs? @@ -25,16 +44,6 @@ if(RMW_IMPLEMENTATION_BAKED) list(APPEND rmw_implementation_INCLUDE_DIRS ${@RMW_IMPLEMENTATION@_INCLUDE_DIRS}) list(APPEND rmw_implementation_LIBRARIES ${@RMW_IMPLEMENTATION@_LIBRARIES}) else() - if(NOT "${RMW_IMPLEMENTATION}" STREQUAL "") - set(requested_rmw_implementation "${RMW_IMPLEMENTATION}") - set(requested_rmw_implementation_from "CMake") - elseif(NOT "$ENV{RMW_IMPLEMENTATION}" STREQUAL "") - set(requested_rmw_implementation "$ENV{RMW_IMPLEMENTATION}") - set(requested_rmw_implementation_from "environment variable 'RMW_IMPLEMENTATION'") - else() - set(requested_rmw_implementation "@RMW_IMPLEMENTATION@") - set(requested_rmw_implementation_from "the default when @PROJECT_NAME@ was built") - endif() get_available_rmw_implementations(available_rmw_implementations)