[CMake] avoiding unnecessary rebuilds

Dave Yost Dave at Yost.com
Sat Apr 11 04:16:07 EDT 2015


Seems to me that it would be great if cmake could produce Makefiles that work like the proposal below.

This approach can eliminate a lot of unnecessary downstream rebuilds. It is similar to how I imagine ccache <https://ccache.samba.org/> works, but unlike ccache which is only for compiling C/C++, the approach should work for any kind of target production.

It seems reasonable that cmake could do the work of generating rules to work like this, but it also might be possible that make and ninja could be made to work like this, optionally.

Proposal

For every target foo there will be a foo-stamp timestamp file.

If foo-stamp doesn’t exist or is older than any of foo's dependencies
    # Build foo without clobbering the old foo.
    make-foo > tmpdir/foo
    # See if what we made is different from the existing target.
    If tmpdir/foo ≠ foo, then
        mv -f tmpdir/foo foo
        # foo is now newer than it was and will cause downstream rebuilds.
    else
        rm -f tmpdir/foo
        # This is no longer needed, and foo is still its old self.
    # Prevent make-foo from having to run until a dependency is touched.
    touch foo-stamp

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150411/48c4e955/attachment.html>


More information about the CMake mailing list