Shared code and cross-platform stubs in IDF CMake API v4.0

MindReader32
Posts: 25
Joined: Mon May 14, 2018 8:33 am

Shared code and cross-platform stubs in IDF CMake API v4.0

Postby MindReader32 » 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 :

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!

MindReader32
Posts: 25
Joined: Mon May 14, 2018 8:33 am

Re: Shared code and cross-platform stubs in IDF CMake API v4.0

Postby MindReader32 » Sun Oct 13, 2019 9:24 am

I've waded thru this (nodding appropriately) "Compatibility between "normal CMake" and ESP-IDF": https://esp32.com/viewtopic.php?f=13&t=7535&start=30

In the process found this: https://github.com/PerMalmberg/IO-Card-G3

Which leads to this: https://github.com/PerMalmberg/Smooth

Which looks awesome on both a build setup and library front, thank you permal !

permal
Posts: 384
Joined: Sun May 14, 2017 5:36 pm

Re: Shared code and cross-platform stubs in IDF CMake API v4.0

Postby permal » Sun Oct 13, 2019 9:33 am

You're welcome :)

Looking forward to you feedback. Smooth isn't perfect but it has worked well for me. Just recently a few others have also started using it so welcome to the club I guess. ;)

Who is online

Users browsing this forum: hetal-mpc and 135 guests