How to add compile options to Arduino IDE 1.8.13

To affect all boards, you can add this property to the global platform.txt:
https://arduino.github.io/arduino-cli/latest/platform-specification/#global-platformtxt
So if your Arduino IDE installation is at "C:\Program Files (x86)\Arduino" then the location of the global platform.txt is "C:\Program Files (x86)\Arduino\hardware\platform.txt"

A couple things to note though:

build.extra_flags property is intended for use by the platform developer. What this means is that you may end up overriding important flags with your custom definition. Here's an example:

leonardo.build.extra_flags={build.usb_flags}

and the definition of build.usb_flags here:

build.usb_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}'

So use build.extra_flags cautiously.

From reading the comments in the official platform level platform.txt files:

# This can be overridden in boards.txt
build.extra_flags=

# These can be overridden in platform.local.txt
compiler.c.extra_flags=
compiler.c.elf.extra_flags=
compiler.S.extra_flags=
compiler.cpp.extra_flags=
compiler.ar.extra_flags=
compiler.objcopy.eep.extra_flags=
compiler.elf2hex.extra_flags=

it seems that the compiler.x.extra_flags properties are intended for use by the user (because platform developers have no need for platform.local.txt). So you are better off to use those properties. Unfortunately, some platform developers have unnecessarily used these properties as well. For example:

but it's at least less common than build.extra_flags.

There is some interesting discussion on how this situation might be improved here:

1 Like