how to make CMake structure for ESP-IDF components with separate include/src directories?
Posted: Wed Mar 26, 2025 10:33 pm
I have an ESP-IDF v5.4 project with this structure:
How should I configure the CMakeLists.txt files to handle multiple components?
Do I need a CMakeLists.txt file in each folder (components, mis_comp, include, and src)?
I tried to do this in cmake from the main folder:
and mis_comp folder:
but it didn't work for me, it doesn't compile the program.
What’s the right way to do it?
Code: Untitled.c Select all
root/
├── main/
│ ├── CMakeLists.txt
│ └── main.c
└── components/
└── mis_comp/
├── CMakeLists.txt
├── include/ # .h files
└── src/ # .c files
Do I need a CMakeLists.txt file in each folder (components, mis_comp, include, and src)?
I tried to do this in cmake from the main folder:
Code: Untitled.cmake Select all
idf_component_register(
SRCS
"main.c"
INCLUDE_DIRS "."
REQUIRES mis_comp
)
and mis_comp folder:
Code: Untitled.cmake Select all
idf_component_register(
SRCS
"src/initGPIO.c"
"src/adc_esp32.c"
"src/initWifi.c"
"src/fun_i2c_master.c"
"src/fun_i2c_slave.c"
"src/mqtt_esp32.c"
INCLUDE_DIRS
"include"
)
but it didn't work for me, it doesn't compile the program.
What’s the right way to do it?