|
| 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