CMake ≥ 3.20.0 + ccache + CCACHE_BASEDIR + Unix Makefiles generator triggers rebuilds
Thanks for creating CMake!
Summary
Ccache rewrites absolute paths into relative when using the base_dir
(CCACHE_BASEDIR
) feature. This interacts badly with CMake 3.20.0's Unix Makefiles Generator, leading to rebuilds.
How to reproduce
- Have CMake 3.20.0+ and ccache installed on a Linux system.
- Download and unpack cmake-ccache-basedir-problem.tar.gz.
cd cmake-ccache-basedir-problem
./repro
- The script runs
make
two times in a row and the secondmake
unexpectedly rebuilds the targets.
Comments
When running make -d
in build
I notice that Make first checks ../src/lib.c
as expected but then also checks ../../src/lib.c
which doesn't exist, and this apparently triggers a rebuild of src/CMakeFiles/lib.dir/lib.c.o
. ../../src/lib.c
comes from src/CMakeFiles/lib.dir/compiler_depend.make
. With the CCACHE_BASEDIR
line commented out in repro
there is no such entry (not even one with an absolute path) in compiler_depend.make
. I haven't investigated this further, but I suspect that it is a consequence of ccache rewriting absolute paths on the command line to relative, thus implicitly rewriting absolute paths to relative in src/CMakeFiles/lib.dir/lib.c.o.d
.
I guess CMake isn't really at fault here, but I thought that I should report the issue here anyway since more people may stumble on this. Maybe there is an easy enough fix?