Skip to content

Commit be406d9

Browse files
authored
add ament_get_recursive_properties (#259)
* add ament_get_recursive_properties Signed-off-by: Dirk Thomas <[email protected]> * fix spelling in docblock Signed-off-by: Dirk Thomas <[email protected]>
1 parent bae0fb8 commit be406d9

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

ament_cmake_target_dependencies/ament_cmake_target_dependencies-extras.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@ find_package(ament_cmake_core QUIET REQUIRED)
1919
find_package(ament_cmake_include_directories QUIET REQUIRED)
2020
find_package(ament_cmake_libraries QUIET REQUIRED)
2121

22+
include(
23+
"${ament_cmake_target_dependencies_DIR}/ament_get_recursive_properties.cmake")
2224
include(
2325
"${ament_cmake_target_dependencies_DIR}/ament_target_dependencies.cmake")
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Copyright 2020 Open Source Robotics Foundation, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
#
16+
# Get the recursive include directories and libraries from interface targets.
17+
#
18+
# :param var_include_dirs: the output variable name
19+
# :type var_include_dirs: string
20+
# :param var_libraries: the output variable name
21+
# :type var_libraries: string
22+
# :param ARGN: a list of interface targets
23+
# :type ARGN: list of strings
24+
#
25+
# @public
26+
#
27+
function(ament_get_recursive_properties var_include_dirs var_libraries)
28+
set(all_include_dirs "")
29+
set(all_libraries "")
30+
31+
if(${ARGC} GREATER 0)
32+
foreach(target ${ARGN})
33+
# only use actual targets
34+
if(NOT TARGET "${target}")
35+
continue()
36+
endif()
37+
38+
get_target_property(include_dirs ${target} INTERFACE_INCLUDE_DIRECTORIES)
39+
if(include_dirs)
40+
list_append_unique(all_include_dirs "${include_dirs}")
41+
endif()
42+
43+
get_target_property(link_libraries ${target} INTERFACE_LINK_LIBRARIES)
44+
if(link_libraries)
45+
foreach(link_library ${link_libraries})
46+
if(TARGET "${link_library}")
47+
ament_get_recursive_properties(include_dirs libraries "${link_library}")
48+
list_append_unique(all_include_dirs "${include_dirs}")
49+
list_append_unique(all_libraries "${libraries}")
50+
else()
51+
list(APPEND all_libraries ${link_library})
52+
endif()
53+
endforeach()
54+
endif()
55+
56+
get_target_property(imported_configurations ${target} IMPORTED_CONFIGURATIONS)
57+
if(imported_configurations)
58+
get_target_property(imported_implib ${target} IMPORTED_IMPLIB_${imported_configurations})
59+
if(imported_implib)
60+
list(APPEND all_libraries "${imported_implib}")
61+
else()
62+
get_target_property(imported_location ${target} IMPORTED_LOCATION_${imported_configurations})
63+
if(imported_location)
64+
list(APPEND all_libraries "${imported_location}")
65+
endif()
66+
endif()
67+
endif()
68+
endforeach()
69+
70+
ament_include_directories_order(ordered_include_dirs ${all_include_dirs})
71+
ament_libraries_deduplicate(unique_libraries ${all_libraries})
72+
endif()
73+
74+
set(${var_include_dirs} ${ordered_include_dirs} PARENT_SCOPE)
75+
set(${var_libraries} ${unique_libraries} PARENT_SCOPE)
76+
endfunction()

0 commit comments

Comments
 (0)