MantisBT - CMake
View Issue Details
0015354CMakeCMakepublic2015-01-14 18:092015-06-01 08:38
Tom Hughes 
 
normalminoralways
closedno change required 
MacOSX10.10.1
CMake 3.1 
 
0015354: regression: ccache no longer works with cmake 3.1.0
Between cmake 3.0.2 and 3.1.0, ccache (v3.2.1) stopped working (I'm using the ninja generator). I had been using ccache by setting CMAKE_C_COMPILER to ccache and CMAKE_C_COMPILER_ARG1 to clang.

In the original project where I hit this, the error occurs during the first run of cmake when it decides that it needs to re-run configure:

-- Configuring done
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_C_COMPILER= /usr/local/bin/ccache
CMAKE_CXX_COMPILER= /usr/local/bin/ccache
CMAKE_C_COMPILER= /usr/local/bin/ccache
CMAKE_CXX_COMPILER= /usr/local/bin/ccache

-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
-- Check for working C compiler using: Ninja
-- Check for working C compiler using: Ninja -- broken

However, in the simple test case that I created, it doesn't occur until you touch the CMakeLists.txt and re-run ninja (see attachments).
I have a simple test case that reproduces the problem and a script that you can use with "git bisect run" (attached as find-cmake-bug.sh).

That points to the following commit:

commit 6120fca8e229da08fae1d58017962491fb6e03f3
Author: Sylvain Joubert <joubert.sy@gmail.com>
Date: Sat Sep 20 22:37:52 2014 +0200

    Ninja: Prevent compilers to be silently modified

    Unlike with Unix Makefiles generator modifying compiler paths was not
    protected with Ninja generator. It was possible to modify them in the
    cache without the expected effect on the generated solution. Also
    activate corresponding tests with Ninja.
No tags attached.
gz cmake-ccache-bug.tar.gz (859) 2015-01-14 18:09
https://public.kitware.com/Bug/file/5347/cmake-ccache-bug.tar.gz
Issue History
2015-01-14 18:09Tom HughesNew Issue
2015-01-14 18:09Tom HughesFile Added: cmake-ccache-bug.tar.gz
2015-01-15 08:25Brad KingSummaryregression: ccache no longer works with cmake 3.1.2 => regression: ccache no longer works with cmake 3.1.0
2015-01-15 08:25Brad KingDescription Updatedbug_revision_view_page.php?rev_id=1672#r1672
2015-01-15 08:32Brad KingNote Added: 0037696
2015-01-15 08:32Brad KingStatusnew => resolved
2015-01-15 08:32Brad KingResolutionopen => no change required
2015-01-15 13:49Tom HughesNote Added: 0037702
2015-01-15 13:58Brad KingNote Added: 0037703
2015-06-01 08:38Robert MaynardNote Added: 0038853
2015-06-01 08:38Robert MaynardStatusresolved => closed

Notes
(0037696)
Brad King   
2015-01-15 08:32   
From the example:

 $ cat CMakeLists.txt
 set(CMAKE_C_COMPILER_ARG1 "/usr/bin/clang" CACHE INTERNAL "")
 set(CMAKE_C_COMPILER "/usr/local/bin/ccache" CACHE INTERNAL "")
 ...

Setting the compiler like this in CMakeLists.txt is not supported. It should be done on the command-line:

 CC='/usr/local/bin/ccache /usr/bin/clang' cmake .. -GNinja

or:

 cmake .. -GNinja -DCMAKE_C_COMPILER=/usr/local/bin/ccache -DCMAKE_C_COMPILER_ARG1=/usr/bin/clang

Although not officially supported, one can also set it in the CMakeLists.txt file before an explicit project command call:

 $ cat CMakeLists.txt
 cmake_minimum_required(VERSION 3.0)
 set(CMAKE_C_COMPILER_ARG1 "/usr/bin/clang" CACHE INTERNAL "")
 set(CMAKE_C_COMPILER "/usr/local/bin/ccache" CACHE INTERNAL "")
 project(Issue15354 C)
 ...
(0037702)
Tom Hughes   
2015-01-15 13:49   
Thanks. The reason I'm setting those variables in cmake (as opposed to commandline) is that I want to use find_program to find the path for ccache (varies by platform I'm using) and also be able to conditionally enable ccache based on a cmake variable. My project is very complicated (lots of add_subdirectory and includes), so it's hard to ensure that the compiler variable is set before any explicit project command is called (specifically there are platform-specific check_cxx_compiler_flags that don't seem to work without calling project) and it's hard to cleanly refactor those to all be after the compiler setting.

Any plans for somehow officially supporting ccache (i.e., enable/disable it via a cmake variable and have it find it on the platform)? The current method has always seemed like a hack.
(0037703)
Brad King   
2015-01-15 13:58   
Re 0015354:0037702:

> Any plans for somehow officially supporting ccache

I'm not aware of any work or plans for this, but if you want to work on it please join the dev list:

 http://www.cmake.org/mailman/listinfo/cmake-developers [^]

and post there. Likely it will be some optional feature of the Makefile and Ninja generators to insert ccache at the beginning of compilation command lines.
(0038853)
Robert Maynard   
2015-06-01 08:38   
Closing resolved issues that have not been updated in more than 4 months.