# Inject a user header file into a library

**URL:** <https://discourse.cmake.org/t/inject-a-user-header-file-into-a-library/9724>\
**Category:** Code\
**Created:** [December 26, 2023, 6:50pm UTC](https://discourse.cmake.org/t/inject-a-user-header-file-into-a-library/9724 "2023-12-26T18:50:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![erincatto](https://discourse.cmake.org/user_avatar/discourse.cmake.org/erincatto/32/4119_2.png) [@erincatto](https://discourse.cmake.org/u/erincatto)\
**Post date:** [December 26, 2023, 6:50pm UTC](https://discourse.cmake.org/t/inject-a-user-header-file-into-a-library/9724/1 "2023-12-26T18:50:31Z")

</div>

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.

> <https://github.com/ocornut/imgui/blob/master/imconfig.h>

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

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [December 26, 2023, 7:04pm UTC](https://discourse.cmake.org/t/inject-a-user-header-file-into-a-library/9724/2 "2023-12-26T19:04:01Z")

</div>

`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.
