Issue
By checking the timestamp of a sample file out.txt
before and after running configure_file(in.txt out.txt)
, it seems like the last modified date does not change when the new content is the same when the out.txt
file already exist (so when variables are the same).
Is it really true and guaranteed? I can't find about this in CMake documentation.
Solution
Is it really true and guaranteed? I can't find about this in CMake documentation.
You have partly answered your own question here: if it's not documented, it's certainly not guaranteed. Fortunately, it is documented, here: https://cmake.org/cmake/help/latest/command/configure_file.html
If the input file is modified the build system will re-run CMake to re-configure the file and generate the build system again. The generated file is modified and its timestamp updated on subsequent cmake runs only if its content is changed.
Internally, configure_file
writes its output to a temp file and then calls the equivalent of cmake -E copy_if_different
. That is, it does a byte-for-byte comparison and only does the copy (thereby updating timestamps) if there is a difference.
You can see the sources here: https://github.com/Kitware/CMake/blob/f0a2ec12e2743a7be39201e2bc563ab37debd791/Source/cmMakefile.cxx#L3836
Answered By - Alex Reinking Answer Checked By - Senaida (WPSolving Volunteer)