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.
This commit is contained in:
Sudeep Mohanty
2026-05-20 13:48:14 +02:00
parent c5e7c137f5
commit fed8ed784f

View File

@@ -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)