Skip to content

Commit a9dd9e3

Browse files
committed
Merge branch 'feature/embed_generated_files' into 'master'
cmake: allow embedding files to be dependent on a target See merge request espressif/esp-idf!8535
2 parents 59347d6 + aed204c commit a9dd9e3

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

docs/en/api-guides/build-system.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,24 @@ Place this line after the ``project()`` line in your project CMakeLists.txt file
832832

833833
For an example of using this technique, see :example:`protocols/https_request` - the certificate file contents are loaded from the text .pem file at compile time.
834834

835+
836+
.. highlight:: cmake
837+
838+
It is also possible embed a generated file::
839+
840+
add_custom_command(OUTPUT my_processed_file.bin
841+
COMMAND my_process_file_cmd my_unprocessed_file.bin)
842+
target_add_binary_data(my_target "my_processed_file.bin" BINARY)
843+
844+
In the example above, ``my_processed_file.bin`` is generated from ``my_unprocessed_file.bin`` through some command ``my_process_file_cmd``, then embedded into the target.
845+
846+
To specify a dependence on a target, use the ``DEPENDS`` argument::
847+
848+
add_custom_target(my_process COMMAND ...)
849+
target_add_binary_data(my_target "my_embed_file.bin" BINARY DEPENDS my_process)
850+
851+
The ``DEPENDS`` argument to ``target_add_binary_data`` ensures that the target executes first.
852+
835853
Code and Data Placements
836854
------------------------
837855

tools/cmake/utilities.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ endfunction()
7777
# by converting it to a generated source file which is then compiled
7878
# to a binary object as part of the build
7979
function(target_add_binary_data target embed_file embed_type)
80-
cmake_parse_arguments(_ "" "RENAME_TO" "" ${ARGN})
80+
cmake_parse_arguments(_ "" "RENAME_TO" "DEPENDS" ${ARGN})
8181
idf_build_get_property(build_dir BUILD_DIR)
8282
idf_build_get_property(idf_path IDF_PATH)
8383

@@ -99,7 +99,7 @@ function(target_add_binary_data target embed_file embed_type)
9999
-D "FILE_TYPE=${embed_type}"
100100
-P "${idf_path}/tools/cmake/scripts/data_file_embed_asm.cmake"
101101
MAIN_DEPENDENCY "${embed_file}"
102-
DEPENDS "${idf_path}/tools/cmake/scripts/data_file_embed_asm.cmake"
102+
DEPENDS "${idf_path}/tools/cmake/scripts/data_file_embed_asm.cmake" ${__DEPENDS}
103103
WORKING_DIRECTORY "${build_dir}"
104104
VERBATIM)
105105

0 commit comments

Comments
 (0)