CMake - ccache/ccache GitHub Wiki
There are two ways to use ccache with CMake, both described in Run modes in the ccache documentation: you can enable ccache for all compilations by letting ccache masquerade as the compiler, or you can prefix your compilation command with ccache
. The latter can be done by setting CMAKE_<LANG>_COMPILER_LAUNCHER
when running the CMake configuration step.
Example:
$ cmake -D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_CXX_COMPILER_LAUNCHER=ccache ...
In ccache 4.8 and newer, it is possible to pass project-specific configuration options on the command line like this:
$ ccache [KEY=VALUE …] compiler [compiler options]
For instance, to set namespace = myproject
and sloppiness = time_macros
, ccache can be invoked like this:
$ ccache namespace=myproject sloppiness=time_macros gcc ...
With CMake this can be accomplished by adding the configuration options separated by semicolons.
Example:
$ cmake -D CMAKE_CXX_COMPILER_LAUNCHER='ccache;namespace=myproject;sloppiness=time_macros' ...
CMAKE_<LANG>_COMPILER_LAUNCHER
can also be set as a variable inside a CMake script if you want to keep project-specific ccache settings there.
Note that ccache settings that are not specific to the project but to your personal preferences or the system are better specified in ccache's own configuration file or by CCACHE_*
environment variables.