From 0133eef8401f937c22148fe980053a35d497e602 Mon Sep 17 00:00:00 2001 From: Frantisek Hrbata Date: Fri, 29 Aug 2025 15:04:00 +0200 Subject: [PATCH] fix(cmakev2/compat): use alias target in idf_component_optional_requires The optional dependency is currently added if the optional component interface target exists, which is always the case unless a non-existent component is requested. Instead, base the optional dependency on the component interface target alias, as it is created only when the component is included in the project. Signed-off-by: Frantisek Hrbata --- tools/cmakev2/compat.cmake | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/cmakev2/compat.cmake b/tools/cmakev2/compat.cmake index f11ec3c3665..cd6720fab15 100644 --- a/tools/cmakev2/compat.cmake +++ b/tools/cmakev2/compat.cmake @@ -191,7 +191,14 @@ function(idf_component_optional_requires req_type) set(optional_reqs ${ARGN}) foreach(req ${optional_reqs}) __get_component_interface(COMPONENT "${req}" OUTPUT req_interface) - target_link_libraries(${COMPONENT_TARGET} ${req_type} "$<$:${req_interface}>") + if("${req_interface}" STREQUAL "NOTFOUND") + continue() + endif() + idf_component_get_property(req_alias "${req}" COMPONENT_ALIAS) + # The component alias is created only after the component is included, + # meaning the add_subdirectory command for it has been called. This can + # be used to detect if a component has already been added to the build. + target_link_libraries(${COMPONENT_TARGET} ${req_type} "$<$:${req_interface}>") endforeach() endfunction()