Chapter 4. API Guides
Multiple components with the same name
When ESP-IDF is collecting all the components to compile, it will do this in the order specified by COMPO-
NENT_DIRS; by default, this means ESP-IDF's internal components first (IDF_PATH/components), then
any components in directories specified in EXTRA_COMPONENT_DIRS, and finally the project's components
(PROJECT_DIR/components). If two or more of these directories contain component sub-directories with the
same name, the component in the last place searched is used. This allows, for example, overriding ESP-IDF com-
ponents with a modified version by copying that component from the ESP-IDF components directory to the project
components directory and then modifying it there. If used in this way, the ESP-IDF directory itself can remain
untouched.
Note:
If a component is overridden in an existing project by moving it to a new location, the project will not
automatically see the new component path. Run idf.py reconfigure (or delete the project build folder) and
then build again.
Minimal Component CMakeLists
The minimal component CMakeLists.txt file simply registers the component to the build system using
idf_component_register:
idf_component_register(SRCS "foo.c" "bar.c"
• SRCS is a list of source files (*.c, *.cpp, *.cc, *.S). These source files will be compiled into the com-
ponent library.
• INCLUDE_DIRS is a list of directories to add to the global include search path for any component which
requires this component, and also the main source files.
• REQUIRES is not actually required, but it is very often required to declare what other components this com-
ponent will use. See
A library with the name of the component will be built and linked into the final app.
Directories are usually specified relative to the CMakeLists.txt file itself, although they can be absolute.
There are other arguments that can be passed to idf_component_register. These arguments are discussed
here.
See
example component requirements
Lists.txt examples.
Create a new component
Use the command idf.py create-component for creating a new component. The new component will contain
set of files necessary for building a component. You may include the component's header file into your project and
use its functionality. For more information execute idf.py create-component --help.
Example:
idf.py -C components create-component my_component
The example will create a new component in the subdirectory components under the current working directory. For
more information about components follow the documentation page
Preset Component Variables
The following component-specific variables are available for use inside component CMakeLists, but should not be
modified:
Espressif Systems
INCLUDE_DIRS "include"
REQUIRES
mbedtls)
Component
Requirements.
and
example component CMakeLists
Submit Document Feedback
for more complete component CMake-
see
above.
1276
Release v4.4
Need help?
Do you have a question about the ESP32-S2 and is the answer not in the manual?