Skip to content

Commit 4eb9657

Browse files
committed
find_package() in root scope
1 parent 19d1698 commit 4eb9657

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

rmw_implementation/cmake/add_executable_for_each_rmw_implementation.cmake

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,18 @@
3737
# :param INSTALL: if set install all executables
3838
# :type INSTALL: option
3939
#
40-
function(add_executable_for_each_rmw_implementations target)
41-
cmake_parse_arguments(ARG
42-
"INSTALL;SKIP_DEFAULT" "ALL_TARGET_NAMES_VAR" "TARGET_DEPENDENCIES" ${ARGN})
43-
40+
macro(add_executable_for_each_rmw_implementations)
4441
# get available rmw implementations
45-
get_available_rmw_implementations(rmw_implementations)
46-
foreach(rmw_implementation ${rmw_implementations})
47-
find_package("${rmw_implementation}" REQUIRED)
42+
get_available_rmw_implementations(_rmw_implementations)
43+
foreach(_rmw_implementation ${_rmw_implementations})
44+
find_package("${_rmw_implementation}" REQUIRED)
4845
endforeach()
46+
_add_executable_for_each_rmw_implementations(${ARGN})
47+
endmacro()
48+
49+
function(_add_executable_for_each_rmw_implementations target)
50+
cmake_parse_arguments(ARG
51+
"INSTALL;SKIP_DEFAULT" "ALL_TARGET_NAMES_VAR" "TARGET_DEPENDENCIES" ${ARGN})
4952

5053
set(targets "")
5154
if(NOT ARG_SKIP_DEFAULT)

rmw_implementation/cmake/get_default_rmw_implementation.cmake

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,36 @@
2121
# :param var: the output variable name containing the package name
2222
# :type var: string
2323
#
24-
function(get_default_rmw_implementation var)
25-
get_available_rmw_implementations(middleware_implementations)
24+
macro(get_default_rmw_implementation var)
25+
get_available_rmw_implementations(_middleware_implementations)
2626

27-
if("${middleware_implementations} " STREQUAL " ")
27+
if("${_middleware_implementations} " STREQUAL " ")
2828
message(FATAL_ERROR "Could not find any ROS middleware implementation.")
2929
endif()
3030

3131
# option()
3232
if(NOT "${ROS_MIDDLEWARE_IMPLEMENTATION} " STREQUAL " ")
33-
set(middleware_implementation "${ROS_MIDDLEWARE_IMPLEMENTATION}")
33+
set(_middleware_implementation "${ROS_MIDDLEWARE_IMPLEMENTATION}")
3434
elseif(NOT "$ENV{ROS_MIDDLEWARE_IMPLEMENTATION} " STREQUAL " ")
35-
set(middleware_implementation "$ENV{ROS_MIDDLEWARE_IMPLEMENTATION}")
35+
set(_middleware_implementation "$ENV{ROS_MIDDLEWARE_IMPLEMENTATION}")
3636
else()
3737
# TODO detemine "default" implementation based on the available ones
38-
list(GET middleware_implementations 0 middleware_implementation)
38+
list(GET _middleware_implementations 0 _middleware_implementation)
3939
endif()
4040

4141
# verify that the selection one is available
42-
list(FIND middleware_implementations "${middleware_implementation}" _index)
42+
list(FIND _middleware_implementations "${_middleware_implementation}" _index)
4343
if(_index EQUAL -1)
44-
string(REPLACE ";" ", " middleware_implementations_string "${middleware_implementations}")
45-
message(FATAL_ERROR "Could not find ROS middleware implementation '${middleware_implementation}'. Choose one of the following: ${middleware_implementations_string}")
44+
string(REPLACE ";" ", " _middleware_implementations_string "${_middleware_implementations}")
45+
message(FATAL_ERROR "Could not find ROS middleware implementation '${_middleware_implementation}'. Choose one of the following: ${_middleware_implementations_string}")
4646
endif()
47-
find_package("${middleware_implementation}" REQUIRED)
47+
find_package("${_middleware_implementation}" REQUIRED)
4848

4949
# persist implementation decision in cache
5050
set(
51-
ROS_MIDDLEWARE_IMPLEMENTATION "${middleware_implementation}"
51+
ROS_MIDDLEWARE_IMPLEMENTATION "${_middleware_implementation}"
5252
CACHE STRING "Select ROS middleware implementation to link against" FORCE
5353
)
5454

55-
set(${var} ${middleware_implementation} PARENT_SCOPE)
56-
endfunction()
55+
set(${var} ${_middleware_implementation})
56+
endmacro()

0 commit comments

Comments
 (0)