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 <frantisek.hrbata@espressif.com>
This commit is contained in:
Frantisek Hrbata
2025-08-29 15:04:00 +02:00
parent 2ac4afeb53
commit 0133eef840

View File

@@ -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} "$<$<TARGET_EXISTS:${req_interface}>:${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} "$<$<TARGET_EXISTS:${req_alias}>:${req_interface}>")
endforeach()
endfunction()