Work around LDF not recognizing dynamic include

Hello friends. Really enjoying platformio, got me into serious embedded programming. Decided to split my monolith into libraries, had to find out ways to avoid circular dependencies. Came up with config files approach. Some libraries like SQLite, LittleFS and others have ability to provide config header filename as environment variable (i.e. LFS_CONFIG=lfs_config.h). It uses code similar to:

#ifdef CANOPEN_CONFIG
# define INC_STRINGIFY_(f) #f
# define INC_STRINGIFY(f) INC_STRINGIFY_(f)
# include INC_STRINGIFY(CANOPEN_CONFIG)
#endif

that works nicely for declaring variables. However it doesn’t seem that LDF “sees” includes inside config files. For example, I’d like to define SQLITE_MALLOC macro to use my own malloc function. If I add #include my_alloc.h to a config file, the library wouldn’t compile as it wouldn’t know that it depends on the library that provides my_alloc.h.

I can work around that by adding -Ilib/my_alloc or something to the build flags, but it is not very scalable as I’d have to do that for all possible includes in config files. Since I’m writing a sort of a framework, i don’t want the framework users to deal with that. Additionally, I would need to do this for all dependencies of that library (e.g. if my_alloc depends on multi_heap or something). That quickly gets out of hand.

Question 1: Is there a way to make LDF recognize dynamic includes like this? My hunch is no… but I’d like to make sure.

Question 2: Is there a way to force “global” dependency for all libraries? That wouldn’t be very clean approach, but it would be easy solution.

Question 3: Is there a way to provide/modify library.json or its equivalent for a library from a project at the build time? I guess, I could simply add some code into extra_script.py that physically writes the library.json to each library, but is there a better way?

It seems that conditional scanner only supports #include VARIABLE, but variable has to contain quoted string, which isn’t possible to pass as build flag, as double quotes are removed.

For now I create a pre-build python script that scans a specific directory for json files, and replaces libraries own library.json. This way I can use non-forked github repos of code that is not platformio libraries. And then i can disable LDF for the libraries, as well as handle the issues of dynamically provided config files.