# Is it possible to configure a file at build time?

**URL:** https://discourse.cmake.org/t/is-it-possible-to-configure-a-file-at-build-time/9476
**Category:** Usage
**Created:** [November 21, 2023, 12:16pm UTC](https://discourse.cmake.org/t/is-it-possible-to-configure-a-file-at-build-time/9476 "2023-11-21T12:16:54Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Brian](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/97f17d/32.png) [@Brian](https://discourse.cmake.org/u/Brian)
#### Post date: [November 21, 2023, 12:16pm UTC](https://discourse.cmake.org/t/is-it-possible-to-configure-a-file-at-build-time/9476/1 "2023-11-21T12:16:54Z")

</div>

Hi All,

Is it possible to configure a file at build time?

I want the functionality that `configure_file` provides but I need it to run after another set of files have been generated.

I already have a custom command that generates a set of files. I then need to create another set of files based off a `.in` file.

is it possible to do something like this?

```auto
# run the first add_custom_command
# set some variables based on the content of the generated files
# run add_custom_command again to create another file based of the source controlled wrapper.h.in

add_custom_command(
   OUTPUT wrapper.h
   COMMAND <cmake configure_file feature> wrapper.h.in wrapper.h
   DEPENDS wrapper.in.h

```

---

<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: [November 21, 2023, 1:23pm UTC](https://discourse.cmake.org/t/is-it-possible-to-configure-a-file-at-build-time/9476/2 "2023-11-21T13:23:23Z")

</div>

[This function](https://github.com/Kitware/sprokit/blob/master/conf/sprokit-macro-configure.cmake) I wrote years ago can do what you want. You do need to list all variables you want to be able to use as they’re not otherwise available.

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [November 21, 2023, 1:23pm UTC](https://discourse.cmake.org/t/is-it-possible-to-configure-a-file-at-build-time/9476/3 "2023-11-21T13:23:59Z")

</div>

You can run cmake scripts at build time with the -P command line argument.

If you need variables from cmake configure time in that cmake script, just make it a .cmake.in file and use configure\_file() to prepare it, maybe with @ONLY parameter to not get confused with replaced variables and script-internal variables.
