feat(cmakev2/project): include project_include.cmake files

During the initialization of a component in the __init_component
function, store the full path of the project_include.cmake file in the
component's __PROJECT_INCLUDE property, if it exists. Include the
project_include.cmake files for all discovered components at the global
scope within the idf_project_init macro.

Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
This commit is contained in:
Frantisek Hrbata
2025-10-30 17:17:49 +08:00
committed by BOT
parent 2967ff3e2e
commit 01279ea4c3
2 changed files with 38 additions and 0 deletions
+11
View File
@@ -359,6 +359,11 @@ function(__init_component)
__collect_kconfig_files_from_directory("${component_directory}" "${target}"
component_kconfig component_projbuild component_rename)
set(component_project_include "${component_directory}/project_include.cmake")
if(NOT EXISTS "${component_project_include}")
set(component_project_include "")
endif()
__get_component_interface(COMPONENT "${component_name}" OUTPUT existing_component_interface)
if(NOT "${existing_component_interface}" STREQUAL "NOTFOUND")
# A component with the same name is already initialized. Check if it
@@ -399,6 +404,9 @@ function(__init_component)
idf_component_set_property("${component_name}" __KCONFIG "${component_kconfig}")
idf_component_set_property("${component_name}" __KCONFIG_PROJBUILD "${component_projbuild}")
idf_component_set_property("${component_name}" __SDKCONFIG_RENAME "${component_rename}")
# Update component project_include.cmake path.
idf_component_set_property("${component_name}" __PROJECT_INCLUDE "${component_project_include}")
endif()
return()
@@ -431,6 +439,9 @@ function(__init_component)
idf_component_set_property("${component_name}" __KCONFIG "${component_kconfig}")
idf_component_set_property("${component_name}" __KCONFIG_PROJBUILD "${component_projbuild}")
idf_component_set_property("${component_name}" __SDKCONFIG_RENAME "${component_rename}")
# Set component project_include.cmake.
idf_component_set_property("${component_name}" __PROJECT_INCLUDE "${component_project_include}")
endfunction()
#[[
+27
View File
@@ -516,6 +516,13 @@ endfunction()
build system functions. It initializes the PROJECT_NAME and PROJECT_VER
build properties, as well as all default C, CXX, and ASM compile options,
link options, and compile definitions.
This macro also includes project_include.cmake files for the discovered
components, as these files define project-wide functionality that needs to
be available before any component's CMakeLists.txt is evaluated. The
project_include.cmake files should be evaluated in the global scope.
Therefore, this is defined as a macro and should be called only from the
global scope or from within another macro.
#]]
macro(idf_project_init)
idf_build_get_property(project_initialized __PROJECT_INITIALIZED)
@@ -532,6 +539,26 @@ macro(idf_project_init)
# Initialize all compilation options and defines.
__init_project_configuration()
# Include all project_include.cmake files for the components that have
# been discovered.
idf_build_get_property(component_names COMPONENTS_DISCOVERED)
foreach(component_name IN LISTS component_names)
idf_component_get_property(project_include ${component_name} __PROJECT_INCLUDE)
idf_component_get_property(component_dir ${component_name} COMPONENT_DIR)
if(project_include)
set(COMPONENT_NAME ${component_name})
set(COMPONENT_DIR ${component_dir})
# The use of COMPONENT_PATH is deprecated in cmakev1. Users
# are encouraged to use COMPONENT_DIR instead.
set(COMPONENT_PATH ${component_dir})
idf_dbg("Including ${project_include}")
include("${project_include}")
unset(COMPONENT_NAME)
unset(COMPONENT_DIR)
unset(COMPONENT_PATH)
endif()
endforeach()
idf_build_set_property(__PROJECT_INITIALIZED YES)
endif()
unset(project_initialized)