This is working for me, a standard esp-idf C project, and few components.
Originally, the include files where located in the component directory (the headers for common_utils next to the sources in common_utils, the headers for snmp in the snmp directory), but to mimick your setup, I created an
include directory and moved the .h files.
Code: Select all
experiments/waveshare/$ tree -d -L 3
.
├── build
├── components
│ ├── common_utils
│ │ ├── example
│ │ └── include
│ ├── snmp
│ │ ├── example
│ │ └── include
│ └── wifi_utils
│ ├── example
│ └── include
├── data
└── main
So, this is a test project called waveshare, with 3 components. Every component has it's own CMakeLists.txt, for example:
Code: Select all
include($ENV{IDF_PATH}/tools/cmake/version.cmake)
execute_process(
COMMAND git describe --tags --always
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Generate a header file with version information
configure_file( "${COMPONENT_DIR}/version.h.in" "${COMPONENT_DIR}/version.h" @ONLY )
idf_component_register(
SRCS snmp.c snmp-utils.c hwinfo.c
INCLUDE_DIRS . include
)
I didn't alter my code, it is still using includes like: #include <snmp.h> I only added the
include directory name to the INCLUDE_DIRS statement in idf_component_register.
For clarity; my top level CMakeLists.txt:
Code: Select all
cmake_minimum_required(VERSION 3.16)
set(PROJECT_VER 0.0.0.7)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(WaveShare)
idf_build_set_property(COMPILE_OPTIONS "-D_PROJECT_NAME_=\"${CMAKE_PROJECT_NAME}\"" APPEND)
idf_build_set_property(COMPILE_OPTIONS "-D_PROJECT_VER_=\"${PROJECT_VER}\"" APPEND)
target_add_binary_data(${CMAKE_PROJECT_NAME}.elf "data/index.html" TEXT)
and the CMakeLists.txt in the top source directory (main):
Code: Select all
idf_component_register(
SRCS main.c app_wifi.c app_web.c task_ota.c task_rgb.c lcd.c esp_lcd_panel_st7789t.c
REQUIRES app_update esp_https_ota esp_http_server mqtt driver json esp-tls wifi_utils snmp common_utils lvgl led_strip
)