Skip to content

CMake: use configure_file() to ensure noop incremental builds

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

Currently, whenever CMake is rerun, config-backends.h is regenerated and it's timestamp is updated which causes some rules to become outdated and rebuilt when building solid again. By writing to an intermediary file and using configure_file() to copy the intermediate file to config-backends.h, we avoid the rebuild because configure_file() will not touch the output file it its contents are the same as the input file. This means the timestamp of config-backends.h does not get updated and all rules depending on it are not rerun.

Before:

[root@mkosi-ced0f074bfe8474dbdb213c10b36cc14 solid]# cmake . &> /dev/null
[root@mkosi-ced0f074bfe8474dbdb213c10b36cc14 solid]# ninja
[3/3] Creating library symlink bin/libKF5Solid.so.5 bin/libKF5Solid.so

After:

[root@mkosi-ced0f074bfe8474dbdb213c10b36cc14 solid]# cmake . &> /dev/null
[root@mkosi-ced0f074bfe8474dbdb213c10b36cc14 solid]# ninja
ninja: no work to do.

In the future, once the minimum CMake version is greater than 3.18, we can replace this with file(CONFIGURE).

Merge request reports