Skip to content

Commit f55cc6a

Browse files
authored
Disable ccache by default for versions older than 3.4.3 (#1029)
* Disable ccache by default for versions older than 3.4.3 * Guard against redundant ccache detection
1 parent 51ed4c7 commit f55cc6a

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

build/cmake/CCache.cmake

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,43 @@
88
ON or OFF.
99
]]
1010

11-
# Find and enable ccache for compiling
12-
find_program (CCACHE_EXECUTABLE ccache)
13-
if (CCACHE_EXECUTABLE)
14-
message (STATUS "Found ccache: ${CCACHE_EXECUTABLE}")
15-
option (MONGO_USE_CCACHE "Use CCache when compiling" ON)
16-
endif ()
11+
# Find and enable ccache for compiling if not already found.
12+
if (NOT DEFINED MONGO_USE_CCACHE)
13+
find_program (CCACHE_EXECUTABLE ccache)
14+
if (CCACHE_EXECUTABLE)
15+
message (STATUS "Found ccache: ${CCACHE_EXECUTABLE}")
16+
17+
execute_process (
18+
COMMAND ${CCACHE_EXECUTABLE} --version | perl -ne "print $1 if /^ccache version (.+)$/"
19+
OUTPUT_VARIABLE CCACHE_VERSION
20+
OUTPUT_STRIP_TRAILING_WHITESPACE
21+
)
22+
23+
# Assume `ccache --version` mentions a simple version string, e.g. "1.2.3".
24+
# Permit patch number to be omitted, e.g. "1.2".
25+
set (SIMPLE_SEMVER_REGEX "([0-9]+)\.([0-9]+)(\.([0-9]+))?")
26+
string (REGEX MATCH "${SIMPLE_SEMVER_REGEX}" CCACHE_VERSION ${CCACHE_VERSION})
27+
28+
if (CCACHE_VERSION)
29+
message (STATUS "Detected ccache version: ${CCACHE_VERSION}")
30+
else ()
31+
message (WARNING "Could not obtain ccache version from `ccache --version`. Defaulting to 0.1.0.")
32+
set (CCACHE_VERSION 0.1.0)
33+
endif ()
34+
35+
# Avoid spurious "ccache.conf: No such file or directory" errors due to ccache being invoked in parallel, which was patched in ccache version 3.4.3.
36+
if (${CCACHE_VERSION} VERSION_LESS 3.4.3)
37+
message (STATUS "Detected ccache version ${CCACHE_VERSION} is less than 3.4.3, which may lead to spurious failures when run in parallel. See https://github.com/ccache/ccache/issues/260 for more information.")
38+
message (STATUS "Compiling with CCache disabled. Enable by setting MONGO_USE_CCACHE to ON")
39+
option (MONGO_USE_CCACHE "Use CCache when compiling" OFF)
40+
else ()
41+
message (STATUS "Compiling with CCache enabled. Disable by setting MONGO_USE_CCACHE to OFF")
42+
option (MONGO_USE_CCACHE "Use CCache when compiling" ON)
43+
endif ()
44+
endif (CCACHE_EXECUTABLE)
45+
endif (NOT DEFINED MONGO_USE_CCACHE)
1746

1847
if (MONGO_USE_CCACHE)
19-
message (STATUS "Compiling with CCache enabled. Disable by setting MONGO_USE_CCACHE to OFF")
2048
set (CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_EXECUTABLE}")
2149
set (CMAKE_C_COMPILER_LAUNCHER "${CCACHE_EXECUTABLE}")
2250
endif ()

0 commit comments

Comments
 (0)