Skip to content

Commit 237bcf8

Browse files
authored
Do not elide find_package() if MONGO_USE_CCACHE is set (#1031)
* Do not elide find_program() if MONGO_USE_CCACHE is set * Fix undesirable variable expansion in if condition
1 parent f55cc6a commit 237bcf8

File tree

1 file changed

+34
-35
lines changed

1 file changed

+34
-35
lines changed

build/cmake/CCache.cmake

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

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)
11+
find_program (CCACHE_EXECUTABLE ccache)
12+
13+
# Enable ccache for compiling if not already configured.
14+
if (CCACHE_EXECUTABLE AND NOT DEFINED MONGO_USE_CCACHE)
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 AND NOT DEFINED MONGO_USE_CCACHE)
4645

4746
if (MONGO_USE_CCACHE)
4847
set (CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_EXECUTABLE}")

0 commit comments

Comments
 (0)