From 84c0470bcbfe1ab84b595d71655e6fb95e7c90bc Mon Sep 17 00:00:00 2001 From: proller Date: Sat, 9 Sep 2017 03:32:34 +0300 Subject: [PATCH] cmake: ccache detect proper version (#1222) --- CMakeLists.txt | 8 ++------ cmake/find_ccache.cmake | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 cmake/find_ccache.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index f3669a53afb..985e5bfc6e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,11 +30,7 @@ cmake_policy (SET CMP0012 NEW) # Don't dereference TRUE and FALSE # Write compile_commands.json set(CMAKE_EXPORT_COMPILE_COMMANDS 1) -find_program (CCACHE_FOUND ccache) -if (CCACHE_FOUND AND NOT CMAKE_CXX_COMPILER_LAUNCHER MATCHES "ccache" AND NOT CMAKE_CXX_COMPILER MATCHES "ccache") - set_property (GLOBAL PROPERTY RULE_LAUNCH_COMPILE "ccache") - set_property (GLOBAL PROPERTY RULE_LAUNCH_LINK "ccache") -endif () +include (cmake/find_ccache.cmake) if (NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "None") message (STATUS "CMAKE_BUILD_TYPE is not set, set to default = RELWITHDEBINFO") @@ -190,7 +186,7 @@ if (UNBUNDLED OR NOT (CMAKE_SYSTEM MATCHES "Linux" OR APPLE) OR ARCH_32) option (NO_WERROR "Disable -Werror compiler option" ON) endif () -message (STATUS "Building for: ${CMAKE_SYSTEM} ${CMAKE_SYSTEM_PROCESSOR} ${CMAKE_LIBRARY_ARCHITECTURE} ; USE_STATIC_LIBRARIES=${USE_STATIC_LIBRARIES} MAKE_STATIC_LIBRARIES=${MAKE_STATIC_LIBRARIES} UNBUNDLED=${UNBUNDLED} CCACHE=${CCACHE_FOUND}") +message (STATUS "Building for: ${CMAKE_SYSTEM} ${CMAKE_SYSTEM_PROCESSOR} ${CMAKE_LIBRARY_ARCHITECTURE} ; USE_STATIC_LIBRARIES=${USE_STATIC_LIBRARIES} MAKE_STATIC_LIBRARIES=${MAKE_STATIC_LIBRARIES} UNBUNDLED=${UNBUNDLED} CCACHE=${CCACHE_FOUND} ${CCACHE_VERSION}") include(GNUInstallDirs) diff --git a/cmake/find_ccache.cmake b/cmake/find_ccache.cmake new file mode 100644 index 00000000000..beb4e306156 --- /dev/null +++ b/cmake/find_ccache.cmake @@ -0,0 +1,15 @@ + +find_program (CCACHE_FOUND ccache) +if (CCACHE_FOUND AND NOT CMAKE_CXX_COMPILER_LAUNCHER MATCHES "ccache" AND NOT CMAKE_CXX_COMPILER MATCHES "ccache") + execute_process(COMMAND ${CCACHE_FOUND} "-V" OUTPUT_VARIABLE CCACHE_VERSION) + string(REGEX REPLACE "ccache version ([0-9\\.]+).*" "\\1" CCACHE_VERSION ${CCACHE_VERSION} ) + string(COMPARE GREATER ${CCACHE_VERSION} "3.2.0" CCACHE_VERSION_OK) + + if (CCACHE_VERSION_OK) + #message(STATUS "Using ${CCACHE_FOUND} ${CCACHE_VERSION}") + set_property (GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_FOUND}) + set_property (GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE_FOUND}) + else () + message(STATUS "Not using ${CCACHE_FOUND} ${CCACHE_VERSION} bug: https://bugzilla.samba.org/show_bug.cgi?id=8118") + endif () +endif ()