How to add compiler flags to PlatformIO project

In order to add compiler flags to your PlatformIO project, add the following line to your build config(s) in platformio.ini:

build_flags = -std=gnu++17

You can also use multiple lines:

build_flags =
    -std=gnu++17
    -ffast-math

Full platformio.ini example:

[env:d1_mini]
platform = espressif8266
board = d1_mini
framework = arduino
monitor_speed = 115200
build_flags = -std=gnu++17