Platformio.ini dynamic build flags

I would like to set a build flag from a dynamic variable like this, but it’s not working (the build flag is ignored). What is the right way to do this?

[settings]
output = A

[env:my_env]
build_flags = -D OUTPUT=${settings.output}

This works, but I prefer the version above since it keeps [settings] simpler.

[settings]
build_flags = -D OUTPUT=A

[env:my_env]
build_flags = ${settings.build_flags}

Interestingly the following also works. Same as my first example, except I include an empty build_flags in the [settings] section.

[settings]
build_flags = 
output = A

[env:my_env]
build_flags = -D OUTPUT=${settings.output}

Hi @solenoid! Sorry for the late reply. I couldn’t reproduce this behavior with that latest PlatformIO v4.3.0, the following config works just fine:

[settings]
build_flags = -D OUTPUT=A

[env:my_env]
build_flags = ${settings.build_flags}
1 Like