Setting flags/defines for building a library's dependency

I have Project A that I’m currently developing.
Project A has dependency of Library B that I made.
Library B has dependency of Library C that i did not make.

Library C requires a ton of flags being supplied through build_flags in platformio.ini:

-DTFT_SWRST=1
-DTFT_CASET=42
-DTFT_PASET=43
-DTFT_RAMWR=44
-DTFT_RAMRD=46

…And the list goes on. How do I, in Library B, imbed these defines so Project A does not need to know about them? Can I also do that as part of Library B’s platformio.ini? Just supplying them as #define’s in Library B does not work, it’s not picked up by Library C.

Libraries usually don´t have a platformio.ini but a library.json file.
The build flags can be specified in this file like so:

{
  "name": "libraryc",
  "version": "0.0.1",
  "build": {
    "flags": [
      "-DTFT_SWRST=1",
      "-DTFT_CASET=42",
      "-DTFT_PASET=43",
      "-DTFT_RAMWR=44",
      "-DTFT_RAMRD=46"
    ]
  }
}

Take a look at the README in the lib directory.

Thank you for your response, @sivar2311

It doesn’t seem to work as I want it. When added to Library B’s library.json, Library C (which i have no control over) doesn’t see the defines when building.

I’m not sure how the dependency building works - but i would expect it to be something like this:

Building Project A, it will build Library B. As Library C is a dependency of LIbrary B, it will be build with Library B’s build settings.

If i directly copy the build flags from Library B to Project A then everything works as expected - but that was kinda the whole point wrapping it up in LIbrary B in the first place, so that’s no good.

The build flags in library.json only apply locally for the respective library.
The build flags in platformio.ini apply to the entire project.

If it is the task of library B to configure library C, I don’t see a solution.

I think the only way to configure library C is to use the build flags in platformio.ini, which then apply to the entire project.

A working solution is to make library C a part of library B (copy library C into your library B), as follows:

libb
|--src
|  |--libc
|  |  |--src
|  |     |-libc.h
|  |     |-libc.cpp
|  |-libb.h
|  |-libb.cpp
|-library.json

To include library C through library B, use: #include "./libc/src/libc.h".
The settings in the library.json of library B also apply to library C

I checked if I could use extra_scripts and create a python script that does something like this:

Import("env")
for lb in env.GetLibBuilders():
    if (lb.name == "Library C"):
        lb.env.Append(CPPDEFINES=[
            ("MY_DEFINE", 123)
        ])

While the code executes correctly it doesn’t seem to work. Library C is not build with those defines -_-