Hi permal,
(For benefit of anyone skim reading the replies, this post is about Generic CMake projects including ESP-IDF as a series of libraries, not the other way around.)
- How do I run menuconfig for a project like idf_as_lib to generate my sdkconfig and subsequent sdkconfig.h file?
I can reproduce the menuconfig target failing as well, will fix.
Normal (non-menuconfig) generation of sdkconfig.h happens during the build. Note that if building a project with IDF as a library, CMake needs to invoked with some additional arguments (because this isn't an ESP-IDF project CMakeLists.txt, there is less "magic"). The necessary arguments are shown in the README:
https://github.com/espressif/esp-idf/tr ... is-example
idf.py won't work for generic CMake projects, as it doesn't pass these arguments (and there's no way for idf.py to know how a generic CMake project is structured). Will see if we can make that a clearer error.
- How are include paths for components supposed to be propagated to the higher-level component (e.g. esp-idf/components/esp32/include)?
The idf_import_components() step adds all of the components as libraries to the build and idf_link_components() adds them as dependencies of the target executable.
Similar to any other component library target in CMake, the dependent libraries' public headers are added to the executable's include paths automatically (this is how idf_as_lib project's main.c file can include FreeRTOS headers, etc).
If you have other library subprojects added to the top level CMake project that need to access IDF components' headers, you'll need to import those headers in the same way you would for a normal CMake project which contains multiple static libraries. Calling idf_import_components() and idf_link_components() creates library targets of the form idf_component_COMPONENTNAME for all components, so these targets can be used in other CMake code.
For example, if you have some subdirectory "mylib" that calls add_library(mylib STATIC ...) then you can do something like this:
Code: Select all
add_subdirectory(mylib)
target_link_libraries(${CMAKE_PROJECT_NAME}.elf mylib)
target_include_directories(mylib PRIVATE
$<TARGET_PROPERTY:idf_component_esp32,INCLUDE_DIRECTORIES>)
(The INCLUDE_DIRECTORIES property includes the esp32 component's public directories and all its dependent public header directories.)
Will add some of these details to the documentation.
I'll also see if there's a way we can make an IDF_INCLUDE_DIRECTORIES variable available in the parent CMake project, similar to how this variable can be used when including a CMake subproject into an ESP-IDF project - as I can see that this would make this step a bit simpler. But the above pure CMake approach will work.
EDIT: I misunderstood the role of this variable, generator expressions are probably the easiest method for adding dependencies to external libraries.