[Solved] Link dependent ESP-IDF projects

Completed

I'm testing the waters with CLion (30-day trial) and I'm trying to link several ESP-IDF projects together.

I followed this tutorial; the hello-world project went smoothly and flashed fine.

My firmware consists of a main project containing a ‘main’ src folder and ‘components’ dir with components. The ‘dependent’ projects all contain only a ‘components’ dir with more components (They're shared by multiple main projects). On the command line (with idf.py) this compiles fine.

Somewhat simplified, the directory structure looks like this:

 

The `main-project/CMakeLists.txt` looks like this:

# 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)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mlongcalls -mtext-section-literals")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mlongcalls -mtext-section-literals -Wunused-function -Wunused-variable")

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

set(EXTRA_COMPONENT_DIRS
    "$ENV{UNI_LIB}/components/comm"
    "$ENV{UNI_LIB}/components/drivers"
    "$ENV{UNI_LIB}/components/global"
    "$ENV{UNI_LIB}/components/utils"
    "$ENV{UNI_LIB}/components/wificonn"
    "$ENV{HW_MANAGER}/components/hardwaredriver"
    "$ENV{DEVICE_COMMON}/components/common"
    "$ENV{DEVICE_COMMON}/components/commonbutton"
    "$ENV{DEVICE_COMMON}/components/commonconstants"
    "$ENV{DEVICE_COMMON}/components/commondriver"
    "$ENV{DEVICE_COMMON}/components/commonutil"
    "$ENV{DEVICE_COMMON}/components/hardwaredefinitions"
)

project(main)

I tried following another forum suggestion to add them via add_subdirectory,

add_subdirectory("${CMAKE_SOURCE_DIR}/../uni-lib" "whereisthis")

However this hilariously fails with a “Maximum recursion depth of 1000 exceeded” error.

My goal is to have the directories together in the project side panel and have working code code completion. Building is a lower concern since the “real” build is performed on the command line or in a git worker.

Is this possible?

0
1 comment

Solved.

1. The ‘library’ projects should not contain `include($ENV{IDF_PATH}/tools/cmake/project.cmake)` in their root CMakeLists.txt.

2. For some reason I can't use environment variables, so I changed everything to using relative paths. Now `add_subdirectory` works as expected.

0

Please sign in to leave a comment.