Platform dependent dependencies for library

Hi,

I’m trying to write a wrapper around two separate libraries which target their own platforms, atmelavr and teensy. The project works fine if I use a platformio.ini which species different lib_deps for each [env:<platform], but when I try writing a library.json to export these dependencies, this is where it does not go well.

I think my biggest hangup is with the project structure. It seems to me that the project structure is recommended to be different for end user projects and for libraries. For end user projects, it seems that sources/headers should be split into “private” libraries which go in the lib directory, while for libraries everything gets shoved in src. I like the separation of files into the lib directory because it enables me to use the LDF to compile/link the platform dependent sources, rather than filtering for them using src_filter.

However, when I put them in the lib directory, they are not seen by the LDF when exported (in my end user project). I tried making srcDir equal to lib, but then the headers are not found. I could specify includeDir as lib, but that would couple my include paths in the source code with my directory structure in a way that is not desirable.

I could add -I flags for each directory, but at this point we’re straying very far from where I want to be.

So what’s the recommendation? Where do source files go in an exported library?

If you #include "someFileFromYourLibrary" but your library isn’t picked up by the LDF, likely libLDFMode is incorrect. Hard to say without seeing your exact file structure and sources.

DREV-CAN is the parent library. It wraps around two platform specific libraries, which are marked as dependencies in library.json. PedalBox-DREV22 is the end/leaf project, which depends on DREV-CAN.

In PedalBox’s src/main.cpp, it tries to include drev_can.h. It does this successfully, but when drev_can.h tries including can_node_teensy.h, it fails to find the header. That header is in DREV-CAN/lib/drev-can-teensy/can_node_teensy.h.

Then the library.json ought do add DREV-CAN/lib/drev-can-teensy/ to the include path (e.g. via -I<path> commands in build flags), if DREV-CAN is the library folder. Also see extraScript — PlatformIO latest documentation for an alternative / more reactive way.

Still, this structure is weird. The library should not include its sub-libraries, it can just be the abstraction layer without having the sub-library files in them. The sub-library files can then be included by the library as real dependencies (on a whole library). This can also be made platform dependent.

This leads to 404 not found for me.

Oops, the repo was private. It’s public now.

The library should not include its sub-libraries

What do you mean by this? Include as in #include? Include as in lib_deps?

This can also be made platform dependent

Yep, I took advantage of this in DREV-CAN in the library.json :slight_smile:

That reminds me of another question, too - should DREV-CAN (the parent library) be specifying both a library.json and a platformio.ini, or should it be able to infer the platformio.ini from the library.json? If the former, am I just to update both in parallel when I add new libraries?

Thanks, I really appreciate your help (on both threads).