From fed8ed784ff905d52bc76970d320ce9308748ebb Mon Sep 17 00:00:00 2001 From: Sudeep Mohanty Date: Wed, 20 May 2026 13:48:14 +0200 Subject: [PATCH] fix(cmakev2): handle .elf target name in target_add_binary_data In cmakev1, the executable target is named "${project}.elf". In cmakev2, the executable is named "${project}" with .elf as the output suffix. Strip the .elf suffix and look up the bare target name when the original name doesn't exist. --- tools/cmakev2/utilities.cmake | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/cmakev2/utilities.cmake b/tools/cmakev2/utilities.cmake index a2804964184..6ff966a7556 100644 --- a/tools/cmakev2/utilities.cmake +++ b/tools/cmakev2/utilities.cmake @@ -835,6 +835,17 @@ endfunction() function(target_add_binary_data target embed_file embed_type) cmake_parse_arguments(_ "" "RENAME_TO" "DEPENDS" ${ARGN}) idf_build_get_property(build_dir BUILD_DIR) + + # In cmakev1, the executable target was named "${project}.elf". + # In cmakev2, the executable is named "${project}" and ".elf" is just the + # output suffix. Strip the ".elf" suffix if the target does not exist but + # the bare name does. This keeps existing app CMakeLists.txt files working. + if(NOT TARGET "${target}") + string(REGEX REPLACE "\\.elf$" "" target_bare "${target}") + if(TARGET "${target_bare}") + set(target "${target_bare}") + endif() + endif() idf_build_get_property(idf_path IDF_PATH) get_filename_component(embed_file "${embed_file}" ABSOLUTE)