Chapter 4. API Guides
• COMPONENTS: A list of component names to build into the project. Defaults to all components found in the
COMPONENT_DIRS directories. Use this variable to“trim down”the project for faster build times. Note that
any component which “requires”another component via the REQUIRES or PRIV_REQUIRES arguments
on component registration will automatically have it added to this list, so the COMPONENTS list can be very
short.
Any paths in these variables can be absolute paths, or set relative to the project directory.
To set these variables, use the cmake set command ie set(VARIABLE "VALUE"). The set() commands
should be placed after the cmake_minimum(...) line but before the include(...) line.
Renaming main component
The build system provides special treatment to the main component. It is a component that gets automatically added
to the build provided that it is in the expected location, PROJECT_DIR/main. All other components in the build are
also added as its dependencies, saving the user from hunting down dependencies and providing a build that works right
out of the box. Renaming the main component causes the loss of these behind-the-scenes heavy lifting, requiring the
user to specify the location of the newly renamed component and manually specifying its dependencies. Specifically,
the steps to renaming main are as follows:
1. Rename main directory.
2. Set EXTRA_COMPONENT_DIRS in the project CMakeLists.txt to include the renamed main directory.
3. Specify the dependencies in the renamed component’s CMakeLists.txt file via REQUIRES or
PRIV_REQUIRES arguments on component registration.
Overriding default build specifications
The build sets some global build specifications (compile flags, definitions, etc.) that gets used in compiling all sources
from all components.
For example, one of the default build specifications set is the compile option -Wextra. Suppose a user wants to use
override this with -Wno-extra, it should be done after project():
cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(myProject)
idf_build_set_property(COMPILE_OPTIONS "-Wno-error" APPEND)
This ensures that the compile options set by the user won’t be overriden by the default build specifications, since the
latter are set inside project().
4.4.5 Component CMakeLists Files
Each project contains one or more components. Components can be part of ESP-IDF, part of the project’s own
components directory, or added from custom component directories (see above).
A component is any directory in the COMPONENT_DIRS list which contains a CMakeLists.txt file.
Searching for Components
The list of directories in COMPONENT_DIRS is searched for the project’s components. Directories in this list can
either be components themselves (ie they contain a CMakeLists.txt file), or they can be top-level directories whose
sub-directories are components.
When CMake runs to configure the project, it logs the components included in the build. This list can be useful for
debugging the inclusion/exclusion of certain components.
Espressif Systems 1275
Submit Document Feedback
Release v4.4