Inject a user header file into a library

Is there a good pattern for a user to optionally inject a user header file into my library? This would setup some defines that override default defines and doesn’t require putting these defines into every compilation call. Of course this would only work in source builds and binary builds would not be able to use this feature.

An example is the imgui file imconfig.h. imgui doesn’t use CMake though.

I’m currently using configure_file() and wondering if this is the best approach.

configure_file helps to make the header, but there’s no mechanism to force anything using your library to include it beyond making it a transitive include of your primary headers.

1 Like