Skip to content

Commit aed204c

Browse files
committed
cmake: allow embedding to depend on a target
1 parent 8b67370 commit aed204c

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
@@ -830,6 +830,24 @@ Place this line after the ``project()`` line in your project CMakeLists.txt file
830830

831831
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.
832832

833+
834+
.. highlight:: cmake
835+
836+
It is also possible embed a generated file::
837+
838+
add_custom_command(OUTPUT my_processed_file.bin
839+
COMMAND my_process_file_cmd my_unprocessed_file.bin)
840+
target_add_binary_data(my_target "my_processed_file.bin" BINARY)
841+
842+
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.
843+
844+
To specify a dependence on a target, use the ``DEPENDS`` argument::
845+
846+
add_custom_target(my_process COMMAND ...)
847+
target_add_binary_data(my_target "my_embed_file.bin" BINARY DEPENDS my_process)
848+
849+
The ``DEPENDS`` argument to ``target_add_binary_data`` ensures that the target executes first.
850+
833851
Code and Data Placements
834852
------------------------
835853

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)