Chapter 4. API Guides
Build Scripts
The listfiles for the ESP-IDF build system reside in /tools/cmake. The modules which implement core build system
functionality are as follows:
• build.cmake - Build related commands i.e. build initialization, retrieving/setting build properties,
build processing.
• component.cmake - Component related commands i.e. adding components, retrieving/setting
component properties, registering components.
• kconfig.cmake - Generation of configuration files (sdkconfig, sdkconfig.h, sdkconfig.cmake, etc.)
from Kconfig files.
• ldgen.cmake - Generation of final linker script from linker fragment files.
• target.cmake - Setting build target and toolchain file.
• utilities.cmake - Miscellaneous helper commands.
Aside from these files, there are two other important CMake scripts in /tools/cmake:
• idf.cmake - Sets up the build and includes the core modules listed above. Included in CMake
projects in order to access ESP-IDF build system functionality.
• project.cmake - Includes idf.cmake and provides a custom project() command that takes
care of all the heavy lifting of building an executable. Included in the top-level CMakeLists.txt of
standard ESP-IDF projects.
The rest of the files in /tools/cmake are support or third-party scripts used in the build process.
Build Process
This section describes the standard ESP-IDF application build process. The build process can be broken down roughly
into four phases:
Fig. 2: ESP-IDF Build System Process
Initialization This phase sets up necessary parameters for the build.
• Upon inclusion of idf.cmake in project.cmake, the following steps are performed:
– Set IDF_PATH from environment variable or inferred from path to project.cmake
included in the top-level CMakeLists.txt.
– Add /tools/cmake to CMAKE_MODULE_PATH and include core modules plus the various
helper/third-party scripts.
– Set build tools/executables such as default Python interpreter.
– Get ESP-IDF git revision and store as IDF_VER.
– Set global build specifications i.e. compile options, compile definitions, include directo-
ries for all components in the build.
– Add components in components to the build.
• The initial part of the custom project() command performs the following steps:
– Set IDF_TARGET from environment variable or CMake cache and the corresponding
CMAKE_TOOLCHAIN_FILE to be used.
– Add components in EXTRA_COMPONENTS_DIRS to the build.
– Prepare arguments for calling command idf_build_process() from vari-
ables such as COMPONENTS/EXCLUDE_COMPONENTS, SDKCONFIG, SDKCON-
FIG_DEFAULTS.
The call to idf_build_process() command marks the end of this phase.
Espressif Systems 1296
Submit Document Feedback
Release v4.4