Skip to content

Commit bd55cdf

Browse files
committed
cmake: allow calling get component property in early expansion
1 parent ebf07d3 commit bd55cdf

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

tools/cmake/scripts/component_get_requirements.cmake

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
cmake_minimum_required(VERSION 3.5)
12
include("${BUILD_PROPERTIES_FILE}")
23
include("${COMPONENT_PROPERTIES_FILE}")
34

@@ -18,6 +19,38 @@ function(__component_get_property var component_target property)
1819
set(${var} ${${_property}} PARENT_SCOPE)
1920
endfunction()
2021

22+
#
23+
# Given a component name or alias, get the corresponding component target.
24+
#
25+
function(__component_get_target var name_or_alias)
26+
idf_build_get_property(component_targets __COMPONENT_TARGETS)
27+
28+
# Assume first that the paramters is an alias.
29+
string(REPLACE "::" "_" name_or_alias "${name_or_alias}")
30+
set(component_target ___${name_or_alias})
31+
32+
if(component_target IN_LIST component_targets)
33+
set(${var} ${component_target} PARENT_SCOPE)
34+
set(target ${component_target})
35+
else() # assumption is wrong, try to look for it manually
36+
unset(target)
37+
foreach(component_target ${component_targets})
38+
__component_get_property(_component_name ${component_target} COMPONENT_NAME)
39+
if(name_or_alias STREQUAL _component_name)
40+
set(target ${component_target})
41+
break()
42+
endif()
43+
endforeach()
44+
set(${var} ${target} PARENT_SCOPE)
45+
endif()
46+
endfunction()
47+
48+
function(idf_component_get_property var component property)
49+
__component_get_target(component_target ${component})
50+
__component_get_property(_var ${component_target} ${property})
51+
set(${var} ${_var} PARENT_SCOPE)
52+
endfunction()
53+
2154
macro(require_idf_targets)
2255
endmacro()
2356

@@ -104,15 +137,15 @@ __component_set_property(${__component_target} __COMPONENT_REGISTERED ${__compon
104137

105138
if(__component_kconfig)
106139
get_filename_component(__component_kconfig "${__component_kconfig}" ABSOLUTE)
107-
set(__contents
108-
"${__contents}\n__component_set_property(${__component_target} KCONFIG \"${__component_kconfig}\""
140+
set(__contents
141+
"${__contents}\n__component_set_property(${__component_target} KCONFIG \"${__component_kconfig}\")"
109142
)
110143
endif()
111144

112145
if(__component_kconfig_projbuild)
113146
get_filename_component(__component_kconfig "${__component_kconfig}" ABSOLUTE)
114-
set(__contents
115-
"${__contents}\n__component_set_property(${__component_target} KCONFIG_PROJBUILD \"${__component_kconfig_projbuild}\""
147+
set(__contents
148+
"${__contents}\n__component_set_property(${__component_target} KCONFIG_PROJBUILD \"${__component_kconfig_projbuild}\")"
116149
)
117150
endif()
118151

0 commit comments

Comments
 (0)