feat(cmakev2/project): initialize global flash targets

The global flash targets are created using
__create_project_flash_targets, but these are merely placeholders that
allow components to declare their dependencies on the global flash or
encrypted-flash target in their project_include.cmake. The actual logic
for flash targets is located in the project_include.cmake of the
esptool_py component. Therefore, the targets must be initialized
after this file has been included. To address this, a new function,
__init_project_flash_targets, has been added for this purpose.

Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
This commit is contained in:
Frantisek Hrbata
2025-11-04 07:48:14 +01:00
parent 81c7c79af5
commit 8ac1da9cfb
+23 -3
View File
@@ -506,12 +506,12 @@ function(__init_project_configuration)
endfunction()
#[[
__init_project_flash_targets()
__create_project_flash_targets()
Add placeholder flash targets to the build. This is used by components to
declare dependencies on the flash target.
#]]
function(__init_project_flash_targets)
function(__create_project_flash_targets)
if(NOT TARGET flash)
add_custom_target(flash)
endif()
@@ -526,6 +526,23 @@ function(__init_project_flash_targets)
endif()
endfunction()
#[[
__init_project_flash_targets()
If binary generation is enabled, initialize the esptool component and enable
the generation of esptool flash argument files for the flash and
encrypted-flash targets. Note that this is done after including the
project_include.cmake files, as we need the functions defined in the
esptool_py component.
#]]
function(__init_project_flash_targets)
if(CONFIG_APP_BUILD_GENERATE_BINARIES)
idf_component_get_property(main_args esptool_py FLASH_ARGS)
idf_component_get_property(sub_args esptool_py FLASH_SUB_ARGS)
esptool_py_flash_target(flash "${main_args}" "${sub_args}")
endif()
endfunction()
#[[api
.. cmakev2:macro:: idf_project_init
@@ -562,7 +579,7 @@ macro(idf_project_init)
__init_project_configuration()
# Create global flash targets.
__init_project_flash_targets()
__create_project_flash_targets()
# Include all project_include.cmake files for the components that have
# been discovered.
@@ -584,6 +601,9 @@ macro(idf_project_init)
endif()
endforeach()
# Initialize global flash targets.
__init_project_flash_targets()
# If explicitly requested, include all components by calling
# `add_subdirectory` for every discovered component. The default
# behavior is to include only the components based on the requirements.