From ba78e62bcff874c400282a8131be19646fe3d7c9 Mon Sep 17 00:00:00 2001 From: Frantisek Hrbata Date: Fri, 8 Aug 2025 16:30:50 +0200 Subject: [PATCH] feat(cmakev2/build): use idf_component_include into idf_build_library Call idf_component_include for all components requested in the library and link them into it. Signed-off-by: Frantisek Hrbata --- tools/cmakev2/build.cmake | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tools/cmakev2/build.cmake b/tools/cmakev2/build.cmake index 3ca8da6b46a..2845c7c8a36 100644 --- a/tools/cmakev2/build.cmake +++ b/tools/cmakev2/build.cmake @@ -774,10 +774,28 @@ function(idf_build_library) endif() # Initialize settings that must be configured after the project() function - # is called. + # is called. The __init_build function is evaluated only once per project. __init_build() + # Create library interface. add_library("${ARG_INTERFACE}" INTERFACE) idf_build_set_property(LIBRARY_INTERFACES "${ARG_INTERFACE}" APPEND) idf_library_set_property("${ARG_INTERFACE}" LIBRARY_COMPONENTS "${ARG_COMPONENTS}") + + # Add global include directories, such as the directory containing + # sdkconfig, to the library's include directories. + idf_build_get_property(include_directories INCLUDE_DIRECTORIES GENERATOR_EXPRESSION) + target_include_directories("${ARG_INTERFACE}" INTERFACE "${include_directories}") + + # Add link options. + idf_build_get_property(link_options LINK_OPTIONS) + target_link_options(${ARG_INTERFACE} INTERFACE "${link_options}") + + # Include the requested components and link their interface targets to the + # library. + foreach(component_name IN LISTS ARG_COMPONENTS) + idf_component_include("${component_name}") + idf_component_get_property(component_interface "${component_name}" COMPONENT_INTERFACE) + target_link_libraries("${ARG_INTERFACE}" INTERFACE "${component_interface}") + endforeach() endfunction()