Skip to content

Commit 0648bef

Browse files
Detect old CCache to prevent spurious failures (#1105)
1 parent 7652c6c commit 0648bef

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

build/cmake/CCache.cmake

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,44 @@
11
#[[
2-
This module enables CCache support by inserting a ccache executable as
2+
This module enables Ccache support by inserting a ccache executable as
33
the compiler launcher for C and C++ if there is a ccache executable availbale
44
on the system.
55
6-
CCache support will be automatically enabled if it is found on the system.
7-
CCache can be forced on or off by setting the MONGO_USE_CCACHE CMake option to
6+
Ccache support will be automatically enabled if it is found on the system.
7+
Ccache can be forced on or off by setting the MONGO_USE_CCACHE CMake option to
88
ON or OFF.
99
]]
1010

1111
# Find and enable ccache for compiling
1212
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)
13+
14+
if (CCACHE_EXECUTABLE AND NOT DEFINED MONGO_USE_CCACHE)
15+
message (STATUS "Found Ccache: ${CCACHE_EXECUTABLE}")
16+
execute_process(
17+
COMMAND "${CCACHE_EXECUTABLE}" --version
18+
OUTPUT_VARIABLE _out
19+
OUTPUT_STRIP_TRAILING_WHITESPACE
20+
)
21+
set (_enable TRUE)
22+
# Avoid spurious "ccache.conf: No such file or directory" errors due to
23+
# ccache being invoked in parallel, which was patched in ccache version 3.4.3.
24+
if (_out MATCHES "^ccache version ([0-9]+\\.[0-9]+\\.[0-9]+)")
25+
set (_version "${CMAKE_MATCH_1}")
26+
message (STATUS "Detected Ccache version: ${_version}")
27+
if (_version VERSION_LESS "3.4.3")
28+
message (STATUS "Not using Ccache: Detected Ccache version ${_version} "
29+
"is less than 3.4.3, which may lead to spurious failures "
30+
"when run in parallel. See https://github.com/ccache/ccache/issues/260 "
31+
"for more information.")
32+
set (_enable FALSE)
33+
endif ()
34+
else ()
35+
message (STATUS "Note: Unable to automatically detect Ccache from from output: [[${_out}]]")
36+
endif ()
37+
option (MONGO_USE_CCACHE "Use Ccache when compiling" "${_enable}")
1638
endif ()
1739

1840
if (MONGO_USE_CCACHE)
19-
message (STATUS "Compiling with CCache enabled. Disable by setting MONGO_USE_CCACHE to OFF")
41+
message (STATUS "Compiling with Ccache enabled. Disable by setting MONGO_USE_CCACHE to OFF")
2042
set (CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_EXECUTABLE}")
2143
set (CMAKE_C_COMPILER_LAUNCHER "${CCACHE_EXECUTABLE}")
2244
endif ()

0 commit comments

Comments
 (0)