diff --git a/CMakeLists.txt b/CMakeLists.txt index ce0d60603..b3eb79440 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,8 +58,11 @@ endif() project(monero) -option (USE_COMPILER_CACHE "Use compiler cache if a usable instance is found (sccache/ccache)" ON) -if (USE_COMPILER_CACHE) +set (COMPILER_CACHE "auto" CACHE STRING "Compiler cache to use: auto, ccache, sccache, or none") +set_property(CACHE COMPILER_CACHE PROPERTY STRINGS auto ccache sccache none) +if (COMPILER_CACHE STREQUAL "none") + message(STATUS "Compiler cache deselected") +elseif (COMPILER_CACHE STREQUAL "auto") find_program(SCCACHE sccache) find_program(CCACHE ccache) if (SCCACHE) @@ -75,8 +78,18 @@ if (USE_COMPILER_CACHE) else() message(STATUS "No compiler cache found") endif() +elseif (COMPILER_CACHE STREQUAL "sccache") + find_program(SCCACHE sccache REQUIRED) + message(STATUS "Using sccache: ${SCCACHE}") + set(CMAKE_C_COMPILER_LAUNCHER "${SCCACHE}") + set(CMAKE_CXX_COMPILER_LAUNCHER "${SCCACHE}") +elseif (COMPILER_CACHE STREQUAL "ccache") + find_program(CCACHE ccache REQUIRED) + message(STATUS "Using ccache: ${CCACHE}") + set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE}") + set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE}") else() - message(STATUS "Compiler cache deselected") + message(FATAL_ERROR "Invalid COMPILER_CACHE value '${COMPILER_CACHE}': expected auto, ccache, sccache, or none") endif() option (USE_COMPILATION_TIME_PROFILER "Use compilation time profiler (for CLang >= 9 only)" OFF) diff --git a/contrib/guix/libexec/build.sh b/contrib/guix/libexec/build.sh index 9688366c8..5c4f58f15 100644 --- a/contrib/guix/libexec/build.sh +++ b/contrib/guix/libexec/build.sh @@ -336,7 +336,7 @@ mkdir -p "$DISTSRC" esac # Turn off unused default options - CMAKEFLAGS+=" -DUSE_COMPILER_CACHE=OFF -DBUILD_DOCUMENTATION=OFF" + CMAKEFLAGS+=" -DCOMPILER_CACHE=none -DBUILD_DOCUMENTATION=OFF" # Configure this DISTSRC for $HOST # shellcheck disable=SC2086 diff --git a/utils/health/clang-build-time-analyzer-run.sh b/utils/health/clang-build-time-analyzer-run.sh index d9a1c92ea..a30e415eb 100755 --- a/utils/health/clang-build-time-analyzer-run.sh +++ b/utils/health/clang-build-time-analyzer-run.sh @@ -56,7 +56,7 @@ mkdir -p "$DIR_BUILD" && cd "$DIR_BUILD" cmake ../.. \ -DCMAKE_C_COMPILER=clang \ -DCMAKE_CXX_COMPILER=clang++ \ --DUSE_COMPILER_CACHE=OFF \ +-DCOMPILER_CACHE=none \ -DUSE_COMPILATION_TIME_PROFILER=ON \ -DBUILD_SHARED_LIBS=ON \ -DBUILD_TESTS=ON diff --git a/utils/health/clang-include-what-you-use-run.sh b/utils/health/clang-include-what-you-use-run.sh index d72e7a773..342d2c98f 100755 --- a/utils/health/clang-include-what-you-use-run.sh +++ b/utils/health/clang-include-what-you-use-run.sh @@ -56,7 +56,7 @@ UWYU_COMMAND="$PROG;-Xiwyu;any;-Xiwyu;iwyu;-Xiwyu;args" # Copy-pasted from the u cmake ../.. \ -DCMAKE_C_COMPILER=clang \ -DCMAKE_CXX_COMPILER=clang++ \ --DUSE_COMPILER_CACHE=ON \ +-DCOMPILER_CACHE=auto \ -DCMAKE_C_INCLUDE_WHAT_YOU_USE="$UWYU_COMMAND" \ -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE="$UWYU_COMMAND" \ -DBUILD_SHARED_LIBS=ON \ diff --git a/utils/health/clang-tidy-run-common.sh b/utils/health/clang-tidy-run-common.sh index 692a1362a..d8c84df24 100755 --- a/utils/health/clang-tidy-run-common.sh +++ b/utils/health/clang-tidy-run-common.sh @@ -45,7 +45,7 @@ function tidy_for_language() { cmake ../.. \ -DCMAKE_C_COMPILER=clang \ -DCMAKE_CXX_COMPILER=clang++ \ - -DUSE_COMPILER_CACHE=ON \ + -DCOMPILER_CACHE=auto \ -DUSE_CLANG_TIDY_${LANG}=ON \ -DBUILD_SHARED_LIBS=ON \ -DBUILD_TESTS=ON