Chapter 4. API Guides
• Optional "components"directory contains components that are part of the project. A project does not have
to contain custom components of this kind, but it can be useful for structuring reusable code or including third
party components that aren't part of ESP-IDF. Alternatively, EXTRA_COMPONENT_DIRS can be set in
the top-level CMakeLists.txt to look for components in other places. See the
info. If you have a lot of source files in your project, we recommend grouping most into components instead
of putting them all in "main".
•"main"directory is a special component that contains source code for the project itself. "main"is a default
name, the CMake variable COMPONENT_DIRS includes this component but you can modify this variable.
•"build"directory is where build output is created. This directory is created by idf.py if it doesn't already
exist. CMake configures the project and generates interim build files in this directory. Then, after the main
build process is run, this directory will also contain interim object files and libraries as well as final binary
output files. This directory is usually not added to source control or distributed with the project source code.
Component directories each contain a component CMakeLists.txt file. This file contains variable definitions to
control the build process of the component, and its integration into the overall project. See
Files
for more details.
Each component may also include a Kconfig file defining the
menuconfig. Some components may also include Kconfig.projbuild and project_include.cmake
files, which are special files for
4.4.4 Project CMakeLists File
Each project has a single top-level CMakeLists.txt file that contains build settings for the entire project. By
default, the project CMakeLists can be quite minimal.
Minimal Example CMakeLists
Minimal project:
cmake_minimum_required(VERSION
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(myProject)
Mandatory Parts
The inclusion of these three lines, in the order shown above, is necessary for every project:
• cmake_minimum_required(VERSION 3.5) tells CMake the minimum version that is required to
build the project. ESP-IDF is designed to work with CMake 3.5 or newer. This line must be the first line in
the CMakeLists.txt file.
• include($ENV{IDF_PATH}/tools/cmake/project.cmake) pulls in the rest of the CMake
functionality to configure the project, discover all the components, etc.
• project(myProject) creates the project itself, and specifies the project name. The project name is used
for the final binary output files of the app - ie myProject.elf, myProject.bin. Only one project can
be defined per CMakeLists file.
Optional Project Variables
These variables all have default values that can be overridden for custom behaviour.
/tools/cmake/project.cmake
• COMPONENT_DIRS: Directories to search for components.
PROJECT_DIR/components, and EXTRA_COMPONENT_DIRS. Override this variable if you don't
want to search for components in these places.
• EXTRA_COMPONENT_DIRS: Optional list of additional directories to search for components. Paths can be
relative to the project directory, or absolute.
Espressif Systems
overriding parts of the
project.
3.5)
for all of the implementation details.
Submit Document Feedback
component configuration
Defaults to IDF_PATH/components,
1274
renaming main
section for more
Component CMakeLists
options that can be set via
Look in
Release v4.4
Need help?
Do you have a question about the ESP32-S2 and is the answer not in the manual?