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.

USEFUL?
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.

Comments

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