From 747f50de987d467c9ca4bbf1a7fa07935955749c Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Wed, 15 May 2024 10:55:10 +0200 Subject: [PATCH] Refactor how CCache is set up * Use RULE_LAUNCH_COMPILE property as you're apparently supposed to * Detect if compiler is already ccache to prevent build failure --- CMakeLists.txt | 9 ++------- cmake/SetupCCache.cmake | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 cmake/SetupCCache.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 57400e36..20e37cfd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,8 @@ include(CheckLibraryExists) include(CMakeDependentOption) include(CheckIPOSupported) +include(SetupCCache) + set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum OS X deployment version") set(CMAKE_C_STANDARD 11) @@ -91,13 +93,6 @@ endif() set(CMAKE_POSITION_INDEPENDENT_CODE ON) -find_program(CCACHE "ccache") -if (CCACHE) - message(STATUS "Using CCache to speed up compilation") - set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE}) - set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE}) -endif() - option(ENABLE_GDBSTUB "Enable GDB stub" ON) if (ENABLE_GDBSTUB) add_definitions(-DGDBSTUB_ENABLED) diff --git a/cmake/SetupCCache.cmake b/cmake/SetupCCache.cmake new file mode 100644 index 00000000..72388bf8 --- /dev/null +++ b/cmake/SetupCCache.cmake @@ -0,0 +1,19 @@ +include(FindPackageMessage) + +find_program(CCACHE "ccache") + +cmake_dependent_option(USE_CCACHE "Use CCache to speed up repeated builds." ON CCACHE OFF) + +if (NOT CCACHE OR NOT USE_CCACHE) + return() +endif() + +# Fedora, and probably also Red Hat-based distros in general, use CCache by default if it's installed on the system. +# We'll try to detect this here, and exit if that's the case. +# Trying to launch ccache with ccache as we'd otherwise do seems to cause build issues. +if (CMAKE_C_COMPILER MATCHES "ccache" OR CMAKE_CXX_COMPILER MATCHES "ccache") + return() +endif() + +find_package_message(CCache "Using CCache to speed up compilation" "${USE_CCACHE}") +set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE}") \ No newline at end of file