fix(cmakev2/build): extend idf_build_generate_metadata to also accept executable

Currently, idf_build_generate_metadata only accepts binary targets for
which it generates metadata (project_description.json). On Linux
targets, binary images are not generated, but we still need to generate
project_description.json. Extend the current function to accept both
executable and binary targets and ensure project_description.json is
generated when a Linux target is used.

Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
This commit is contained in:
Frantisek Hrbata
2026-01-20 16:57:42 +01:00
parent fc5e7eb22d
commit ce73a1fd8e
3 changed files with 40 additions and 25 deletions

View File

@@ -715,35 +715,55 @@ endfunction()
.. code-block:: cmake
idf_build_generate_metadata(<binary>
idf_build_generate_metadata([BINARY <binary>]
[EXECUTABLE <executable>]
[OUTPUT_FILE <file>])
*binary[in]*
*BINARY[in,opt]*
Binary target for which to generate a metadata file.
*EXECUTABLE[in,opt]*
Executable target for which to generate a metadata file.
*OUTPUT_FILE[in,opt]*
Optional output file path for storing the metadata. If not provided,
the default path ``<build>/project_description.json`` is used.
Generate metadata for the specified ``binary`` and store it in the
specified ``OUTPUT_FILE``. If no ``OUTPUT_FILE`` is provided, the default
location ``<build>/project_description.json`` will be used.
Generate metadata for the specified ``binary`` or ``executable`` target and
store it in the specified ``OUTPUT_FILE``. If no ``OUTPUT_FILE`` is
provided, the default location ``<build>/project_description.json`` will be
used.
#]]
function(idf_build_generate_metadata binary)
function(idf_build_generate_metadata)
set(options)
set(one_value OUTPUT_FILE)
set(one_value OUTPUT_FILE BINARY EXECUTABLE)
set(multi_value)
cmake_parse_arguments(ARG "${options}" "${one_value}" "${multi_value}" ${ARGN})
# The EXECUTABLE_TARGET property is set by the idf_build_binary or
# the idf_sign_binary function.
get_target_property(executable "${binary}" EXECUTABLE_TARGET)
if(NOT executable)
idf_die("Binary target '${binary}' is missing 'EXECUTABLE_TARGET' property.")
if(NOT DEFINED ARG_BINARY AND NOT DEFINED ARG_EXECUTABLE)
idf_die("BINARY or EXECUTABLE option is required")
endif()
__get_executable_library_or_die(TARGET "${executable}" OUTPUT library)
if(DEFINED ARG_BINARY)
# The EXECUTABLE_TARGET property is set by the idf_build_binary or
# the idf_sign_binary function.
get_target_property(ARG_EXECUTABLE "${ARG_BINARY}" EXECUTABLE_TARGET)
if(NOT ARG_EXECUTABLE)
idf_die("Binary target '${ARG_BINARY}' is missing 'EXECUTABLE_TARGET' property.")
endif()
# The BINARY_PATH property is set by the idf_build_binary or
# the idf_sign_binary function.
get_target_property(binary_path ${ARG_BINARY} BINARY_PATH)
if(NOT binary_path)
idf_die("Binary target '${ARG_BINARY}' is missing 'BINARY_PATH' property.")
endif()
get_filename_component(PROJECT_BIN "${binary_path}" NAME)
endif()
__get_executable_library_or_die(TARGET "${ARG_EXECUTABLE}" OUTPUT library)
idf_build_get_property(PROJECT_NAME PROJECT_NAME)
idf_build_get_property(PROJECT_VER PROJECT_VER)
@@ -752,14 +772,7 @@ function(idf_build_generate_metadata binary)
idf_build_get_property(BUILD_DIR BUILD_DIR)
idf_build_get_property(SDKCONFIG SDKCONFIG)
idf_build_get_property(SDKCONFIG_DEFAULTS SDKCONFIG_DEFAULTS)
set(PROJECT_EXECUTABLE "$<TARGET_FILE_NAME:${executable}>")
# The BINARY_PATH property is set by the idf_build_binary or
# the idf_sign_binary function.
get_target_property(binary_path ${binary} BINARY_PATH)
if(NOT binary_path)
idf_die("Binary target '${binary}' is missing 'BINARY_PATH' property.")
endif()
get_filename_component(PROJECT_BIN "${binary_path}" NAME)
set(PROJECT_EXECUTABLE "$<TARGET_FILE_NAME:${ARG_EXECUTABLE}>")
if(NOT PROJECT_BIN)
set(PROJECT_BIN "")
endif()

View File

@@ -731,7 +731,7 @@ function(__project_default)
TARGET app-flash
NAME "app"
FLASH)
idf_build_generate_metadata("${executable}_binary_signed")
idf_build_generate_metadata(BINARY "${executable}_binary_signed")
else()
idf_build_binary("${executable}"
OUTPUT_FILE "${build_dir}/${executable}.bin"
@@ -748,10 +748,12 @@ function(__project_default)
idf_create_dfu("${executable}_binary"
TARGET dfu)
idf_build_generate_metadata("${executable}_binary")
idf_build_generate_metadata(BINARY "${executable}_binary")
endif()
idf_build_generate_flasher_args()
else()
idf_build_generate_metadata(EXECUTABLE "${executable}")
endif()
idf_create_menuconfig("${executable}"

View File

@@ -232,7 +232,7 @@ function(test_executable)
NAME fatfs_example)
idf_create_menuconfig(fatfs_example
TARGET menuconfig-fatfs)
idf_build_generate_metadata(fatfs_example_bin
idf_build_generate_metadata(BINARY fatfs_example_bin
OUTPUT_FILE project_description_fatfs.json)
idf_build_generate_depgraph(fatfs_example
OUTPUT_FILE component_deps_fatfs.dot)
@@ -257,7 +257,7 @@ function(test_executable)
NAME hello_world_example)
idf_create_menuconfig(hello_world_example
TARGET menuconfig-hello_world)
idf_build_generate_metadata(hello_world_example_bin
idf_build_generate_metadata(BINARY hello_world_example_bin
OUTPUT_FILE project_description_hello_world.json)
idf_build_generate_depgraph(hello_world_example
OUTPUT_FILE component_deps_hello_world.dot)