From 5379a555db696f5a9f17deb75285d12c003c0247 Mon Sep 17 00:00:00 2001 From: "Daniel J. Hofmann" Date: Wed, 30 Sep 2015 19:13:46 +0200 Subject: [PATCH] Use ccache by default if available and a suitable compiler is used. This checks if `ccache` is available, and if so uses it. The user can stil disable it via the ccache env variable, quoting: disable (CCACHE_DISABLE) [boolean] When true, ccache will just call the real compiler, bypassing the cache completely. The default is false. At least Clang required `CCACHE_CPP2`. The user does not have to set up anything, just to install ccache. Of course, things like the cache's max size, its location and so on can be configured. References: - https://ccache.samba.org/manual.html --- CMakeLists.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index eff883b68..21b46ba49 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -409,3 +409,13 @@ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "Generating API documentation with Doxygen" VERBATIM ) endif() + +# prefix compilation with ccache by default if available and on clang or gcc +if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") + find_program(CCACHE_FOUND ccache) + if(CCACHE_FOUND) + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) + set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) + set(ENV{CCACHE_CPP2} "true") + endif() +endif()