mirror of
https://github.com/espressif/esp-idf.git
synced 2026-09-22 13:01:16 +03:00
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>