From 3a0f0bb13f1c59f48570844f4254424ce025dd68 Mon Sep 17 00:00:00 2001 From: Frantisek Hrbata Date: Sat, 7 Mar 2026 16:29:09 +0100 Subject: [PATCH] feat(cmakev2/build): add ALL option to idf_build_binary and idf_sign_binary Add an optional ALL parameter to idf_build_binary and idf_sign_binary functions. When specified, the created custom target is included in the default build target. Without ALL, custom targets created by these functions are excluded from the default build (add_custom_target behavior), meaning they won't be built unless explicitly requested or depended upon by another target in ALL. Signed-off-by: Frantisek Hrbata --- tools/cmakev2/build.cmake | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/tools/cmakev2/build.cmake b/tools/cmakev2/build.cmake index 99d4c3af82..ab6d71ed0d 100644 --- a/tools/cmakev2/build.cmake +++ b/tools/cmakev2/build.cmake @@ -913,7 +913,8 @@ endfunction() idf_build_binary( TARGET - OUTPUT_FILE ) + OUTPUT_FILE + [ALL]) *executable[in]* @@ -928,6 +929,10 @@ endfunction() Output file path for storing the binary image file. + *ALL[in,opt]* + + If specified, the target will be added to the default build target. + Create a binary image for the specified ``executable`` target and save it in the file specified with the ``OUTPUT_FILE`` option. A custom target named ``TARGET`` will be created for the generated binary image. The path @@ -936,7 +941,7 @@ endfunction() the ``TARGET``. #]] function(idf_build_binary executable) - set(options) + set(options ALL) set(one_value OUTPUT_FILE TARGET) set(multi_value) cmake_parse_arguments(ARG "${options}" "${one_value}" "${multi_value}" ${ARGN}) @@ -990,8 +995,13 @@ function(idf_build_binary executable) COMMENT "Generating binary image '${binary_name}' from executable '${executable_name}'" ) - # Create a custom target to generate the binary file - add_custom_target(${ARG_TARGET} DEPENDS "${ARG_OUTPUT_FILE}") + # Create a custom target to generate the binary file. + # If ALL is specified, include the target in the default build. + set(all_arg) + if(ARG_ALL) + set(all_arg ALL) + endif() + add_custom_target(${ARG_TARGET} ${all_arg} DEPENDS "${ARG_OUTPUT_FILE}") # Store the path of the binary file in the BINARY_PATH property of the # custom binary target, which is used by the idf_flash_binary. @@ -1010,7 +1020,8 @@ endfunction() idf_sign_binary( TARGET OUTPUT_FILE - [KEYFILE ]) + [KEYFILE ] + [ALL]) *binary[in]* @@ -1033,6 +1044,10 @@ endfunction() provided, the key file specified by the ``CONFIG_SECURE_BOOT_SIGNING_KEY`` configuration option will be used. + *ALL[in,opt]* + + If specified, the target will be added to the default build target. + Sign binary image specified by ``binary`` target with ``KEYFILE`` and save it in the file specified with the `OUTPUT_FILE` option. A custom target named ``TARGET`` will be created for the signed binary image. The path of @@ -1041,7 +1056,7 @@ endfunction() ``TARGET``. #]] function(idf_sign_binary binary) - set(options) + set(options ALL) set(one_value OUTPUT_FILE TARGET KEYFILE) set(multi_value) cmake_parse_arguments(ARG "${options}" "${one_value}" "${multi_value}" ${ARGN}) @@ -1097,7 +1112,13 @@ function(idf_sign_binary binary) VERBATIM COMMENT "Signing '${binary_name}' with key '${key_name}' into '${signed_binary_name}'" ) - add_custom_target(${ARG_TARGET} DEPENDS "${ARG_OUTPUT_FILE}") + # Create a custom target for the signed binary file. + # If ALL is specified, include the target in the default build. + set(all_arg) + if(ARG_ALL) + set(all_arg ALL) + endif() + add_custom_target(${ARG_TARGET} ${all_arg} DEPENDS "${ARG_OUTPUT_FILE}") # Store the path of the binary file in the BINARY_PATH property of the # custom signed binary target, which is used by the idf_flash_binary.