Replacing ESP-IDF components in CMakeLists

Palonso
Posts: 95
Joined: Tue Sep 24, 2019 8:43 pm

Replacing ESP-IDF components in CMakeLists

Postby Palonso » Wed Jul 28, 2021 2:38 pm

Hi,

I know this topic is widely discussed but most examples I found are done over 'make' and I have my complains on doing them over CMakeLists.

based on: https://docs.espressif.com/projects/esp ... -same-name it says:
Multiple components with the same name

When ESP-IDF is collecting all the components to compile, it will do this in the order specified by COMPONENT_DIRS; by default, this means ESP-IDF’s internal components first (IDF_PATH/components), then any components in directories specified in EXTRA_COMPONENT_DIRS, and finally the project’s components (PROJECT_DIR/components). If two or more of these directories contain component sub-directories with the same name, the component in the last place searched is used. This allows, for example, overriding ESP-IDF components with a modified version by copying that component from the ESP-IDF components directory to the project components directory and then modifying it there. If used in this way, the ESP-IDF directory itself can remain untouched.
Here is the scheme I'm using:

Code: Select all

myProject:
    -build/
    -components/
        -esp_http_client/
            (a modified version of the http_client library)
        -include/
            CustomHeader_1.h
            CustomHeader_2.h
        -src/
            CustomLib_1.c
            CustomLib_2.c
        -CMakeLists.txt (components Cmake list)
    -main/
        main.c
        CMakeLists.txt (main Cmake list)
    -someFiles.*
    -CmakeLists.txt (project Cmake list)
And this is my 'components Cmake list':

Code: Select all

set(srcs "src/file_1.c"
	"src/file_2.c"
        )
        
idf_component_register(SRCS "${srcs}"
                    INCLUDE_DIRS include esp_http_client
                    REQUIRES nvs_flash mqtt json app_update esp_https_ota esp_adc_cal ulp bt)
with these scheme I'm not able of compiling the project since the compiler can't find the custom 'esp_http_client' files, here is the compiler include log:

Code: Select all

-Iconfig 
-I/home/pablo/esp/esp-idf/components/newlib/platform_include 
-I/home/pablo/esp/esp-idf/components/freertos/include 
-I/home/pablo/esp/esp-idf/components/freertos/xtensa/include 
-I/home/pablo/esp/esp-idf/components/heap/include 
-I/home/pablo/esp/esp-idf/components/log/include 
-I/home/pablo/esp/esp-idf/components/lwip/include/apps 
-I/home/pablo/esp/esp-idf/components/lwip/include/apps/sntp 
-I/home/pablo/esp/esp-idf/components/lwip/lwip/src/include 
-I/home/pablo/esp/esp-idf/components/lwip/port/esp32/include 
-I/home/pablo/esp/esp-idf/components/lwip/port/esp32/include/arch 
-I/home/pablo/esp/esp-idf/components/lwip/port/esp32/tcp_isn 
-I/home/pablo/esp/esp-idf/components/soc/src/esp32/. 
-I/home/pablo/esp/esp-idf/components/soc/src/esp32/include 
-I/home/pablo/esp/esp-idf/components/soc/include 
-I/home/pablo/esp/esp-idf/components/esp_rom/include 
-I/home/pablo/esp/esp-idf/components/esp_common/include 
-I/home/pablo/esp/esp-idf/components/esp_system/include 
-I/home/pablo/esp/esp-idf/components/xtensa/include 
-I/home/pablo/esp/esp-idf/components/xtensa/esp32/include 
-I/home/pablo/esp/esp-idf/components/esp32/include 
-I/home/pablo/esp/esp-idf/components/driver/include 
-I/home/pablo/esp/esp-idf/components/driver/esp32/include 
-I/home/pablo/esp/esp-idf/components/esp_ringbuf/include 
-I/home/pablo/esp/esp-idf/components/efuse/include 
-I/home/pablo/esp/esp-idf/components/efuse/esp32/include 
-I/home/pablo/esp/esp-idf/components/espcoredump/include 
-I/home/pablo/esp/esp-idf/components/esp_timer/include 
-I/home/pablo/esp/esp-idf/components/esp_ipc/include 
-I/home/pablo/esp/esp-idf/components/soc/soc/esp32/include 
-I/home/pablo/esp/esp-idf/components/soc/soc/esp32/../include 
-I/home/pablo/esp/esp-idf/components/soc/soc/esp32/private_include 
-I/home/pablo/esp/esp-idf/components/vfs/include 
-I/home/pablo/esp/esp-idf/components/esp_wifi/include 
-I/home/pablo/esp/esp-idf/components/esp_wifi/esp32/include 
-I/home/pablo/esp/esp-idf/components/esp_event/include 
-I/home/pablo/esp/esp-idf/components/esp_netif/include 
-I/home/pablo/esp/esp-idf/components/tcpip_adapter/include 
-I/home/pablo/esp/esp-idf/components/app_trace/include 
-I/home/pablo/esp/esp-idf/components/mbedtls/port/include 
-I/home/pablo/esp/esp-idf/components/mbedtls/mbedtls/include 
-I/home/pablo/esp/esp-idf/components/mbedtls/esp_crt_bundle/include 
-I/home/pablo/esp/esp-idf/components/bootloader_support/include 
-I/home/pablo/esp/esp-idf/components/app_update/include 
-I/home/pablo/esp/esp-idf/components/spi_flash/include 
-I/home/pablo/esp/esp-idf/components/wpa_supplicant/include 
-I/home/pablo/esp/esp-idf/components/wpa_supplicant/port/include 
-I/home/pablo/esp/esp-idf/components/wpa_supplicant/include/esp_supplicant 
-I/home/pablo/esp/esp-idf/components/nvs_flash/include 
-I/home/pablo/esp/esp-idf/components/pthread/include 
-I/home/pablo/esp/esp-idf/components/perfmon/include 
-I/home/pablo/esp/esp-idf/components/asio/asio/asio/include 
-I/home/pablo/esp/esp-idf/components/asio/port/include 
-I/home/pablo/esp/esp-idf/components/bt/include 
-I/home/pablo/esp/esp-idf/components/bt/common/osi/include 
-I/home/pablo/esp/esp-idf/components/bt/host/bluedroid/api/include/api 
-I/home/pablo/esp/esp-idf/components/cbor/port/include 
-I/home/pablo/esp/esp-idf/components/coap/port/include 
-I/home/pablo/esp/esp-idf/components/coap/port/include/coap 
-I/home/pablo/esp/esp-idf/components/coap/libcoap/include 
-I/home/pablo/esp/esp-idf/components/coap/libcoap/include/coap2 
-I/home/pablo/esp/esp-idf/components/console 
-I/home/pablo/esp/esp-idf/components/nghttp/port/include 
-I/home/pablo/esp/esp-idf/components/nghttp/nghttp2/lib/includes 
-I/home/pablo/esp/esp-idf/components/esp-tls 
-I/home/pablo/esp/esp-idf/components/esp_adc_cal/include 
-I/home/pablo/esp/esp-idf/components/esp_gdbstub/include 
-I/home/pablo/esp/esp-idf/components/esp_hid/include 
-I/home/pablo/esp/esp-idf/components/tcp_transport/include 
[b]-I/home/pablo/esp/esp-idf/components/esp_http_client/include [/b]
-I/home/pablo/esp/esp-idf/components/esp_http_server/include 
-I/home/pablo/esp/esp-idf/components/esp_https_ota/include 
-I/home/pablo/esp/esp-idf/components/protobuf-c/protobuf-c 
-I/home/pablo/esp/esp-idf/components/protocomm/include/common 
-I/home/pablo/esp/esp-idf/components/protocomm/include/security 
-I/home/pablo/esp/esp-idf/components/protocomm/include/transports 
-I/home/pablo/esp/esp-idf/components/mdns/include 
-I/home/pablo/esp/esp-idf/components/esp_local_ctrl/include 
-I/home/pablo/esp/esp-idf/components/sdmmc/include 
-I/home/pablo/esp/esp-idf/components/esp_serial_slave_link/include 
-I/home/pablo/esp/esp-idf/components/esp_websocket_client/include 
-I/home/pablo/esp/esp-idf/components/expat/expat/expat/lib 
-I/home/pablo/esp/esp-idf/components/expat/port/include 
-I/home/pablo/esp/esp-idf/components/wear_levelling/include 
-I/home/pablo/esp/esp-idf/components/fatfs/diskio 
-I/home/pablo/esp/esp-idf/components/fatfs/vfs 
-I/home/pablo/esp/esp-idf/components/fatfs/src 
-I/home/pablo/esp/esp-idf/components/freemodbus/common/include 
-I/home/pablo/esp/esp-idf/components/idf_test/include 
-I/home/pablo/esp/esp-idf/components/idf_test/include/esp32 
-I/home/pablo/esp/esp-idf/components/jsmn/include 
-I/home/pablo/esp/esp-idf/components/json/cJSON 
-I/home/pablo/esp/esp-idf/components/libsodium/libsodium/src/libsodium/include 
-I/home/pablo/esp/esp-idf/components/libsodium/port_include 
-I/home/pablo/esp/esp-idf/components/mqtt/esp-mqtt/include 
-I/home/pablo/esp/esp-idf/components/openssl/include 
-I/home/pablo/esp/esp-idf/components/spiffs/include 
-I/home/pablo/esp/esp-idf/components/ulp/include 
-I/home/pablo/esp/esp-idf/components/unity/include 
-I/home/pablo/esp/esp-idf/components/unity/unity/src 
-I/home/pablo/esp/esp-idf/components/wifi_provisioning/include 
-I../components/include 
[b]-I../components/esp_http_client[/b]

In my custom http_client I have:

Code: Select all

#define CUSTOM_ESP_HTTP_CLIENT_H
in wich the the main.c file checks for it:

Code: Select all

#ifndef CUSTOM_ESP_HTTP_CLIENT_H
	#error "Custom HTTP client not defined"
#endif
And my compiler output is:

Code: Select all

../main/main.c:13:3: error: #error "Custom HTTP client not defined"
  #error "Custom HTTP client not defined"
   ^~~~~
[1202/1237] Building C object esp-idf/libsodium/CMakeFiles/__idf_libso...rc/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-ref.c.obj
ninja: build stopped: subcommand failed.
The terminal process "bash '-c', 'cmake --build .'" terminated with exit code: 1.
What's wrong? This should be straightforward..

Best regards,
P

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

Re: Replacing ESP-IDF components in CMakeLists

Postby ESP_igrr » Wed Jul 28, 2021 2:44 pm

I think the structure should look like this:

Code: Select all

- project
  - components
    - esp_http_client
      - CMakeLists.txt
      - (any source files and header directories of esp_http_client)
    - your_custom_component
      - CMakeLists.txt
      - (any source files and header directories of your_custom_component
  - main
    - CMakeLists.txt and source files
  - CMakeLists.txt (for the project)
It looks like you are placing CMakeLists.txt file inside `components` directory. The build system thinks that `components` directory contains some component, and doesn't search it recursively for more components, hence doesn't find esp_http_client.
If you place esp_http_client and your_custom_component at the same level in `components` directory, it should work.

Palonso
Posts: 95
Joined: Tue Sep 24, 2019 8:43 pm

Re: Replacing ESP-IDF components in CMakeLists

Postby Palonso » Wed Jul 28, 2021 5:37 pm

Hi ESP_igrr,

I'm trying to add the custom component and I'm not able to do so. What should the CMakeList.txt be? I try to add new folders with the components, but the compiler doesn't seem to "replace" the one of the IDF with the custom one.

I added:

Code: Select all

#ifndef CUSTOM_ESP_HTTP_CLIENT_H
	#error "custom IDF files needed"
#endif
And the compiler stops in that error.

Who is online

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