I started my project with a simple "blink" example and used it as a template to write my code.
This example used only one source file blink.c
.
Eventually, I want to a use multi source files project and can't figure out how to configure CMakeLists.txt
in order to compile the project.
My CMakeLists.txt
is:
cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(blink)
I want to add for example init.c
.
I tried different ways, but with no success.
None of idf_component_register() / register_component() worked for me.
Any idea how to correctly configure the project?
Right, the CMake project hierarchy in ESP IDF is a bit tricky. You are looking at the wrong CMakeLists.txt
file. Instead of the one in root directory, open the one in blink/main/CMakeLists.txt
. This file lists the source files for the "main" component, which is the one you want to use. It would look like this:
idf_component_register(SRCS "blink.c" "init.c"
INCLUDE_DIRS ".")
Make sure your init.c
file is in the same directory as this CMakeLists.txt
and blink.c
.
I also recommend taking a look at the Espressif Build System documentation, it's quite useful.
You should edit the CMakeLists.txt located in your main
folder inside your project folder. In addition, you need to put the directory that contains the header files into INCLUDE_DIRS
parameter.
For example, if you have this file structure in your project (you're putting init.h
inside include
folder) as shown below:
blink/
├── main/
│ ├── include/
│ │ └── init.h
│ ├── blink.c
│ ├── CMakeLists.txt
│ ├── init.c
│ └── ...
├── CMakeLists.txt
└── ...
The content in your main/CMakeLists.txt
should be:
idf_component_register(SRCS "blink.c" "init.c"
INCLUDE_DIRS "." "include")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With