From ce73a1fd8e582913cff7a4e1555cb1fd102d1faf Mon Sep 17 00:00:00 2001 From: Frantisek Hrbata Date: Tue, 20 Jan 2026 16:57:42 +0100 Subject: [PATCH] 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 --- tools/cmakev2/build.cmake | 55 +++++++++++++++++++------------ tools/cmakev2/project.cmake | 6 ++-- tools/cmakev2/test/CMakeLists.txt | 4 +-- 3 files changed, 40 insertions(+), 25 deletions(-) diff --git a/tools/cmakev2/build.cmake b/tools/cmakev2/build.cmake index 79e806a3bf2..75516401064 100644 --- a/tools/cmakev2/build.cmake +++ b/tools/cmakev2/build.cmake @@ -715,35 +715,55 @@ endfunction() .. code-block:: cmake - idf_build_generate_metadata( + idf_build_generate_metadata([BINARY ] + [EXECUTABLE ] [OUTPUT_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 ``/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 ``/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 ``/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 "$") - # 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 "$") if(NOT PROJECT_BIN) set(PROJECT_BIN "") endif() diff --git a/tools/cmakev2/project.cmake b/tools/cmakev2/project.cmake index e5738bf51a4..cd0392a9908 100644 --- a/tools/cmakev2/project.cmake +++ b/tools/cmakev2/project.cmake @@ -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}" diff --git a/tools/cmakev2/test/CMakeLists.txt b/tools/cmakev2/test/CMakeLists.txt index 0981ec92afb..8eb5c75ac1f 100644 --- a/tools/cmakev2/test/CMakeLists.txt +++ b/tools/cmakev2/test/CMakeLists.txt @@ -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)