Files
esp-idf/tools
Frantisek Hrbata 22626469de fix(cmakev2/utilities): add a dependency target for the embedded file
Currently, embedded files can be added in two ways. First, by calling
the `target_add_binary_data` function directly within a component.
Second, by passing `EMBED_FILES` or `EMBED_TXTFILES` to
`idf_component_register`, or in cmakev2 by setting the `EMBED_FILES` or
`EMBED_TXTFILES` component properties.

The source file for an embedded file is generated using
`add_custom_command`. When the embedded file is added directly in the
component's CMakeLists.txt file by using the `target_add_binary_data`
function, the `add_custom_command` command is evaluated in the same
directory context where the component target is created. As a result,
the generated embedded file can be used automatically as a file
dependency in component's sources.

However, when an embedded file is added via `idf_component_register` or
by setting the component property, the call to `add_custom_command`
inside `target_add_binary_data` occurs after the component has been
evaluated, specifically after the `add_subdirectory` call, within
`idf_component_include`. This means it is not created in the same
directory context as the component's target. In this case, the embedded
file dependency is not added to the component's target, and the embedded
file is not generated. This behavior is described in the
`add_custom_command` documentation [1].

   > A target created in the same directory (CMakeLists.txt file)
   > that specifies any output of the custom command as a source
   > file is given a rule to generate the file using the command at
   > build time.

To fix this issue, an explicit custom target for the generated embedded
file is created and added as a dependency of the component's target,
ensuring that the file is generated correctly.

[1] - https://cmake.org/cmake/help/latest/command/add_custom_command.html

Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
2026-03-20 08:13:26 +01:00
..
2022-08-01 15:52:21 +08:00
2025-09-26 10:25:25 +08:00
2025-09-30 15:28:55 +02:00
2025-09-30 15:28:55 +02:00
2025-06-03 08:37:56 +02:00
2025-06-03 08:37:56 +02:00
2025-06-03 08:37:56 +02:00
2025-06-03 08:37:56 +02:00
2025-08-01 08:05:10 +02:00
2025-08-01 08:05:10 +02:00
2023-09-27 08:43:45 +02:00
2025-09-30 15:28:55 +02:00
2025-09-30 15:28:55 +02:00