Adding source folder to project

cskilbeck
Posts: 11
Joined: Tue Dec 10, 2019 10:40 pm

Adding source folder to project

Postby cskilbeck » Sat Jul 15, 2023 11:20 am

I am trying to add a component ('common') to my project ('esp_project') which is in a folder outside the project folder. I have this folder structure:

Code: Select all

esp_project/
    main/
common/
The file esp_project/CMakeFiles.txt contains this

Code: Select all

cmake_minimum_required(VERSION 3.5)
set(EXTRA_COMPONENT_DIRS ../common)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(esp_project)
The file common/CMakeFiles.txt contains this

Code: Select all

idf_component_register(
    SRCS "crc.cpp"
    INCLUDE_DIRS ".")
But the 'common' component is not compiled or linked. Can anyone tell me what I am doing wrong?

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

Re: Adding source folder to project

Postby ESP_igrr » Sun Jul 16, 2023 7:40 am

As far as including the component in the build, what you have done should work.
Could you please check two things:

1) Run "idf.py reconfigure" and see if "common" is in the list of components being built. (There will be one line logged by CMake with the list of all components.) If "common" is not on the list, could you check if there are any warnings about a component not being found in one of that directory?

2) Does esp_project/main/CMakeLists.txt declare the dependency on "common"? (Or simply idf_component_register without REQUIRES/PRIV_REQUIRES)?

cskilbeck
Posts: 11
Joined: Tue Dec 10, 2019 10:40 pm

Re: Adding source folder to project

Postby cskilbeck » Tue Jul 18, 2023 9:04 am

idf.py reconfigure doesn't list the `common` component and gives no warnings

CMakeLists.txt doesn't declare a dependency on `common`

Is it a supported scenario to have a component that exists outside the project folder? If so, can you explain the recommended way to make it happen?

I'm using cmake version 3.16.3

This is the output from `idf.py reconfigure`

Thanks for your help,
Charlie.

Code: Select all

chs@loft-pc:/mnt/u/dev/distance_sensor/firmware/esp8266$ python ~/esp/ESP8266_RTOS_SDK/tools/idf.py reconfigure
Checking Python dependencies...
Python requirements from /home/chs/esp/ESP8266_RTOS_SDK/requirements.txt are satisfied.
Executing action: reconfigure
Running cmake in directory /mnt/u/dev/distance_sensor/firmware/esp8266/build
Executing "cmake -G 'Unix Makefiles' -DPYTHON_DEPS_CHECKED=1 -DESP_PLATFORM=1 -DCCACHE_ENABLE=0 /mnt/u/dev/distance_sensor/firmware/esp8266"...
-- Found Git: /usr/bin/git (found version "2.25.1")
-- IDF_TARGET not set, using default target: esp8266
-- The C compiler identification is GNU 8.4.0
-- The CXX compiler identification is GNU 8.4.0
-- The ASM compiler identification is GNU
-- Found assembler: /home/chs/esp/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc
-- Check for working C compiler: /home/chs/esp/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc
-- Check for working C compiler: /home/chs/esp/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /home/chs/esp/xtensa-lx106-elf/bin/xtensa-lx106-elf-g++
-- Check for working CXX compiler: /home/chs/esp/xtensa-lx106-elf/bin/xtensa-lx106-elf-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Project version: 23dfa87-dirty
-- Building ESP-IDF components for target esp8266
-- Found PythonInterp: /usr/bin/python (found version "2.7.18")
-- Found Perl: /usr/bin/perl (found version "5.30.0")
-- Adding linker script /mnt/u/dev/distance_sensor/firmware/esp8266/build/esp-idf/esp8266/esp8266_out.ld
-- Adding linker script /home/chs/esp/ESP8266_RTOS_SDK/components/esp8266/ld/esp8266.project.ld.in
-- Adding linker script /home/chs/esp/ESP8266_RTOS_SDK/components/esp8266/ld/esp8266.rom.ld
-- Adding linker script /home/chs/esp/ESP8266_RTOS_SDK/components/esp8266/ld/esp8266.peripherals.ld
-- Components: app_update bootloader bootloader_support coap console esp-tls esp-wolfssl esp8266 esp_common esp_event esp_gdbstub esp_http_client esp_http_server esp_https_ota esp_ringbuf esptool_py fatfs freemodbus freertos heap http_parser jsmn json libsodium log lwip main mbedtls mdns mqtt newlib nvs_flash openssl partition_table protobuf-c protocomm pthread spi_flash spi_ram spiffs tcp_transport tcpip_adapter vfs wear_levelling wifi_provisioning wpa_supplicant
-- Component paths: /home/chs/esp/ESP8266_RTOS_SDK/components/app_update /home/chs/esp/ESP8266_RTOS_SDK/components/bootloader /home/chs/esp/ESP8266_RTOS_SDK/components/bootloader_support /home/chs/esp/ESP8266_RTOS_SDK/components/coap /home/chs/esp/ESP8266_RTOS_SDK/components/console /home/chs/esp/ESP8266_RTOS_SDK/components/esp-tls /home/chs/esp/ESP8266_RTOS_SDK/components/esp-wolfssl /home/chs/esp/ESP8266_RTOS_SDK/components/esp8266 /home/chs/esp/ESP8266_RTOS_SDK/components/esp_common /home/chs/esp/ESP8266_RTOS_SDK/components/esp_event /home/chs/esp/ESP8266_RTOS_SDK/components/esp_gdbstub /home/chs/esp/ESP8266_RTOS_SDK/components/esp_http_client /home/chs/esp/ESP8266_RTOS_SDK/components/esp_http_server /home/chs/esp/ESP8266_RTOS_SDK/components/esp_https_ota /home/chs/esp/ESP8266_RTOS_SDK/components/esp_ringbuf /home/chs/esp/ESP8266_RTOS_SDK/components/esptool_py /home/chs/esp/ESP8266_RTOS_SDK/components/fatfs /home/chs/esp/ESP8266_RTOS_SDK/components/freemodbus /home/chs/esp/ESP8266_RTOS_SDK/components/freertos /home/chs/esp/ESP8266_RTOS_SDK/components/heap /home/chs/esp/ESP8266_RTOS_SDK/components/http_parser /home/chs/esp/ESP8266_RTOS_SDK/components/jsmn /home/chs/esp/ESP8266_RTOS_SDK/components/json /home/chs/esp/ESP8266_RTOS_SDK/components/libsodium /home/chs/esp/ESP8266_RTOS_SDK/components/log /home/chs/esp/ESP8266_RTOS_SDK/components/lwip /mnt/u/dev/distance_sensor/firmware/esp8266/main /home/chs/esp/ESP8266_RTOS_SDK/components/mbedtls /home/chs/esp/ESP8266_RTOS_SDK/components/mdns /home/chs/esp/ESP8266_RTOS_SDK/components/mqtt /home/chs/esp/ESP8266_RTOS_SDK/components/newlib /home/chs/esp/ESP8266_RTOS_SDK/components/nvs_flash /home/chs/esp/ESP8266_RTOS_SDK/components/openssl /home/chs/esp/ESP8266_RTOS_SDK/components/partition_table /home/chs/esp/ESP8266_RTOS_SDK/components/protobuf-c /home/chs/esp/ESP8266_RTOS_SDK/components/protocomm /home/chs/esp/ESP8266_RTOS_SDK/components/pthread /home/chs/esp/ESP8266_RTOS_SDK/components/spi_flash /home/chs/esp/ESP8266_RTOS_SDK/components/spi_ram /home/chs/esp/ESP8266_RTOS_SDK/components/spiffs /home/chs/esp/ESP8266_RTOS_SDK/components/tcp_transport /home/chs/esp/ESP8266_RTOS_SDK/components/tcpip_adapter /home/chs/esp/ESP8266_RTOS_SDK/components/vfs /home/chs/esp/ESP8266_RTOS_SDK/components/wear_levelling /home/chs/esp/ESP8266_RTOS_SDK/components/wifi_provisioning /home/chs/esp/ESP8266_RTOS_SDK/components/wpa_supplicant
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/u/dev/distance_sensor/firmware/esp8266/build

MicroController
Posts: 1570
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Adding source folder to project

Postby MicroController » Tue Jul 18, 2023 2:06 pm

Try setting EXTRA_COMPONENT_DIRS to the parent folder of your component folder ("common"). (Or rather move "common" into a "mycomponents" folder and set the latter as a component dir.)
I believe the intention is that an "EXTRA_COMPONENT_DIR", just like "components" in your project or the IDF, contains one sub-folder for each component.

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

Re: Adding source folder to project

Postby ESP_igrr » Tue Jul 18, 2023 2:25 pm

What you are describing (a component in EXTRA_COMPONENT_DIRS outside of the project tree) works in ESP-IDF. Here is a code snippet I have tried in examples/get-started/hello_world/CMakeLists.txt:

Code: Select all

cmake_minimum_required(VERSION 3.16)

set(EXTRA_COMPONENT_DIRS ../../common_components/protocol_examples_common)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(hello_world)
and after "idf.py reconfigure", "protocol_examples_common" is visible in the list of components included into the build.

What I didn't realize why you asked the question is that you aren't using ESP-IDF, but ESP8266_RTOS_SDK. I didn't expect this since this is an esp32.com forum :)

I don't have much experience with ESP8266_RTOS_SDK, but it looks like you can try adding some debugging here:
https://github.com/espressif/ESP8266_RT ... #L144-L147

Code: Select all

        get_filename_component(component_dir "${component_dir}" ABSOLUTE)
        message(STATUS "Considering ${component_dir}/CMakeLists.txt")
        if(EXISTS ${component_dir}/CMakeLists.txt)
            message(STATUS "Found ${component_dir}/CMakeLists.txt, adding it to the build")
            idf_build_component(${component_dir})
        else()
            message(STATUS "Didn't find ${component_dir}/CMakeLists.txt")
            ...
and then run "idf.py reconfigure" again. You should see additional lines in the log, hopefully there will be a mention of "common" component. Based on whether its CMakeLists.txt is found or not, we can continue troubleshooting the issue.

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

Re: Adding source folder to project

Postby ESP_igrr » Tue Jul 18, 2023 2:33 pm

MicroController wrote:
Tue Jul 18, 2023 2:06 pm
Try setting EXTRA_COMPONENT_DIRS to the parent folder of your component folder ("common"). (Or rather move "common" into a "mycomponents" folder and set the latter as a component dir.)
I believe the intention is that an "EXTRA_COMPONENT_DIR", just like "components" in your project or the IDF, contains one sub-folder for each component.
In ESP-IDF, EXTRA_COMPONENT_DIRS can be used to specify either a directory of a single component (without subfolders), or a directory with several components in subfolders.
The relevant code which handles this is here:
https://github.com/espressif/esp-idf/bl ... #L310-L314
and the tests are here:
https://github.com/espressif/esp-idf/bl ... ponents.py

One I thing I can think of is that perhaps in the ESP8266_RTOS_SDK, EXTRA_COMPONENT_DIRS has to be an absolute path? ESP-IDF supports both relative and absolute paths there, but not sure about ESP8266_RTOS_SDK.

Who is online

Users browsing this forum: derricksenva, devlat, khervey and 84 guests