ESP_IDF cmake configuration for nested/dependency project

I tried to setup an esp-idf project which is fun if you expect the platformio.ini file to handle everything :stuck_out_tongue:.

There is good documentation luckly, but I came across something curious.

Project setup:

| - lib
|    |  - private_lib
|         | - include
|         | - src
|         | - CMakeLists.txt
| - include
| - src
| - CMakeLists.txt

root/CMakeLists.txt

cmake_minimum_required(VERSION 3.5)

include($ENV{IDF_PATH}/tools/cmake/project.cmake) # has squigly lines error, but works fine: "CMake Error at CMakeLists.txt:3 (include):include could not find load file:"
list(APPEND EXTRA_COMPONENT_DIRS src)
list(APPEND EXTRA_COMPONENT_DIRS lib)
project(my-project)

The above setup works fine if I have the content of the private_lib/CMakeLists.txt set to:

cmake_minimum_required(VERSION 3.5)

FILE(GLOB_RECURSE component_sources ${COMPONENT_DIR}/src/*.*)
idf_component_register(SRCS ${component_sources} INCLUDE_DIRS "include")

But if I want to develop that private library in its own root (for tests etc.) this file won’t do (missing project and include call).
I can use git-magic to make this work out of the box for a thirdparty who is gonna use it as a git-submodule for example. But I would love to avoid it if possible.

I tried the following:

cmake_minimum_required(VERSION 3.5) 

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
list(APPEND EXTRA_COMPONENT_DIRS src)
project(my-private-project)

But it throws an error at the include call: “fatal: not a git repository (or any of the parent directories): .git”. Funny thing is, that the private-lib directory is a git repository and itself is contained in an outer git-repository (it is actually a submodule of the outer git-repository).

So I guese that is not the way to fix this, any suggestions on how to do this within a single file (is there some if-else check I can use for example)?

Any feedback is welcome!

The CMakeLists.txt is ignored if you put it in lib/. You mean to write a component.

The squiggly lines do not come from PlatformIO, looks like you’ve installed the ESP-IDF or CMake extension that tries to actually interprete the CMakeLists.txt. PlatformIO’s build system for ESP-IDF works differently, it only exposes the IDF_PATH during runtime when it builds stuff and calls into cmake.

Thanks for the fast reply

I suspected that much. got CMake installed and disabled, but apparently not enough for that :smiley:. It doesn’t mess with anything though, but for completness sake I included it.

Wel it works in the way I described it above. If it wasn’t dependend on ESP-IDF I would do my own thing as described in the included link (CMake has enough documentation for that), but the sub-project actually does use ESP-IDF components itself. How would that work?

Maybe for an re-iteration: how to configure the repository (private_lib in this case) so it can be developed as being the ‘main-component’ while also being able to be embedded / included as dependency for other ‘main-components’ without the third-party having to modify the CMakeLists.txt file?