Chapter 4. API Guides
add_custom_command(OUTPUT my_processed_file.bin
COMMAND my_process_file_cmd
target_add_binary_data(my_target "my_processed_file.bin"
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.
To specify a dependence on a target, use the DEPENDS argument:
add_custom_target(my_process COMMAND
target_add_binary_data(my_target "my_embed_file.bin" BINARY DEPENDS
The DEPENDS argument to target_add_binary_data ensures that the target executes first.
Code and Data Placements
ESP-IDF has a feature called linker script generation that enables components to define where its code and data will
be placed in memory through linker fragment files. These files are processed by the build system, and is used to
augment the linker script used for linking app binary. See
a detailed discussion of the mechanism.
Fully Overriding The Component Build Process
Obviously, there are cases where all these recipes are insufficient for a certain component, for example when the
component is basically a wrapper around another third-party component not originally intended to be compiled under
this build system. In that case, it's possible to forego the ESP-IDF build system entirely by using a CMake feature
called ExternalProject. Example component CMakeLists:
# External build process for quirc, runs in source dir and
# produces libquirc.a
externalproject_add(quirc_build
PREFIX
${COMPONENT_DIR}
SOURCE_DIR ${COMPONENT_DIR}/quirc
CONFIGURE_COMMAND ""
BUILD_IN_SOURCE 1
BUILD_COMMAND make
INSTALL_COMMAND ""
)
# Add libquirc.a to the build process
add_library(quirc STATIC IMPORTED
add_dependencies(quirc
set_target_properties(quirc PROPERTIES IMPORTED_LOCATION
${COMPONENT_DIR}/quirc/libquirc.a)
set_target_properties(quirc PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
${COMPONENT_DIR}/quirc/lib)
set_directory_properties(
"${COMPONENT_DIR}/quirc/libquirc.a")
(The above CMakeLists.txt can be used to create a component named quirc that builds the
own Makefile.)
• externalproject_add defines an external build system.
– SOURCE_DIR, CONFIGURE_COMMAND, BUILD_COMMAND and INSTALL_COMMAND should al-
ways be set. CONFIGURE_COMMAND can be set to an empty string if the build system has no "configure"
step. INSTALL_COMMAND will generally be empty for ESP-IDF builds.
– Setting BUILD_IN_SOURCE means the build directory is the same as the source directory. Otherwise
you can set BUILD_DIR.
Espressif Systems
...)
CC=${CMAKE_C_COMPILER}
GLOBAL)
quirc_build)
PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
1286
Submit Document Feedback
my_unprocessed_file.bin)
BINARY)
Linker Script Generation
for a quick start guide as well as
libquirc.a
my_process)
quirc
project using its
Release v4.4
Need help?
Do you have a question about the ESP32-S2 and is the answer not in the manual?