Compile time configuration of a library

I have several #define statements in a library .h file that need to be different for different sketches. But I can't think of a way to change them except by editing the library. I could modify the library so that these configurations are selectable at run-time but this costs significant code and some memory. And I won't need to change them during run-time.

Is there any way to set configuration parameters at compile time in a library without editing the library itself?

Am I being clear?

You could move the #defines to a separate file and #include that in the library. Still need to edit per sketch, but avoids the risk of accidentally changing something else in the library.

That's still just one file that has to be edited each time I compile a different sketch. I want a separate file for each sketch. Is this not possible in Arduinoland?

Is there an #include directive that causes the compiler to search the folder of the current sketch?

jboyton:
That's still just one file that has to be edited each time I compile a different sketch. I want a separate file for each sketch. Is this not possible in Arduinoland?

Is there an #include directive that causes the compiler to search the folder of the current sketch?

couldn't you just have one #define that you put at the top of your sketch

eg. #define sketch_type 5

Then within your first header file you could have

#if sketch_type == 1
//stuff here
#endif

#if sketch_type == 2
//stuff here
#endif

etc...

couldn't you just have one #define that you put at the top of your sketch

No, because the header file included in the sketch would see that #define value defined in the sketch, but when the header file is included in the library, the #define from the sketch is not visible. It's in another compilation unit.

KenF:
couldn't you just have one #define that you put at the top of your sketch

I wish I could. That would be ideal.

What some development environments do is let you define "defines" which then get passed to every compilation unit. For example, Arduino does that by implication when you select a board type, but it doesn't let you supply user-defined defines. Perhaps make a suggestion to them on GitHub?

With verbose compilation enabled I see that the IDE is invoking the compiler with these options:

-DF_CPU=16000000L
-DUSB_VID=null
-DUSB_PID=null
-DARDUINO=105

If I could somehow slip a few of my own in there I think I'd be set.

Make your class a template, then its not compiled until its used in your sketch. ( pass your config parameters using the template ).

What's a template?

edit: "template class", interesting. My C++ is very weak so I have some homework to do now. Thanks.