Multiple sources for multiple environments

Hi all,

I’ve written a nice C/C++ codebase running on Arduino Micro. As my project is growing, I decided to make it run on an ESP8266 too.

Most of the code will be unchanged, but some low-level routines have to be environment-specific (e.g. to configure GPIO and PWM).
So I thought about having some .h files with class definitions in /src, and a pair of .cpp files with the low-level implementations in e.g. /src-arduinomicro and /src-esp8266, one per environment, and have the linker consider only one of those directories. But I haven’t found a way to tell PlatformIO to specify additional source directories for each environment.

The only workaround I’ve found, is to specify additional build flags like -DENV_MICRO and use pairs of #ifdef#endif in each .cpp file that has environment-specific code, but it makes the codebase difficult to read.

So what is the standard way, in PlatformIO, to build specific source files for specific environments?

Thanks & kind regards

You need Redirecting...

1 Like