fix(cmakev2/utilities): resolve embed file path in idf_component_include

Commit f62f45cf5c 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: f62f45cf5c ("fix(cmakev2/utilities): add a dependency target for the embedded file")

Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
This commit is contained in:
Frantisek Hrbata
2026-04-27 22:07:10 +08:00
committed by BOT
parent bff4657ad6
commit cfc60dba16
2 changed files with 5 additions and 6 deletions
+4
View File
@@ -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()