Can I pass variable value from my sketch to the build recipes at compile time?

I'm working on a sketch which includes a version number defined in a variable. I'd like to modify the compiler recipes so that when the sketch is compiled the version number is used in the name of the final hex file, something like project-1.0.1.hex.

So, is it possible to pass a variable value from the sketch to the build options / compiler at compile time?


I don't think there's any way to do that from the sketch.

The closest thing I can think of is you could use boards.txt to add a custom Tools menu.

You should also be able to do it from the command line via --pref if using arduino or -prefs with arduino-builder.