|
1 | 1 | #[[
|
2 |
| - This module enables CCache support by inserting a ccache executable as |
| 2 | + This module enables Ccache support by inserting a ccache executable as |
3 | 3 | the compiler launcher for C and C++ if there is a ccache executable availbale
|
4 | 4 | on the system.
|
5 | 5 |
|
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 |
8 | 8 | ON or OFF.
|
9 | 9 | ]]
|
10 | 10 |
|
11 | 11 | # Find and enable ccache for compiling
|
12 | 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) |
| 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}") |
16 | 38 | endif ()
|
17 | 39 |
|
18 | 40 | 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") |
20 | 42 | set (CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_EXECUTABLE}")
|
21 | 43 | set (CMAKE_C_COMPILER_LAUNCHER "${CCACHE_EXECUTABLE}")
|
22 | 44 | endif ()
|
0 commit comments