Greetings!
I've developed a few libraries that I believe could be useful to others, so I'm considering releasing them as free software.
My question concerns user configuration of compile-time options. I use a number of Arduino platforms, from larger Megas to the (ATtiny85-based) Digispark. In some instances, I'm willing to sacrifice functionality in order to squeeze code into a tight space.
Thus, most of my code is organized so that a few flags (implemented as a set of configuration header #define directives), e.g.
/*
* MY_LIB_INCLUDE_SUPER_FUNCTION
* When this is defined, the library will include and use the super functions.
*
* If you don't need it and want to save space, comment out the line below.
*/
#define MY_LIB_INCLUDE_SUPER_FUNCTION
control what is (or isn't) included in the final compiled library.
This works fine for me, but means:
- You must edit the library source to set/unset the defines
- It's annoying to use the same library in multiple sketches, as it's easy to forget config options you've set and you may have to edit the config everytime you switch projects
So my question is: how can we allow users some control over the library (at compile time) from within the sketch.
I've tried simply setting these options within the sketch, prior to the includes, but this fails: the sketch see's the stuff you've switched-on but then fails with undefined reference errors when linking.
If we had an "advanced options" to control the compilation in the Arduino IDE, I could just tell people to set -DSOME_FLAG as an argument to the compiler, but I couldn't find anything like that.
Any ideas how this can be done?
Thanks!
PatD