CMake include extra components

gibson12345
Posts: 58
Joined: Wed Jul 17, 2019 11:45 pm

CMake include extra components

Postby gibson12345 » Tue Aug 27, 2019 5:05 am

Hey everyone,

I'm trying to include an extra library that interfaces with an accelerometer and I'm not quite understanding how to include it as an extra component.

My dir structure looks like this

Code: Select all

- project/
             - CMakeLists.txt
             - sdkconfig
             - components/ 
                           - Lib1/ 
                                         - CMakeLists.txt
                                         - src1.c
                                         - src1.h
                           - Lib2/ 
                                         - CMakeLists.txt
                                         - src1.c
                                         - src2.h
             - main/       
                           - main.c
                           - accel.c
                           - accel.h
                           - CMakeLists.txt
What do I need to change in my top level CMakeLists.txt and add to the ones inside the components themselves

Cheers,
Gibson

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: CMake include extra components

Postby ESP_Angus » Tue Aug 27, 2019 11:41 pm

Hi Gibson,

(Reply assumes your using ESP-IDF V4.x or current master branch, if you're using v3.x then some of the specifics are a little different.)

Provided "Lib1" and "Lib2" have CMakeLists.txt files that call "idf_component_register", they should be added to the build already. You can check they're in the list of components shown in the log when CMake runs (or when "idf.py reconfigure" runs).

How exactly does it fail at the moment?

If it's a failure to include headers between components, it may be because CMake-based components have to declare their dependencies. So if Lib1 depends on Lib2 (or vice versa) then Lib1 will need to pass "REQUIRES Lib2" or "PRIV_REQUIRES Lib2" in "idf_component_register". You can about these in the docs:
https://docs.espressif.com/projects/esp ... quirements

gibson12345
Posts: 58
Joined: Wed Jul 17, 2019 11:45 pm

Re: CMake include extra components

Postby gibson12345 » Tue Aug 27, 2019 11:54 pm

Hey Angus,
You are correct I am operating in the 4.0 branch
It seems to be failing on this:
ninja: no work to do.
[2/11] Building C object esp-idf/lis3dh/CMakeFiles/__idf_lis3dh.dir/lis3dh.c.obj
FAILED: esp-idf/lis3dh/CMakeFiles/__idf_lis3dh.dir/lis3dh.c.obj
C:\Users\lachlan\.espressif\tools\xtensa-esp32-elf\esp32-2019r1-8.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-gcc.exe -Iconfig -IC:/esp/esp-idf/components/newlib/platform_include -IC:/esp/esp-idf/components/freertos/include -IC:/esp/esp-idf/components/heap/include -IC:/esp/esp-idf/components/log/include -IC:/esp/esp-idf/components/soc/esp32/include -IC:/esp/esp-idf/components/soc/include -IC:/esp/esp-idf/components/esp_rom/include -IC:/esp/esp-idf/components/esp_common/include -IC:/esp/esp-idf/co
mponents/xtensa/include -IC:/esp/esp-idf/components/xtensa/esp32/include -IC:/esp/esp-idf/components/esp32/include -IC:/esp/esp-idf/components/driver/include -IC:/esp/esp-idf/components/esp_ringbuf/include -IC:/esp/esp-idf/components/esp_event/include -IC:/esp/esp-idf/components/tcpip_adapter/include -IC:/esp/esp-idf/components/lwip/include/apps -IC:/esp/esp-idf/components/lwip/include/apps/sntp -IC:/esp/esp-idf/components/lwip/lwip/src/include -IC:/esp/esp-idf/components/lwip/port/esp32/include
-IC:/esp/esp-idf/components/lwip/port/esp32/include/arch -IC:/esp/esp-idf/components/vfs/include -IC:/esp/esp-idf/components/esp_wifi/include -IC:/esp/esp-idf/components/esp_wifi/esp32/include -IC:/esp/esp-idf/components/esp_eth/include -IC:/esp/esp-idf/components/efuse/include -IC:/esp/esp-idf/components/efuse/esp32/include -IC:/esp/esp-idf/components/app_trace/include -mlongcalls -Wno-frame-address -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -nostdlib -Wall -Werror=all -
Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wextra -Wno-unused-parameter -Wno-sign-compare -ggdb -Og -std=gnu99 -Wno-old-style-declaration -D_GNU_SOURCE -DIDF_VER=\"v4.0-dev-1443-g39f090a4f-dirty\" -DGCC_NOT_5_2_0 -DESP_PLATFORM -MD -MT esp-idf/lis3dh/CMakeFiles/__idf_lis3dh.dir/lis3dh.c.obj -MF esp-idf\lis3dh\CMakeFiles\__idf_lis3dh.dir\lis3dh.c.obj.d -o esp-idf/lis3dh/CMakeFiles/__idf_lis3dh.dir/lis3dh.c.obj -c .
./components/lis3dh/lis3dh.c
In file included from ../components/lis3dh/lis3dh.h:94,
from ../components/lis3dh/lis3dh.c:53:
../components/lis3dh/lis3dh_platform.h:52:10: fatal error: esp8266_wrapper.h: No such file or directory
#include "esp8266_wrapper.h"
^~~~~~~~~~~~~~~~~~~
compilation terminated.
[3/11] Building C object esp-idf/main/CMakeFiles/__idf_main.dir/accelerometer.c.obj
FAILED: esp-idf/main/CMakeFiles/__idf_main.dir/accelerometer.c.obj
C:\Users\lachlan\.espressif\tools\xtensa-esp32-elf\esp32-2019r1-8.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-gcc.exe -DHAVE_CONFIG_H -DMBEDTLS_CONFIG_FILE=\"mbedtls/esp_config.h\" -DUNITY_INCLUDE_CONFIG_H -DWITH_POSIX -Iconfig -I../main/. -IC:/esp/esp-idf/components/newlib/platform_include -IC:/esp/esp-idf/components/freertos/include -IC:/esp/esp-idf/components/heap/include -IC:/esp/esp-idf/components/log/include -IC:/esp/esp-idf/components/soc/esp32/include -IC:/esp/esp-idf/components/soc/includ
e -IC:/esp/esp-idf/components/esp_rom/include -IC:/esp/esp-idf/components/esp_common/include -IC:/esp/esp-idf/components/xtensa/include -IC:/esp/esp-idf/components/xtensa/esp32/include -IC:/esp/esp-idf/components/esp32/include -IC:/esp/esp-idf/components/driver/include -IC:/esp/esp-idf/components/esp_ringbuf/include -IC:/esp/esp-idf/components/esp_event/include -IC:/esp/esp-idf/components/tcpip_adapter/include -IC:/esp/esp-idf/components/lwip/include/apps -IC:/esp/esp-idf/components/lwip/include
/apps/sntp -IC:/esp/esp-idf/components/lwip/lwip/src/include -IC:/esp/esp-idf/components/lwip/port/esp32/include -IC:/esp/esp-idf/components/lwip/port/esp32/include/arch -IC:/esp/esp-idf/components/vfs/include -IC:/esp/esp-idf/components/esp_wifi/include -IC:/esp/esp-idf/components/esp_wifi/esp32/include -IC:/esp/esp-idf/components/esp_eth/include -IC:/esp/esp-idf/components/efuse/include -IC:/esp/esp-idf/components/efuse/esp32/include -IC:/esp/esp-idf/components/app_trace/include -IC:/esp/esp-i
df/components/mbedtls/port/include -IC:/esp/esp-idf/components/mbedtls/mbedtls/include -IC:/esp/esp-idf/components/wpa_supplicant/include -IC:/esp/esp-idf/components/wpa_supplicant/port/include -IC:/esp/esp-idf/components/wpa_supplicant/include/esp_supplicant -IC:/esp/esp-idf/components/bootloader_support/include -IC:/esp/esp-idf/components/app_update/include -IC:/esp/esp-idf/components/spi_flash/include -IC:/esp/esp-idf/components/nvs_flash/include -IC:/esp/esp-idf/components/smartconfig_ack/in
clude -IC:/esp/esp-idf/components/pthread/include -IC:/esp/esp-idf/components/espcoredump/include -IC:/esp/esp-idf/components/asio/asio/asio/include -IC:/esp/esp-idf/components/asio/port/include -IC:/esp/esp-idf/components/bt/include -IC:/esp/esp-idf/components/bt/common/osi/include -IC:/esp/esp-idf/components/bt/host/bluedroid/api/include/api -IC:/esp/esp-idf/components/coap/port/include -IC:/esp/esp-idf/components/coap/port/include/coap -IC:/esp/esp-idf/components/coap/libcoap/include -IC:/esp
/esp-idf/components/coap/libcoap/include/coap2 -IC:/esp/esp-idf/components/console/. -IC:/esp/esp-idf/components/nghttp/port/include -IC:/esp/esp-idf/components/nghttp/nghttp2/lib/includes -IC:/esp/esp-idf/components/esp-tls/. -IC:/esp/esp-idf/components/esp-tls/PRIVATE_INCLUDE_DIRS -IC:/esp/esp-idf/components/esp-tls/private_include -IC:/esp/esp-idf/components/esp_adc_cal/include -IC:/esp/esp-idf/components/esp_gdbstub/include -IC:/esp/esp-idf/components/tcp_transport/include -IC:/esp/esp-idf/c
omponents/tcp_transport/PRIVATE_INCLUDE_DIRS -IC:/esp/esp-idf/components/tcp_transport/private_include -IC:/esp/esp-idf/components/esp_http_client/include -IC:/esp/esp-idf/components/esp_http_server/include -IC:/esp/esp-idf/components/esp_https_ota/include -IC:/esp/esp-idf/components/protobuf-c/protobuf-c -IC:/esp/esp-idf/components/protocomm/include/common -IC:/esp/esp-idf/components/protocomm/include/security -IC:/esp/esp-idf/components/protocomm/include/transports -IC:/esp/esp-idf/components/
mdns/include -IC:/esp/esp-idf/components/esp_local_ctrl/include -IC:/esp/esp-idf/components/esp_websocket_client/include -IC:/esp/esp-idf/components/expat/expat/expat/lib -IC:/esp/esp-idf/components/expat/port/include -IC:/esp/esp-idf/components/wear_levelling/include -IC:/esp/esp-idf/components/sdmmc/include -IC:/esp/esp-idf/components/fatfs/diskio -IC:/esp/esp-idf/components/fatfs/vfs -IC:/esp/esp-idf/components/fatfs/src -IC:/esp/esp-idf/components/freemodbus/common/include -IC:/esp/esp-idf/c
omponents/idf_test/include -IC:/esp/esp-idf/components/jsmn/include -IC:/esp/esp-idf/components/json/cJSON -IC:/esp/esp-idf/components/libsodium/libsodium/src/libsodium/include -IC:/esp/esp-idf/components/libsodium/port_include -IC:/esp/esp-idf/components/mqtt/esp-mqtt/include -IC:/esp/esp-idf/components/openssl/include -IC:/esp/esp-idf/components/spiffs/include -IC:/esp/esp-idf/components/ulp/include -IC:/esp/esp-idf/components/unity/include -IC:/esp/esp-idf/components/unity/unity/src -IC:/esp/
esp-idf/components/wifi_provisioning/include -mlongcalls -Wno-frame-address -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -nostdlib -Wall -Werror=all -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wextra -Wno-unused-parameter -Wno-sign-compare -ggdb -Og -std=gnu99 -Wno-old-style-declaration -D_GNU_SOURCE -DIDF_VER=\"v4.0-dev-1443-g39f090a4f-dirty\" -DGCC_NOT_5_2_0 -DESP_PLATFORM -MD -MT esp-idf/main
/CMakeFiles/__idf_main.dir/accelerometer.c.obj -MF esp-idf\main\CMakeFiles\__idf_main.dir\accelerometer.c.obj.d -o esp-idf/main/CMakeFiles/__idf_main.dir/accelerometer.c.obj -c ../main/accelerometer.c
In file included from ../main/accelerometer.c:1:
../main/accelerometer.h:6:10: fatal error: lis3dh.h: No such file or directory
#include "lis3dh.h"
^~~~~~~~~~
So it's failing to locate the actual headers for the library. I've tried reading over that documentation but it's rather vague and unclear to me, but that's likely just my inexperience with CMake. My components do use idf_component_register but don't use any require but I'm unsure if that's the issue it may be for the first error. Looking at it now I don't think it's necessarily an issue with including them as a component because they're shown in the list of components when I try to compile

Cheers,
Gibson

gibson12345
Posts: 58
Joined: Wed Jul 17, 2019 11:45 pm

Re: CMake include extra components

Postby gibson12345 » Fri Aug 30, 2019 3:42 am

Hey @Angus,

Any suggestions I'm sort of lost on this one.

Cheers,
Gibson

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: CMake include extra components

Postby ESP_Angus » Fri Aug 30, 2019 7:07 am

Hi Gibson,

Sorry for the delay in getting back to you.
gibson12345 wrote:
Tue Aug 27, 2019 11:54 pm

Code: Select all

C:\Users\lachlan\.espressif\tools\xtensa-esp32-elf\esp32-2019r1-8.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-gcc.exe  -Iconfig -IC:/esp/esp-idf/components/newlib/platform_include -IC:/esp/esp-idf/components/freertos/include -IC:/esp/esp-idf/components/heap/include -IC:/esp/esp-idf/components/log/include -IC:/esp/esp-idf/components/soc/esp32/include -IC:/esp/esp-idf/components/soc/include -IC:/esp/esp-idf/components/esp_rom/include -IC:/esp/esp-idf/components/esp_common/include -IC:/esp/esp-idf/co
mponents/xtensa/include -IC:/esp/esp-idf/components/xtensa/esp32/include -IC:/esp/esp-idf/components/esp32/include -IC:/esp/esp-idf/components/driver/include -IC:/esp/esp-idf/components/esp_ringbuf/include -IC:/esp/esp-idf/components/esp_event/include -IC:/esp/esp-idf/components/tcpip_adapter/include -IC:/esp/esp-idf/components/lwip/include/apps -IC:/esp/esp-idf/components/lwip/include/apps/sntp -IC:/esp/esp-idf/components/lwip/lwip/src/include -IC:/esp/esp-idf/components/lwip/port/esp32/include
 -IC:/esp/esp-idf/components/lwip/port/esp32/include/arch -IC:/esp/esp-idf/components/vfs/include -IC:/esp/esp-idf/components/esp_wifi/include -IC:/esp/esp-idf/components/esp_wifi/esp32/include -IC:/esp/esp-idf/components/esp_eth/include -IC:/esp/esp-idf/components/efuse/include -IC:/esp/esp-idf/components/efuse/esp32/include -IC:/esp/esp-idf/components/app_trace/include -mlongcalls -Wno-frame-address   -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -nostdlib -Wall -Werror=all -
Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wextra -Wno-unused-parameter -Wno-sign-compare -ggdb -Og -std=gnu99 -Wno-old-style-declaration -D_GNU_SOURCE -DIDF_VER=\"v4.0-dev-1443-g39f090a4f-dirty\" -DGCC_NOT_5_2_0 -DESP_PLATFORM -MD -MT esp-idf/lis3dh/CMakeFiles/__idf_lis3dh.dir/lis3dh.c.obj -MF esp-idf\lis3dh\CMakeFiles\__idf_lis3dh.dir\lis3dh.c.obj.d -o esp-idf/lis3dh/CMakeFiles/__idf_lis3dh.dir/lis3dh.c.obj   -c .
./components/lis3dh/lis3dh.c
In file included from ../components/lis3dh/lis3dh.h:94,
                 from ../components/lis3dh/lis3dh.c:53:
../components/lis3dh/lis3dh_platform.h:52:10: fatal error: esp8266_wrapper.h: No such file or directory
 #include "esp8266_wrapper.h"
          ^~~~~~~~~~~~~~~~~~~
compilation terminated.
For this to work the component "lis3dh" needs to declare that it REQUIRES the component that contains the esp8266_wrapper.h header. Here's an example of how this looks when registering the component in ESP-IDF V4.0:
https://github.com/espressif/esp-idf/bl ... sts.txt#L4

Also, the component that contains esp8266_wrapper.h must have that directory in its INCLUDE_DIRS list so that the build system knows there are headers in there.
gibson12345 wrote:
Tue Aug 27, 2019 11:54 pm

Code: Select all

C:\Users\lachlan\.espressif\tools\xtensa-esp32-elf\esp32-2019r1-8.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-gcc.exe -DHAVE_CONFIG_H -DMBEDTLS_CONFIG_FILE=\"mbedtls/esp_config.h\" -DUNITY_INCLUDE_CONFIG_H -DWITH_POSIX -Iconfig -I../main/. -IC:/esp/esp-idf/components/newlib/platform_include -IC:/esp/esp-idf/components/freertos/include -IC:/esp/esp-idf/components/heap/include -IC:/esp/esp-idf/components/log/include -IC:/esp/esp-idf/components/soc/esp32/include -IC:/esp/esp-idf/components/soc/includ
e -IC:/esp/esp-idf/components/esp_rom/include -IC:/esp/esp-idf/components/esp_common/include -IC:/esp/esp-idf/components/xtensa/include -IC:/esp/esp-idf/components/xtensa/esp32/include -IC:/esp/esp-idf/components/esp32/include -IC:/esp/esp-idf/components/driver/include -IC:/esp/esp-idf/components/esp_ringbuf/include -IC:/esp/esp-idf/components/esp_event/include -IC:/esp/esp-idf/components/tcpip_adapter/include -IC:/esp/esp-idf/components/lwip/include/apps -IC:/esp/esp-idf/components/lwip/include
/apps/sntp -IC:/esp/esp-idf/components/lwip/lwip/src/include -IC:/esp/esp-idf/components/lwip/port/esp32/include -IC:/esp/esp-idf/components/lwip/port/esp32/include/arch -IC:/esp/esp-idf/components/vfs/include -IC:/esp/esp-idf/components/esp_wifi/include -IC:/esp/esp-idf/components/esp_wifi/esp32/include -IC:/esp/esp-idf/components/esp_eth/include -IC:/esp/esp-idf/components/efuse/include -IC:/esp/esp-idf/components/efuse/esp32/include -IC:/esp/esp-idf/components/app_trace/include -IC:/esp/esp-i
df/components/mbedtls/port/include -IC:/esp/esp-idf/components/mbedtls/mbedtls/include -IC:/esp/esp-idf/components/wpa_supplicant/include -IC:/esp/esp-idf/components/wpa_supplicant/port/include -IC:/esp/esp-idf/components/wpa_supplicant/include/esp_supplicant -IC:/esp/esp-idf/components/bootloader_support/include -IC:/esp/esp-idf/components/app_update/include -IC:/esp/esp-idf/components/spi_flash/include -IC:/esp/esp-idf/components/nvs_flash/include -IC:/esp/esp-idf/components/smartconfig_ack/in
clude -IC:/esp/esp-idf/components/pthread/include -IC:/esp/esp-idf/components/espcoredump/include -IC:/esp/esp-idf/components/asio/asio/asio/include -IC:/esp/esp-idf/components/asio/port/include -IC:/esp/esp-idf/components/bt/include -IC:/esp/esp-idf/components/bt/common/osi/include -IC:/esp/esp-idf/components/bt/host/bluedroid/api/include/api -IC:/esp/esp-idf/components/coap/port/include -IC:/esp/esp-idf/components/coap/port/include/coap -IC:/esp/esp-idf/components/coap/libcoap/include -IC:/esp
/esp-idf/components/coap/libcoap/include/coap2 -IC:/esp/esp-idf/components/console/. -IC:/esp/esp-idf/components/nghttp/port/include -IC:/esp/esp-idf/components/nghttp/nghttp2/lib/includes -IC:/esp/esp-idf/components/esp-tls/. -IC:/esp/esp-idf/components/esp-tls/PRIVATE_INCLUDE_DIRS -IC:/esp/esp-idf/components/esp-tls/private_include -IC:/esp/esp-idf/components/esp_adc_cal/include -IC:/esp/esp-idf/components/esp_gdbstub/include -IC:/esp/esp-idf/components/tcp_transport/include -IC:/esp/esp-idf/c
omponents/tcp_transport/PRIVATE_INCLUDE_DIRS -IC:/esp/esp-idf/components/tcp_transport/private_include -IC:/esp/esp-idf/components/esp_http_client/include -IC:/esp/esp-idf/components/esp_http_server/include -IC:/esp/esp-idf/components/esp_https_ota/include -IC:/esp/esp-idf/components/protobuf-c/protobuf-c -IC:/esp/esp-idf/components/protocomm/include/common -IC:/esp/esp-idf/components/protocomm/include/security -IC:/esp/esp-idf/components/protocomm/include/transports -IC:/esp/esp-idf/components/
mdns/include -IC:/esp/esp-idf/components/esp_local_ctrl/include -IC:/esp/esp-idf/components/esp_websocket_client/include -IC:/esp/esp-idf/components/expat/expat/expat/lib -IC:/esp/esp-idf/components/expat/port/include -IC:/esp/esp-idf/components/wear_levelling/include -IC:/esp/esp-idf/components/sdmmc/include -IC:/esp/esp-idf/components/fatfs/diskio -IC:/esp/esp-idf/components/fatfs/vfs -IC:/esp/esp-idf/components/fatfs/src -IC:/esp/esp-idf/components/freemodbus/common/include -IC:/esp/esp-idf/c
omponents/idf_test/include -IC:/esp/esp-idf/components/jsmn/include -IC:/esp/esp-idf/components/json/cJSON -IC:/esp/esp-idf/components/libsodium/libsodium/src/libsodium/include -IC:/esp/esp-idf/components/libsodium/port_include -IC:/esp/esp-idf/components/mqtt/esp-mqtt/include -IC:/esp/esp-idf/components/openssl/include -IC:/esp/esp-idf/components/spiffs/include -IC:/esp/esp-idf/components/ulp/include -IC:/esp/esp-idf/components/unity/include -IC:/esp/esp-idf/components/unity/unity/src -IC:/esp/
esp-idf/components/wifi_provisioning/include -mlongcalls -Wno-frame-address   -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -nostdlib -Wall -Werror=all -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wextra -Wno-unused-parameter -Wno-sign-compare -ggdb -Og -std=gnu99 -Wno-old-style-declaration -D_GNU_SOURCE -DIDF_VER=\"v4.0-dev-1443-g39f090a4f-dirty\" -DGCC_NOT_5_2_0 -DESP_PLATFORM -MD -MT esp-idf/main
/CMakeFiles/__idf_main.dir/accelerometer.c.obj -MF esp-idf\main\CMakeFiles\__idf_main.dir\accelerometer.c.obj.d -o esp-idf/main/CMakeFiles/__idf_main.dir/accelerometer.c.obj   -c ../main/accelerometer.c
In file included from ../main/accelerometer.c:1:
../main/accelerometer.h:6:10: fatal error: lis3dh.h: No such file or directory
 #include "lis3dh.h"
          ^~~~~~~~~~
This one is different because the "main" component automatically sees all the components in the project, so you don't need to give a REQUIRES list for "main" component.

Suggest checking that the component that provides "lis3dh.h" has this directory in its INCLUDE_DIRS list in CMakeLists.txt

If you're still stuck and it's not working, is it possible to give us the full contents of the relevant CMakeLists.txt files?

gibson12345
Posts: 58
Joined: Wed Jul 17, 2019 11:45 pm

Re: CMake include extra components

Postby gibson12345 » Sun Sep 01, 2019 11:23 pm

ESP_Angus wrote:
Fri Aug 30, 2019 7:07 am
Hi Gibson,

Sorry for the delay in getting back to you.
All good I understand you're likely busy especially if you are still having internal CI issues.
ESP_Angus wrote:
Fri Aug 30, 2019 7:07 am
For this to work the component "lis3dh" needs to declare that it REQUIRES the component that contains the esp8266_wrapper.h header. Here's an example of how this looks when registering the component in ESP-IDF V4.0:
https://github.com/espressif/esp-idf/bl ... sts.txt#L4

Also, the component that contains esp8266_wrapper.h must have that directory in its INCLUDE_DIRS list so that the build system knows there are headers in there.
Okay I'm not quite sure I understand that second part fully but here is what my CMakeLists.txt look like now

esp8266 component

Code: Select all

idf_component_register(SRCS "esp8266_wrapper.c"
                       INCLUDE_DIRS "../lis3dh")
lis3dh component

Code: Select all

idf_component_register(SRCS "lis3dh.c"
                       REQUIRES esp8266)
ESP_Angus wrote:
Fri Aug 30, 2019 7:07 am

This one is different because the "main" component automatically sees all the components in the project, so you don't need to give a REQUIRES list for "main" component.

Suggest checking that the component that provides "lis3dh.h" has this directory in its INCLUDE_DIRS list in CMakeLists.txt

If you're still stuck and it's not working, is it possible to give us the full contents of the relevant CMakeLists.txt files?
This one I also don't fully understand but here is my CMakeLists.txt for my main component.

Code: Select all

set(COMPONENT_REQUIRES )
set(COMPONENT_PRIV_REQUIRES )

set(COMPONENT_SRCS  "main.c"
                    "talkiplayer.c"
                    "bluetooth.c"
                    "nfc.c"
                    "soundPlayer.c"
                    "powerManagement.c"
                    "inactivityTimer.c"
                    "accelerometer.c")
set(COMPONENT_ADD_INCLUDEDIRS ".")


register_component()
And just incase you need it here it my top level CMakeLists.txt

Code: Select all

cmake_minimum_required(VERSION 3.5)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)

project(SourceCode)
Thanks a lot for you consistent help :)

Cheers,
Gibson

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: CMake include extra components

Postby ESP_Angus » Mon Sep 02, 2019 1:57 am

Hi Gibson,

I think the problem is here:
esp8266 component

Code: Select all

idf_component_register(SRCS "esp8266_wrapper.c"
                       INCLUDE_DIRS "../lis3dh")
INCLUDE_DIRS should be a list of the public header directories that are part of this component. So if esp8266 component also contains esp8266_wrapper.h then the directory contianing that headers needs to be listed here, not the directory that belongs to the other component.

This way when the lis3dh component says that it "REQUIRES esp8266", the build system says "OK, what header directories does this mean I now include" and see the list of INCLUDE_DIRS from the esp8266 component. Which means that "#include "esp8266_wrapper.h" will work when compiling lis3dh source files.

Does that makes sense?

gibson12345
Posts: 58
Joined: Wed Jul 17, 2019 11:45 pm

Re: CMake include extra components

Postby gibson12345 » Mon Sep 02, 2019 4:22 am

Hey Angus,
ESP_Angus wrote:
Mon Sep 02, 2019 1:57 am
INCLUDE_DIRS should be a list of the public header directories that are part of this component. So if esp8266 component also contains esp8266_wrapper.h then the directory contianing that headers needs to be listed here, not the directory that belongs to the other component.
I'm not quite sure I get what you mean for this but would that mean if all of the header files are self contained inside the component folder the include_dir would just need to be "." ??
ESP_Angus wrote:
Mon Sep 02, 2019 1:57 am
This way when the lis3dh component says that it "REQUIRES esp8266", the build system says "OK, what header directories does this mean I now include" and see the list of INCLUDE_DIRS from the esp8266 component. Which means that "#include "esp8266_wrapper.h" will work when compiling lis3dh source files.

Does that makes sense?
And would this then mean that so my "Main" component recognises the lis3dh.h header I could need to also have an include_dir of "."?

Tbh I'm not quite sure I understand so correct me if I'm wrong about this.

Thanks again for your understanding in teaching me this :)

Cheers,
Gibson

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: CMake include extra components

Postby ESP_Angus » Mon Sep 02, 2019 5:15 am

gibson12345 wrote:
Mon Sep 02, 2019 4:22 am
I'm not quite sure I get what you mean for this but would that mean if all of the header files are self contained inside the component folder the include_dir would just need to be "." ??
Correct!

(Some components have an "include" directory for the public headers and some private headers in "." which is why we don't assume that "." is where the public headers live, the component tells the build system instead.)
gibson12345 wrote:
Mon Sep 02, 2019 4:22 am
And would this then mean that so my "Main" component recognises the lis3dh.h header I could need to also have an include_dir of "."?
An INCLUDE_DIR of "." in the lis3dh.h component? Yes, that's right (if that's where the header lives).

"main" component is special because it is assumed to REQUIRE all the components in the project without needing to specify this (the assumption being this is where you'll initialise all the other components in the project.)

gibson12345
Posts: 58
Joined: Wed Jul 17, 2019 11:45 pm

Re: CMake include extra components

Postby gibson12345 » Mon Sep 02, 2019 5:41 am

ESP_Angus wrote:
Mon Sep 02, 2019 5:15 am
gibson12345 wrote:
Mon Sep 02, 2019 4:22 am
I'm not quite sure I get what you mean for this but would that mean if all of the header files are self contained inside the component folder the include_dir would just need to be "." ??
Correct!

(Some components have an "include" directory for the public headers and some private headers in "." which is why we don't assume that "." is where the public headers live, the component tells the build system instead.)
gibson12345 wrote:
Mon Sep 02, 2019 4:22 am
And would this then mean that so my "Main" component recognises the lis3dh.h header I could need to also have an include_dir of "."?
An INCLUDE_DIR of "." in the lis3dh.h component? Yes, that's right (if that's where the header lives).

"main" component is special because it is assumed to REQUIRE all the components in the project without needing to specify this (the assumption being this is where you'll initialise all the other components in the project.)
Thanks a bunch angus! Managed to get it working after my last post and have been fiddling since. Maybe I'm just unfamiliar and still learning but the documentation on adding components etc in the new build system was a little confusing is there plans to make it a bit more verbose in the future?

Cheers,
Gibson

Who is online

Users browsing this forum: Bing [Bot] and 85 guests