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.
MyProjectName/main/CMakeLists.txt
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
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
# Set name of project (as PROJECT_NAME)
project(blink-led C CXX ASM)
MyProjectName/main/CMakeLists.txt
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)
idf_component_register(
SRCS
"my_project_file_name.c"
"another_source_file1.c"
"another_source_file2.c"
INCLUDE_DIRS
"."
"header_files"
)
REQUIRES list
See here.