GetTargetInterface.cmake raw
1 # Copyright (c) 2023-present The Bitcoin Core developers
2 # Distributed under the MIT software license, see the accompanying
3 # file COPYING or https://opensource.org/license/mit/.
4
5 include_guard(GLOBAL)
6
7 # Evaluates config-specific generator expressions in a list.
8 # Recognizable patterns are:
9 # - $<$<CONFIG:[config]>:[value]>
10 # - $<$<NOT:$<CONFIG:[config]>>:[value]>
11 function(evaluate_generator_expressions list config)
12 set(input ${${list}})
13 set(result)
14 foreach(token IN LISTS input)
15 if(token MATCHES "\\$<\\$<CONFIG:([^>]+)>:([^>]+)>")
16 if(CMAKE_MATCH_1 STREQUAL config)
17 list(APPEND result ${CMAKE_MATCH_2})
18 endif()
19 elseif(token MATCHES "\\$<\\$<NOT:\\$<CONFIG:([^>]+)>>:([^>]+)>")
20 if(NOT CMAKE_MATCH_1 STREQUAL config)
21 list(APPEND result ${CMAKE_MATCH_2})
22 endif()
23 else()
24 list(APPEND result ${token})
25 endif()
26 endforeach()
27 set(${list} ${result} PARENT_SCOPE)
28 endfunction()
29
30
31 # Gets target's interface properties recursively.
32 function(get_target_interface var config target property)
33 get_target_property(result ${target} INTERFACE_${property})
34 if(result)
35 evaluate_generator_expressions(result "${config}")
36 list(JOIN result " " result)
37 else()
38 set(result)
39 endif()
40
41 get_target_property(dependencies ${target} INTERFACE_LINK_LIBRARIES)
42 if(dependencies)
43 evaluate_generator_expressions(dependencies "${config}")
44 foreach(dependency IN LISTS dependencies)
45 if(TARGET ${dependency})
46 get_target_interface(dep_result "${config}" ${dependency} ${property})
47 string(STRIP "${result} ${dep_result}" result)
48 endif()
49 endforeach()
50 endif()
51
52 set(${var} "${result}" PARENT_SCOPE)
53 endfunction()
54