Total loss with CMakeLists.txt in project with component

colinives
Posts: 37
Joined: Tue Mar 03, 2020 2:53 pm

Total loss with CMakeLists.txt in project with component

Postby colinives » Tue Mar 16, 2021 3:25 pm

Hi,

I've spent a week trying to get a simple project that works with all the code in one level (all with the main.c) but as soon as I take the display portion (u8g2) out as a component it fails to find the u8g2 library I've cloned into esp-idf/components. Its giving me :

Code: Select all

../components/display/include/u8g2_esp32_hal.h:10:10: fatal error: u8g2.h: No such file or directory
 #include "u8g2.h"
All is well finding the library when all in the same folder - its just when I split it up as recommended into components (with include subdirectories) that all fails

Structure:

main>
-----main.c
-----CMakeLists.txt
components>
----display>
-------test_SSD1306.c //contains reference to <u8g2.h>
-------u8g2_esp32_hal.c
-------CMakeLists.txt
-------include>
----------test_SSD1306.h
----------u8g2_esp32_hal.h //contains reference to #include "u8g2.h"

Cmakelists.txt for the Project

Code: Select all

# The following lines of boilerplate have to be in your project's CMakeLists
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)

# Add RainMaker components and other common application components
#set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/esp-rainmaker/components $ENV{IDF_PATH}/esp-rainmaker/rainmaker_examples/common  ${CMAKE_CURRENT_LIST_DIR}/../esp-rainmaker/components ${CMAKE_CURRENT_LIST_DIR}/../esp-rainmaker/examples/common)

set(PROJECT_VER "2.1")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(switch)
CMakeLists.txt for 'main'

Code: Select all

idf_component_register(SRCS "main.c"
                       INCLUDE_DIRS ".")
CMakeLists.txt for the display component

Code: Select all

idf_component_register(SRCS "display.c" "test_SSD1306.c" "u8g2_esp32_hal.c"
                    INCLUDE_DIRS "include")
and C-CPP Json:

Code: Select all

{
  "configurations": [
    {
      "name": "ESP-IDF",
      "compilerPath": "${default}",
      "cStandard": "c11",
      "cppStandard": "c++17",
      "includePath": [
        "${config:idf.espIdfPath}/components/**",
        "${config:idf.espIdfPathWin}/components/**",
        "${workspaceFolder}/**"
      ],
      "browse": {
        "path": [
          "${config:idf.espIdfPath}/components",
          "${config:idf.espIdfPathWin}/components",
          "${workspaceFolder}"
        ],
        "limitSymbolsToIncludedHeaders": false
      }
    }
  ],
  "version": 4
}

As I said, the complier finds u8g2 when everything is in the same 'main' folder but falls over when its in a component. What the flip and I missing? Please, anyone. Thank you


colinives
Posts: 37
Joined: Tue Mar 03, 2020 2:53 pm

Re: Total loss with CMakeLists.txt in project with component

Postby colinives » Tue Mar 16, 2021 3:59 pm

Thank you for that,

I have read all these but I'm clearly missing what I need to do. I've just tried adding:

Code: Select all

set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/components/u8g2)
to the project CMAkeLists.txt - but without any change. I think what I did misunderstand is that my earlier reading was that all components in esp-idf/components were automatically in the search path but it seems that they are not?

colinives
Posts: 37
Joined: Tue Mar 03, 2020 2:53 pm

Re: Total loss with CMakeLists.txt in project with component

Postby colinives » Tue Mar 16, 2021 4:52 pm

Ok,

so I've added "/Users/colinives/esp/esp-idf/components/u8g2/csrc" into the components CMakelists.txt:

Code: Select all

INCLUDE_DIRS "include" "/Users/colinives/esp/esp-idf/components/u8g2/csrc"
And I'm not getting the "u8g2.h" now found error but instead:

(snippet)

Code: Select all

> Executing task: cmake --build . <

[1/8] Performing build step for 'bootloader'
ninja: no work to do.
[5/6] Linking CXX executable switch.elf
FAILED: switch.elf 
: && /Users/colinives/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/xtensa-esp32-elf-g++ -mlongcalls -Wno-frame-address  CMakeFiles/switch.elf.dir/project_elf_src_esp32.c.obj -o switch.elf  esp-idf/esp_pm/libesp_pm.a  esp-idf/mbedtls/libmbedtls.a  esp-idf/efuse/libefuse.a  esp-idf/bootloader_support/libbootloader_support.a  esp-idf/app_update/libapp_update.a  esp-idf/esp_ipc/libesp_ipc.a  esp-idf/spi_flash/libspi_flash.a  esp-idf/nvs_flash/libnvs_flash.a  esp-idf/pthread/libpthread.a  esp-idf/esp_gdbstub/libesp_gdbstub.a  esp-idf/esp_system/libesp_system.a  esp-idf/esp_rom/libesp_rom.a  esp-idf/hal/libhal.a  esp-idf/vfs/libvfs.a  esp-idf/esp_eth/libesp_eth.a  esp-idf/
I clearly am struggling to understand what is going on so I can sort these things out myself but, for now, time sand frustration are becoming overwhelming!

Thanks in advance for further pointers. It should be simple - what am I missing!

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Total loss with CMakeLists.txt in project with component

Postby WiFive » Tue Mar 16, 2021 6:01 pm

For a component you have to set the REQUIRES and or PRIV_REQUIRES if it depends on another component

zliudr
Posts: 360
Joined: Thu Oct 03, 2019 5:15 am

Re: Total loss with CMakeLists.txt in project with component

Postby zliudr » Thu Mar 18, 2021 9:30 pm

If you find the previous response lacking details to implement, which would be my case just a few weeks ago, this is an example:

Code: Select all

idf_component_register(SRCS "HID.cpp"
                    INCLUDE_DIRS "include"
                    REQUIRES spiffs fatfs nvs_flash
                    PRIV_REQUIRES lwip esp-tls tcp_transport)
Your component requires other components so you want tha in REQUIRES. Make sure you find the exact folder name for that u8g2 component and put it in REQUIRES. The PRIV_REQUIRES is private requires. If your main code doesn't require u8g2, put it in PRIV_REQUIRES.

Who is online

Users browsing this forum: No registered users and 170 guests