I tried to setup an esp-idf project which is fun if you expect the platformio.ini file to handle everything .
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!