|
8 | 8 | ON or OFF.
|
9 | 9 | ]]
|
10 | 10 |
|
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) |
46 | 45 |
|
47 | 46 | if (MONGO_USE_CCACHE)
|
48 | 47 | set (CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_EXECUTABLE}")
|
|
0 commit comments