# rerunning configure\_file when the input file changes.

**URL:** <https://discourse.cmake.org/t/rerunning-configure-file-when-the-input-file-changes/5191>\
**Category:** Code\
**Created:** [March 9, 2022, 12:18am UTC](https://discourse.cmake.org/t/rerunning-configure-file-when-the-input-file-changes/5191 "2022-03-09T00:18:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ARSanderson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/arsanderson/32/1195_2.png) [@ARSanderson](https://discourse.cmake.org/u/ARSanderson)\
**Post date:** [March 9, 2022, 12:18am UTC](https://discourse.cmake.org/t/rerunning-configure-file-when-the-input-file-changes/5191/1 "2022-03-09T00:18:13Z")

</div>

When cmake runs the first time I am able to generate a file using the following:

> configure\_file(foo.cpp.in foo.cpp)

That works great. But if foo.cpp.in changes I would like foo.cpp to be regenerated. If I touch foo.cpp.in cmake will rerun but foo.cpp is not regenerated.

I was thinking that perhaps a custom command could be used but not sure what the command would be given I want to use configure\_file.

Any pointers??? Thanks.

---

<div class="post-metadata">

**Author:** ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)\
**Post date:** [March 9, 2022, 4:51pm UTC](https://discourse.cmake.org/t/rerunning-configure-file-when-the-input-file-changes/5191/2 "2022-03-09T16:51:43Z")

</div>

Touching the file is not enough to relaunch `configuke_file()` as described in the [documentation](https://cmake.org/cmake/help/latest/command/configure_file.html):

> The generated file is modified and its timestamp updated on subsequent cmake runs only if its content is changed.

---

<div class="post-metadata">

**Author:** ![ARSanderson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/arsanderson/32/1195_2.png) [@ARSanderson](https://discourse.cmake.org/u/ARSanderson)\
**Post date:** [March 9, 2022, 5:06pm UTC](https://discourse.cmake.org/t/rerunning-configure-file-when-the-input-file-changes/5191/3 "2022-03-09T17:06:42Z")

</div>

Thanks for that pointer. I did not see that detail. I modified the file and the new files are generated.

---

<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:** [March 10, 2022, 12:16pm UTC](https://discourse.cmake.org/t/rerunning-configure-file-when-the-input-file-changes/5191/4 "2022-03-10T12:16:26Z")

</div>

In general to handle more advanced cases, like where file1 is read by CMake to configure\_file() for file2, you can use directory property CONFIGURE\_DEPENDS.
