# force configure\_file() on variable change

**URL:** https://discourse.cmake.org/t/force-configure-file-on-variable-change/9903
**Category:** Code
**Created:** [January 22, 2024, 7:25pm UTC](https://discourse.cmake.org/t/force-configure-file-on-variable-change/9903 "2024-01-22T19:25:49Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![scivision](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@scivision](https://discourse.cmake.org/u/scivision)
#### Post date: [January 22, 2024, 7:25pm UTC](https://discourse.cmake.org/t/force-configure-file-on-variable-change/9903/1 "2024-01-22T19:25:49Z")

</div>

Is there a way to force `configure_file()` to regenerate the output? I have a big config.h file generated from config.h.in with `#cmakedefine` that “ccmake” users want to regenerate when they change a relevant variable.

Right now, they have to manually delete the build directory and reuse “ccmake”.

An alternative CMake development solution could be add an option in “ccmake” and/or “cmake-gui” to regenerate the cache akin to `cmake --fresh`.

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [January 22, 2024, 8:55pm UTC](https://discourse.cmake.org/t/force-configure-file-on-variable-change/9903/2 "2024-01-22T20:55:34Z")

</div>

Not sure I understand the scenario. If there is a CMake variable being changed, then CMake generation will already be re-occurring. That means `configure_file()` will be called again, so it should automatically be updating the output during that configure run. Note that if the output doesn’t change, the file will be left untouched (i.e. its time stamp will not be updated).

---

<div class="post-metadata">

### Author: ![scivision](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@scivision](https://discourse.cmake.org/u/scivision)
#### Post date: [January 22, 2024, 11:01pm UTC](https://discourse.cmake.org/t/force-configure-file-on-variable-change/9903/3 "2024-01-22T23:01:04Z")

</div>

Okay, I will make a small test case to ensure I’m not just making a mistake or misunderstanding.

---

<div class="post-metadata">

### Author: ![scivision](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@scivision](https://discourse.cmake.org/u/scivision)
#### Post date: [January 23, 2024, 7:59pm UTC](https://discourse.cmake.org/t/force-configure-file-on-variable-change/9903/4 "2024-01-23T19:59:45Z")

</div>

I updated `configure_file()` documentation to make the update criteria clear, thanks [https://gitlab.kitware.com/cmake/cmake/-/merge\_requests/9179](https://gitlab.kitware.com/cmake/cmake/-/merge_requests/9179)
