How to specify unique compiling options for multiple sketches?

Suppose I have two sketches named sk1 and sk2 and I want to compile them with different compiler options. Is it possible to do this and, if so, how? I know that I can edit the platform.local.txt file to add custom compiler options but this results in global options for ALL sketches so I would need to edit this file every time I compile either sk1 or sk2. What I am seeking is to find out if there is a way to specify compiler options locally for each sketch. One almost ideal solution would be adding a local platform.local.txt file in the same directory as the sketch itself but this would require changes to the Arduino IDE so it would search for the existence of these files during compilation.

I welcome any ideas.

Thanks for your response in advance.

Arduino IDE doesn't support compile options for individual sketches. but it does for boards.
so you could define a custom board based on official board. you could define board for sketch, or set of sketches.
in the sketch you could check with #ifdef if this special board configuration is selected. so you would never upload the sketch with wrong board selected

here is how to define custom boards. GitHub - JAndrassy/my_boards: My Arduino boards custom variants. You can use it as starting point for your boards specialities.

you can then set build.extra_flags for individual boards.
my_board_for_my_cool_project.build.extra_flags=-DMY_BOARD_FOR_MY_COOL_PROJECT -DWIFI_BUFFER_SIZE=1024

1 Like