Shared code and cross-platform stubs in IDF CMake API v4.0
Posted: Thu Oct 10, 2019 7:33 am
Hi,
I've built a project based on the idf_as_lib example project and want to take it further:
1. support shared code that can target both ESP32 and 'HOST', as it's not platform specific
2. allow the shared code to reside outside the source tree (i.e. $PROJECT_SOURCE_DIR/../shared/...)
3. in addition, some shared code in #1 may have ESP32 dependencies, but when compiling for HOST it should use 'stubs' (for testing)
I've gotten part way but have seem to hit a wall.
Using the IDF CMake API I was able to do #2 (until I tried to compile for HOST) and I'm not seeing a way todo #1
To resolve the issue with #2 for HOST it looks like I need to duplicate IDF CMake API and native CMake, e.g. in my testing $PROJECT_SOURCE_DIR/../shared/utils/CMakeLists.txt contains :
Which works for the ESP32 build but when I go todo the HOST build it looks like I'm going to have to go some way to create a 'HOST' based IDF CMakeAPI, or some such similar helpers, as CMake complains "specifying an out-of-tree source a binary directory must be explicitly specified"
I've not tackled #3 yet.
It's increasingly looking like I'm going to have to go 'native' CMake and re-implement/re-use parts of the IDF Make API in the process, something I wish to avoid.
Thanks in advance for any help!
I've built a project based on the idf_as_lib example project and want to take it further:
1. support shared code that can target both ESP32 and 'HOST', as it's not platform specific
2. allow the shared code to reside outside the source tree (i.e. $PROJECT_SOURCE_DIR/../shared/...)
3. in addition, some shared code in #1 may have ESP32 dependencies, but when compiling for HOST it should use 'stubs' (for testing)
I've gotten part way but have seem to hit a wall.
Using the IDF CMake API I was able to do #2 (until I tried to compile for HOST) and I'm not seeing a way todo #1
To resolve the issue with #2 for HOST it looks like I need to duplicate IDF CMake API and native CMake, e.g. in my testing $PROJECT_SOURCE_DIR/../shared/utils/CMakeLists.txt contains :
Code: Select all
if("${TARGET}" STREQUAL "esp32")
idf_component_register(INCLUDE_DIRS include)
else()
add_library(shared_utils INTERFACE)
target_include_directories(shared_utils INTERFACE .)
add_library(shared::utils ALIAS shared_utils)
endif()
Which works for the ESP32 build but when I go todo the HOST build it looks like I'm going to have to go some way to create a 'HOST' based IDF CMakeAPI, or some such similar helpers, as CMake complains "specifying an out-of-tree source a binary directory must be explicitly specified"
I've not tackled #3 yet.
It's increasingly looking like I'm going to have to go 'native' CMake and re-implement/re-use parts of the IDF Make API in the process, something I wish to avoid.
Thanks in advance for any help!