tags:

views:

647

answers:

3

I would like to do the following: If CCache is present in PATH, use "ccache g++" for compilation, else use g++. I tried writing a small my-cmake script containing

    CC="ccache gcc" CXX="ccache g++" cmake $*

but it does not seem to work (running make still does not use ccache; I checked this using CMAKE_VERBOSE_MAKEFILE on).

Update:

As per this link I tried changing my script to

     cmake -D CMAKE_CXX_COMPILER="ccache" -D CMAKE_CXX_COMPILER_ARG1="g++" -D CMAKE_C_COMPILER="ccache" -D CMAKE_C_COMPILER_ARG1="gcc" $*

but cmake bails out complaining that a test failed on using the compiler ccache (which can be expected).

+2  A: 

I verified the following works (source: this link):

        CC="gcc" CXX="g++" cmake -D CMAKE_CXX_COMPILER="ccache" -D CMAKE_CXX_COMPILER_ARG1="g++" -D CMAKE_C_COMPILER="ccache" -D CMAKE_C_COMPILER_ARG1="gcc" $*

Update: I later realized that even this does not work. Strangely it works every alternate time (the other times cmake complains).

Amit Kumar
A: 

In my opinion the best way is to symlink gcc,g++ to ccache, but if you would like to use within cmake, try this:

export CC="ccache gcc" CXX="ccache g++" cmake ...
Nadir SOUALEM
+1  A: 

I personally have /usr/lib/ccache in my $PATH. This directory contains loads of symlinks for every possible name the compiler could be called from (like gcc and gcc-4.3), all pointing to ccache.

And I didn't even create the symlinks. That directory comes pre-filled when I install ccache on Debian.

Nicolás
wow, that's almost perfect.
Amit Kumar