[ccache] Speeding up builds with clang-tidy, clang-analyzer and iwyu

Joel Rosdahl joel at rosdahl.net
Fri Aug 14 18:30:59 UTC 2020

On Fri, 14 Aug 2020 at 08:39, Christian Ledergerber
<christian.ledergerber at ecorobotix.com> wrote:
> I have created the following issue for cmake to launch the discussion:
> https://gitlab.kitware.com/cmake/cmake/-/issues/21092

When you described your idea I didn't think you meant making changes
for incorporation in the upstream CMake software but to some local
CMake version. I think that it will be hard to implement it in a
generic enough way for CMake since

1. The solution will require a specific ccache version to work at all.
2. The method of using ccache to probe whether clang-tidy should be
run won't work for users who don't use warnings-as-errors. Also, how
would CMake know that warnings-as-errors is used? It could be part of
WarningsAsErrors in the config file or it could be on the command line
but only for some warnings, etc. Sounds brittle and complex.
3. The method is also brittle since the clang-tidy step will be
skipped if the source is built (and therefore cached) by a normal
non-clang-tidy build.

(But if you apply your changes to a local CMake version you can make
any assumptions you want, of course.)

I spontaneously think that it would be a better idea to either (a)
stop running clang-tidy for a normal build and instead run it as a
special build once in a while, or (b) improve
https://github.com/ejfitzgerald/clang-tidy-cache if you find it
deficient in some way (I know nothing about it), or (c) implement
clang-tidy support in ccache or another compiler cache program.

Just a comment on your CMake GitLab issue:

> 2. Add Class.clang-tidy to configuration of extra_files_to_hash of ccache using the command line syntax: --set-config=KEY=VALUE see https://ccache.dev/manual/latest.html

That's not a good idea. --set-config is just a convenience alternative
to manually editing the ccache configuration file. If you run it once
for each compilation you will have race conditions between invocations
and you will mess up the user's ccache configuration. To enable some
ccache setting for a specific compilation you should set the
corresponding environment variable, i.e. CCACHE_EXTRAFILES in this

-- Joel

More information about the ccache mailing list