Chapter 4. API Guides
set_property(DIRECTORY "${COMPONENT_DIR}" APPEND PROPERTY
ADDITIONAL_MAKE_CLEAN_FILES
This answer is adapted from the
ESP-IDF builds.
In this example, logo.h will be generated in the current directory (the build directory) while logo.bmp comes with the
component and resides under the component path. Because logo.h is a generated file, it should be cleaned when the
project is cleaned. For this reason it is added to the
Note:
If generating files as part of the project CMakeLists.txt file, not a component CMakeLists.txt, then use
build property PROJECT_DIR instead of ${COMPONENT_DIR} and ${PROJECT_NAME}.elf instead of
${COMPONENT_LIB}.)
If a a source file from another component included logo.h, then add_dependencies would need to be called
to add a dependency between the two components, to ensure that the component source files were always compiled
in the correct order.
Embedding Binary Data
Sometimes you have a file with some binary or text data that you'd like to make available to your component - but
you don't want to reformat the file as C source.
You can specify argument EMBED_FILES in the component registration, giving space-delimited names of the files
to embed:
idf_component_register(...
Or if the file is a string, you can use the variable EMBED_TXTFILES. This will embed the contents of the text file
as a null-terminated string:
idf_component_register(...
The file's contents will be added to the .rodata section in flash, and are available via symbol names as follows:
extern const
uint8_t
pem_start");
→
extern const
uint8_t
pem_end");
→
The names are generated from the full name of the file, as given in EMBED_FILES. Characters /, ., etc. are replaced
with underscores. The _binary prefix in the symbol name is added by objcopy and is the same for both text and binary
files.
To embed a file into a project, rather than a component, you can call the function target_add_binary_data
like this:
target_add_binary_data(myproject.elf "main/data.bin"
Place this line after the project() line in your project CMakeLists.txt file. Replace myproject.elf with your
project name. The final argument can be TEXT to embed a null-terminated string, or BINARY to embed the content
as-is.
For an example of using this technique, see the "main"component of the file_serving example
cols/http_server/file_serving/main/CMakeLists.txt
It is also possible embed a generated file:
Espressif Systems
logo.h)
CMake FAQ
entry, which contains some other examples that will also work with
ADDITIONAL_MAKE_CLEAN_FILES
EMBED_FILES
server_root_cert.der)
EMBED_TXTFILES
server_root_cert.pem)
server_root_cert_pem_start[]
server_root_cert_pem_end[]
- two files are loaded at build time and linked into the firmware.
1285
Submit Document Feedback
(continued from previous page)
property.
asm("_binary_server_root_cert_
asm("_binary_server_root_cert_
TEXT)
proto-
Release v4.4
Need help?
Do you have a question about the ESP32-S2 and is the answer not in the manual?