ESP-IDF uses the CMake build automation tool and if you created your project from one of the sample projects you will have the necessary “CMakeLists.txt” files. These contain the instructions describing the project sources files and targets.

Which CMakeLists.txt file is used for what ?

The CMake project hierarchy in ESP IDF is a bit tricky!

MyProjectName/CMakeLists.txt example contents (root directory)

This file lists the setup for the whole project, it isn’t used for adding project files.


This file lists the source files for the “main” component, which is the one you want to use for adding project files etc.

MyProjectName/CMakeLists.txt (root directory)

Example contents

# Include build functions from ESP-IDF SDK

# Set name of project (as PROJECT_NAME)
project(blink-led C CXX ASM)

Basic file example contents:

# SRCS is a list of your soruce code files
# INCLUDE_DIRS is a list of your include directories, e.g. if you have your header files located in a seperate folder
idf_component_register(SRCS "my_project_file_name.c"
                    INCLUDE_DIRS ".")

An example where you have several files and a folder to include:
(We’ve added files on separate lines for ease of reading, you don’t need to though)



See here.

We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.


Your email address will not be published. Required fields are marked *