Skip to content
Open
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
58 changes: 26 additions & 32 deletions llvm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -335,48 +335,42 @@ if(LLVM_CCACHE_BUILD)
set(LLVM_CCACHE_PARAMS "CCACHE_CPP2=yes CCACHE_HASHDIR=yes CCACHE_SLOPPINESS=pch_defines,time_macros"
CACHE STRING "Parameters to pass through to ccache")

if(NOT CMAKE_HOST_WIN32)
set(CCACHE_PROGRAM "${LLVM_CCACHE_PARAMS} ${CCACHE_PROGRAM}")
if (LLVM_CCACHE_MAXSIZE)
set(CCACHE_PROGRAM "CCACHE_MAXSIZE=${LLVM_CCACHE_MAXSIZE} ${CCACHE_PROGRAM}")
endif()
if (LLVM_CCACHE_DIR)
set(CCACHE_PROGRAM "CCACHE_DIR=${LLVM_CCACHE_DIR} ${CCACHE_PROGRAM}")
endif()
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_PROGRAM})

if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# ccache with PCH can lead to false-positives when only a macro
# definition changes with non-Clang compilers, because macro definitions
# are not compared in preprocessed mode.
# See: https://github.com/ccache/ccache/issues/1668
if(NOT DEFINED CMAKE_DISABLE_PRECOMPILE_HEADERS)
message(NOTICE "Using ccache with precompiled headers with non-Clang "
if (LLVM_CCACHE_MAXSIZE)
set(LLVM_CCACHE_PARAMS "CCACHE_MAXSIZE=${LLVM_CCACHE_MAXSIZE} ${LLVM_CCACHE_PARAMS}")
endif()
if (LLVM_CCACHE_DIR)
set(LLVM_CCACHE_PARAMS "CCACHE_DIR=${LLVM_CCACHE_DIR} ${LLVM_CCACHE_PARAMS}")
endif()

if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# ccache with PCH can lead to false-positives when only a macro
# definition changes with non-Clang compilers, because macro definitions
# are not compared in preprocessed mode.
# See: https://github.com/ccache/ccache/issues/1668
if(NOT DEFINED CMAKE_DISABLE_PRECOMPILE_HEADERS)
message(NOTICE "Using ccache with precompiled headers with non-Clang "
"compilers is not supported. CMAKE_DISABLE_PRECOMPILE_HEADERS will be set to ON. "
"Pass -DCMAKE_DISABLE_PRECOMPILE_HEADERS=OFF to override this.")
set(CMAKE_DISABLE_PRECOMPILE_HEADERS "ON")
elseif(NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
message(WARNING "Using ccache with precompiled headers with non-Clang "
set(CMAKE_DISABLE_PRECOMPILE_HEADERS "ON")
elseif(NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
message(WARNING "Using ccache with precompiled headers with non-Clang "
"compilers is not supported.")
endif()
endif()
endif()

if (NOT CMAKE_HOST_WIN32)
# On platforms other than Windows pass the arguments as an env var to support older ccache versions
set(CCACHE_PROGRAM "${LLVM_CCACHE_PARAMS} ${CCACHE_PROGRAM}")
else()
# Until a way to reliably configure ccache on Windows is found,
# disable precompiled headers for Windows + ccache builds
if(NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
message(WARNING "Using ccache with precompiled headers on Windows is currently not supported.
CMAKE_DISABLE_PRECOMPILE_HEADERS will be set to ON.")
set(CMAKE_DISABLE_PRECOMPILE_HEADERS "ON")
endif()
if(LLVM_CCACHE_MAXSIZE OR LLVM_CCACHE_DIR OR
NOT LLVM_CCACHE_PARAMS MATCHES "CCACHE_CPP2=yes CCACHE_HASHDIR=yes CCACHE_SLOPPINESS=pch_defines,time_macros")
message(FATAL_ERROR "Ccache configuration through CMake is not supported on Windows. Please use environment variables.")
endif()
# Since ccache 4.8 it is possible to pass options as arguments
set(CCACHE_PROGRAM "${CCACHE_PROGRAM} ${LLVM_CCACHE_PARAMS}")
# RULE_LAUNCH_COMPILE should work with Ninja but currently has issues
# with cmd.exe and some MSVC tools other than cl.exe
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
endif()

set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_PROGRAM})
else()
message(FATAL_ERROR "Unable to find the program ccache. Set LLVM_CCACHE_BUILD to OFF")
endif()
Expand Down
Loading