From ab90489ccb784b86f4f22fcb99722257fc29837d Mon Sep 17 00:00:00 2001 From: Frantisek Hrbata Date: Tue, 10 Mar 2026 12:08:31 +0100 Subject: [PATCH] fix(cmakev2/utilities): resolve embed file path in idf_component_include Commit f62f45cf5cca changed target_add_binary_data to resolve the embedded file path relative to the component directory by using idf_component_get_property to obtain the COMPONENT_DIR. This fixed the path resolution when target_add_binary_data is called from idf_component_include, which runs outside the component's directory context. However, target_add_binary_data can also be called directly from a project's CMakeLists.txt with a non-component target, e.g. target_add_binary_data(app.elf ...) as done in examples/security/security_features_app. In this case, idf_component_get_property fails because the target is not a component. Fix this by moving the path resolution to idf_component_include, where the embed file paths from EMBED_FILES and EMBED_TXTFILES component properties are resolved to absolute paths relative to COMPONENT_DIR before being passed to target_add_binary_data. This way, target_add_binary_data receives already absolute paths from idf_component_include and can use plain get_filename_component(ABSOLUTE) for direct calls, which correctly resolves relative to CMAKE_CURRENT_SOURCE_DIR. Fixes: f62f45cf5cca ("fix(cmakev2/utilities): add a dependency target for the embedded file") Signed-off-by: Frantisek Hrbata --- tools/cmakev2/component.cmake | 4 ++++ tools/cmakev2/utilities.cmake | 7 +------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/tools/cmakev2/component.cmake b/tools/cmakev2/component.cmake index a0262a9ac8f..8a07d0a91d6 100644 --- a/tools/cmakev2/component.cmake +++ b/tools/cmakev2/component.cmake @@ -963,13 +963,17 @@ function(idf_component_include name) idf_die("Unsupported target type '${component_real_target_type}' in component '${component_name}'") endif() + idf_component_get_property(component_dir "${component_name}" COMPONENT_DIR) + idf_component_get_property(embed_files "${component_name}" EMBED_FILES) foreach(file IN LISTS embed_files) + get_filename_component(file "${file}" ABSOLUTE BASE_DIR "${component_dir}") target_add_binary_data(${COMPONENT_TARGET} "${file}" "BINARY") endforeach() idf_component_get_property(embed_txtfiles "${component_name}" EMBED_TXTFILES) foreach(file IN LISTS embed_txtfiles) + get_filename_component(file "${file}" ABSOLUTE BASE_DIR "${component_dir}") target_add_binary_data(${COMPONENT_TARGET} "${file}" "TEXT") endforeach() diff --git a/tools/cmakev2/utilities.cmake b/tools/cmakev2/utilities.cmake index 627cc2ea7a4..a2804964184 100644 --- a/tools/cmakev2/utilities.cmake +++ b/tools/cmakev2/utilities.cmake @@ -837,12 +837,7 @@ function(target_add_binary_data target embed_file embed_type) idf_build_get_property(build_dir BUILD_DIR) idf_build_get_property(idf_path IDF_PATH) - # The target_add_binary_data function is also called within the - # idf_component_include function, which is not executed in the component - # directory context. Therefore, ensure that the absolute path of the - # embedded file is resolved relative to the component directory. - idf_component_get_property(component_directory "${target}" COMPONENT_DIR) - get_filename_component(embed_file "${embed_file}" ABSOLUTE BASE_DIR "${component_directory}") + get_filename_component(embed_file "${embed_file}" ABSOLUTE) get_filename_component(name "${embed_file}" NAME) set(embed_srcfile "${build_dir}/${name}.S")