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()