My project looks like this,
.components
...drivers
......usb
........usb.c
........usb.h
......lcd
......etc
.main
...main.c
In main.c, I would like to include libraries as
#include "drivers/usb.h"
#include "drivers/lcd.h"
How to configure CMake to include subfolders, but include component itself as a folder?
I have tried to include subfolders as PRIV_INCLUDE_DIRS, but it works like this,
#include "usb/usb.h"
instead of
#include "component/sourcefile.h"
esp-idf components like driver and FreeRTOS manage to achive this so well, just can't figure out how to implement such style.
Any help appreciated!
First of all, if you want to use a header file outside the component itself, you need to use
INCLUDE_DIRS
instead ofPRIV_INCLUDE_DIRS
when callingidf_component_register(...)
in the component'sCMakeLists.txt
. For more information, see the IDF Build System component commands documentation page.To enable including header files as
driver/xxx.h
, you can do the following: Add a sub-folderdriver
in each ofusb
,lcd
, etc., move the respective header files there and add each of the directories (usb
,lcd
, etc.), usingINCLUDE_DIRS
inidf_component_register(...)
. Your file tree would look like:This is in fact done for many driver headers in ESP-IDF itself.