Skip to content

Disable ccache by default for versions older than 3.4.3 #1029

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 35 additions & 7 deletions build/cmake/CCache.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,43 @@
ON or OFF.
]]

# Find and enable ccache for compiling
find_program (CCACHE_EXECUTABLE ccache)
if (CCACHE_EXECUTABLE)
message (STATUS "Found ccache: ${CCACHE_EXECUTABLE}")
option (MONGO_USE_CCACHE "Use CCache when compiling" ON)
endif ()
# Find and enable ccache for compiling if not already found.
if (NOT DEFINED MONGO_USE_CCACHE)
find_program (CCACHE_EXECUTABLE ccache)
if (CCACHE_EXECUTABLE)
Comment on lines +12 to +14
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The find_program needs to occur in case that USE_CCACHE is TRUE before CCACHE_EXECUTABLE has been set. The find_program() call is already cache-aware and will be a no-op if the variable is already set to a truth-y value (i.e. has already been set or successfully found).

Suggested change
if (NOT DEFINED MONGO_USE_CCACHE)
find_program (CCACHE_EXECUTABLE ccache)
if (CCACHE_EXECUTABLE)
if (CCACHE_EXECUTABLE AND NOT DEFINED MONGO_USE_CCACHE)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, my mistake. Followup in #1031.

message (STATUS "Found ccache: ${CCACHE_EXECUTABLE}")

execute_process (
COMMAND ${CCACHE_EXECUTABLE} --version | perl -ne "print $1 if /^ccache version (.+)$/"
OUTPUT_VARIABLE CCACHE_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# Assume `ccache --version` mentions a simple version string, e.g. "1.2.3".
# Permit patch number to be omitted, e.g. "1.2".
set (SIMPLE_SEMVER_REGEX "([0-9]+)\.([0-9]+)(\.([0-9]+))?")
string (REGEX MATCH "${SIMPLE_SEMVER_REGEX}" CCACHE_VERSION ${CCACHE_VERSION})

if (CCACHE_VERSION)
message (STATUS "Detected ccache version: ${CCACHE_VERSION}")
else ()
message (WARNING "Could not obtain ccache version from `ccache --version`. Defaulting to 0.1.0.")
set (CCACHE_VERSION 0.1.0)
endif ()

# 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.
if (${CCACHE_VERSION} VERSION_LESS 3.4.3)
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.")
message (STATUS "Compiling with CCache disabled. Enable by setting MONGO_USE_CCACHE to ON")
option (MONGO_USE_CCACHE "Use CCache when compiling" OFF)
else ()
message (STATUS "Compiling with CCache enabled. Disable by setting MONGO_USE_CCACHE to OFF")
option (MONGO_USE_CCACHE "Use CCache when compiling" ON)
endif ()
endif (CCACHE_EXECUTABLE)
endif (NOT DEFINED MONGO_USE_CCACHE)
Comment on lines +44 to +45
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
endif (CCACHE_EXECUTABLE)
endif (NOT DEFINED MONGO_USE_CCACHE)
endif ()

(To match the other suggestion)


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