Chapter 4. API Guides
mkdir -p build
cd
build
cmake .. -G Ninja
# or 'Unix Makefiles'
ninja
In the above list, the cmake command configures the project and generates build files for use with the final build
tool. In this case the final build tool is Ninja: running ninja actually builds the project.
It's not necessary to run cmake more than once. After the first build, you only need to run ninja each time.
ninja will automatically re-invoke cmake if the project needs reconfiguration.
If using CMake with ninja or make, there are also targets for more of the idf.py sub-commands - for example
running make menuconfig or ninja menuconfig in the build directory will work the same as idf.py
menuconfig.
Note: If you're already familiar with CMake, you may find the ESP-IDF CMake-based build system unusual
because it wraps a lot of CMake's functionality to reduce boilerplate. See
writing pure CMake components
for some
information about writing more "CMake style"components.
Flashing with ninja or make
It's possible to build and flash directly from ninja or make by running a target like:
ninja flash
Or:
make app-flash
Available targets are: flash, app-flash (app only), bootloader-flash (bootloader only).
When flashing this way, optionally set the ESPPORT and ESPBAUD environment variables to specify the serial port
and baud rate. You can set environment variables in your operating system or IDE project. Alternatively, set them
directly on the command line:
ESPPORT=/dev/ttyUSB0 ninja flash
Note: Providing environment variables at the start of the command like this is Bash shell Syntax. It will work on
Linux and macOS. It won't work when using Windows Command Prompt, but it will work when using Bash-like
shells on Windows.
Or:
make -j3 app-flash ESPPORT=COM4
ESPBAUD=2000000
Note: Providing variables at the end of the command line is make syntax, and works for make on all platforms.
Using CMake in an IDE
You can also use an IDE with CMake integration. The IDE will want to know the path to the project's CMake-
Lists.txt file. IDEs with CMake integration often provide their own build tools (CMake calls these"generators"
) to build the source files as part of the IDE.
When adding custom non-build steps like "flash"to the IDE, it is recommended to execute idf.py for these
"special"commands.
For more detailed information about integrating ESP-IDF with CMake into an IDE, see
Build System
Metadata.
Espressif Systems
1272
Release v4.4
Submit Document Feedback
Need help?
Do you have a question about the ESP32-S2 and is the answer not in the manual?