

With this in mind, a recommended structure for the top level CMakeLists.txt file would be to start it like this: cmake_minimum_required(VERSION 2.8) When the property setting is placed before project(), these checks will confirm that the compiler can be launched through ccache and report problems early. This global property should be set as early as possible, ideally before even the project() command is called, since project() performs checking on the compilers to be used. By setting RULE_LAUNCH_COMPILE to our ccache command, compilation is re-routed via ccache and build times decrease when rebuilding previously compiled sources with the same settings and source contents. All other CMake generators simply ignore RULE_LAUNCH_COMPILE and build the project normally.
Using cmake linux generator#
This works for the Unix Makefiles generator with all CMake versions from 2.8.0 onwards and with the Ninja generator for CMake 3.4 and later. When this is not empty, CMake inserts it before the compilation command, essentially wrapping the compiler that would have been run with whatever RULE_LAUNCH_COMPILE contains.

The other aspects discussed here in this section are still relevant though.Ī less well known feature of CMake is the global property called RULE_LAUNCH_COMPILE. Update: Don’t use RULE_LAUNCH_COMPILE as discussed in this section, use the CMAKE_COMPILER_LAUNCHER approach discussed further below in Improved functionality from CMake 3.4 instead. where the developer may not be in control of how/where ccache is installed. Specifically, no symlinks need to be set up for ccache, making it suitable for use in CI systems, etc. The techniques presented do not require any changes to the host system.
Using cmake linux how to#
This article demonstrates how to set up a CMake project to use ccache with Unix Makefiles, Ninja or Xcode generators, with Xcode receiving special attention. This is especially true with Xcode builds. Getting ccache to work with CMake is not overly complicated, but the way to do it is not always obvious. When rebuilding a large project that ccache has mostly compiled before already, the time saving can be significant, even sometimes reducing many minutes down to seconds. It supports GCC or any compiler that looks like GCC (eg clang). object files) and reusing them instead of compiling the source again if it gets a compilation request it has seen before and cached. The ccache tool aims to minimise that pain by caching compilation outputs (i.e. The problem gets worse if the developer frequently switches between branches of their source control system, resulting in source files often changing their contents and/or timestamps. Build times in particular can be a sore point, especially if the development team do not have a great understanding of how to minimise dependencies between source files, headers, etc.
Using cmake linux code#
Working with very large C/C++ code bases will sometimes test your patience.
