Skip to content

CMake: Use configure_file() to ensure noop incremental builds

Daan De Meyer requested to merge daandemeyer/ktexteditor:noop-incremental into master

Currently, script.qrc is re-generated every time CMake is rerun. Because the previous file is always removed, all rules depending on script.qrc are always rerun. By writing to a temporary file and using configure_file() to copy to the final location, we avoid unnecessary rebuilds as configure_file() will only touch the final file if it's contents differ from the input file. As a result, the timestamp of the file is not updated and the rules depending on it are not unnecessarily rebuilt.

Before:

[root@mkosi-abd8b2cdeabd4100bb6ac0239afe761e ktexteditor]# cmake . &> /dev/null
[root@mkosi-abd8b2cdeabd4100bb6ac0239afe761e ktexteditor]# ninja
[0/2] Re-checking globbed directories...
[9/9] Creating library symlink bin/libKF5TextEditor.so.5 bin/libKF5TextEditor.so
[root@mkosi-abd8b2cdeabd4100bb6ac0239afe761e ktexteditor]#

After:

[root@mkosi-abd8b2cdeabd4100bb6ac0239afe761e ktexteditor]# cmake . &> /dev/null
[root@mkosi-abd8b2cdeabd4100bb6ac0239afe761e ktexteditor]# ninja
[0/2] Re-checking globbed directories...
ninja: no work to do.
[root@mkosi-abd8b2cdeabd4100bb6ac0239afe761e ktexteditor]#

When the minimum CMake version is raised above 3.18, we can use file(CONFIGURE) instead of writing to a temporary file.

Merge request reports