How can a customize a file in Library from Library Registry?

For one of my projects I need to tweak some parameters in a file config.h inside a library, which i loaded from the library registry in PlatformIO. For my other projects i still need the same library as original without the tweaked parameters.

What is the straight forward way in PlatformIO to do this?

Library: LMIC Arduino, Registry ID 852
Need to change something in this file of library

Meanwhile i found this solution:

install complete source code of library in lib/mytweakedlib
deleted library.json in root of library

This way i can tweak the code in lib/mytweakedlib/config.h, but i must copy the complete library for this to local lib folder.

Is there a way that only needs the tweaked config.h locally?

I did not test it but you can try. You need Redirecting...

So, just explain C++ Preprocessor that you would like to define all macros manually.

build_flags =
  -D _lmic_config_h_
  -D CFG_sx1272_radio=1
1 Like

It works! Thank you very much for helping here.

Is it possible to set a #define in this way and prevent it from being redefined? I would like to change a single value in an included library, but it appears that using -D FOO=value is then simply redefined as soon as the preprocessor hits the #define in the library. Unfortunately I can’t use the technique of just defining everything in the header as there is also a class definition in there.

I’d hate to have to fork the whole library just to change a single value that the preprocessor sees, so I’m hoping there’s a way to do this!

Failing that, is there a way to do something like call sed on this file before compilation? Even something hacky like that would work.

You can do that with PRE hook on the specific OBJECT file. See Redirecting...