To build ccache you need:
- CMake 3.15 or newer.
- A C++17 compiler. See Supported platforms, compilers and languages for details.
- A C99 compiler.
- Various software libraries, see Dependencies below.
Optional:
- GNU Bourne Again SHell (bash) for tests.
- Asciidoctor to build the HTML documentation.
- Python to debug and run the performance test suite.
See also CI configurations for regularly tested build setups, including cross-compilation and dependencies required in Debian/Ubuntu environments.
The CMake variable DEPS
can be set to select how software library dependencies
should be located or retrieved:
AUTO
(the default): Use dependencies from the local system if available. Otherwise: Use bundled dependencies if available. Otherwise: Download dependencies from the internet (dependencies will then be linked statically).DOWNLOAD
: Use bundled dependencies if available. Otherwise: Download dependencies from the internet (dependencies will then be linked statically).LOCAL
: Use dependencies from the local system if available. Otherwise: Use bundled dependencies if available.
- BLAKE31
- cpp-httplib1
- doctest2 (optional, disable with
-D ENABLE_TESTING=OFF
) - fmt2
- hiredis2 (optional, disable with
-D REDIS_STORAGE_BACKEND=OFF
) - span-lite1
- tl-expected1
- xxhash2
- Zstandard2
- To make CMake search for libraries in a custom location, use
-D CMAKE_PREFIX_PATH=/some/custom/path
. - To link libraries statically, pass
-D STATIC_LINK=ON
to CMake (this is the default on Windows). Alternatively, use-D EXAMPLE_LIBRARY=/path/to/libexample.a
to link statically with libexample.
Here is a typical way to build and install ccache:
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release ..
make
make install
You can set the installation directory to e.g. /usr
by adding -D CMAKE_INSTALL_PREFIX=/usr
to the CMake command. You can set the directory where
the system configuration file should be located to e.g. /etc
by adding -D CMAKE_INSTALL_SYSCONFDIR=/etc
.
There are two different ways to use ccache to cache a compilation:
-
Prefix your compilation command with
ccache
. This method is most convenient if you just want to try out ccache or wish to use it for some specific projects. -
Let ccache masquerade as the compiler. This method is most useful when you wish to use ccache for all your compilations. To do this, create a symbolic link to ccache named as the compiler. For example, here is how to set up ccache to masquerade as
gcc
andg++
:cp ccache /usr/local/bin/ ln -s ccache /usr/local/bin/gcc ln -s ccache /usr/local/bin/g++
On platforms that don't support symbolic links you can simply copy ccache to the compiler name instead for a similar effect:
cp ccache /usr/local/bin/gcc cp ccache /usr/local/bin/g++
And so forth. This will work as long as the directory with symbolic links or ccache copies comes before the directory with the compiler (typically
/usr/bin
) inPATH
.