Compiler options in arduino-cli

Hi there,

Please excuse me if this question has been answered before. I have been looking for a way to specify project specific compiler options. I have read the threads where hardware.local.txt and boards.local.txt are discussed, but if I understand correctly, these are all global settings.

As an example, I have a project that needs the following to compile.

arduino-cli compile --build-property compiler.cpp.extra_flags=-fexceptions

It would be nice if the compiler.cpp.extra_flags=-fexceptions settings could be put in a project specific file like sketch.json.

With kind regards,
Jeroen.

There is talk about adding this sort of capability to Arduino CLI, but it is only in the planning stage at this point.

For now, I think your best solution would be to add a build script (or makefile or whatever you like) to the sketch that contains the necessary arduino-cli compile command. That way you don't need to bother with manually adding the right build flags every time you want to compile.

Thank you for the information, I thought about adding a Makefile too, but it is good to hear that I did not miss something obvious.

In case anyone has the same question, I include a reasonably generic Makefile for future reference.

FQBN := arduino:avr:pro
PORT := /dev/ttyUSB0
BUILD := build
FLAGS :=

ARDUINO := arduino-cli

SKETCH := $(wildcard *.ino)
LIBS := $(wildcard *.cpp *.h *.tcc)
HEX := $(BUILD)/$(subst :,.,$(FQBN))/$(addsuffix .hex, $(SKETCH))


all: $(HEX)

$(HEX): $(SKETCH) $(LIBS)
        $(ARDUINO) compile -b $(FQBN) \
    --build-property compiler.cpp.extra_flags="$(FLAGS)" -e

upload: $(HEX)
        $(ARDUINO) upload -b $(FQBN) -p $(PORT) -i $(HEX)