Skip to content

Commit a4425cc

Browse files
NathanielMcVicarsstamenova
authored andcommitted
[ccache] Add Windows support
Windows builds can't receive environment variables on the command line or make use of RULE_LAUNCH_COMPILE with ccache. Reviewed By: stella.stamenova, Ericson2314 Differential Revision: https://reviews.llvm.org/D126575
1 parent 3bb7999 commit a4425cc

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

llvm/CMakeLists.txt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,12 @@ set(LLVM_CCACHE_BUILD OFF CACHE BOOL "Set to ON for a ccache enabled build")
173173
if(LLVM_CCACHE_BUILD)
174174
find_program(CCACHE_PROGRAM ccache)
175175
if(CCACHE_PROGRAM)
176-
set(LLVM_CCACHE_MAXSIZE "" CACHE STRING "Size of ccache")
177-
set(LLVM_CCACHE_DIR "" CACHE STRING "Directory to keep ccached data")
178-
set(LLVM_CCACHE_PARAMS "CCACHE_CPP2=yes CCACHE_HASHDIR=yes"
179-
CACHE STRING "Parameters to pass through to ccache")
176+
set(LLVM_CCACHE_MAXSIZE "" CACHE STRING "Size of ccache")
177+
set(LLVM_CCACHE_DIR "" CACHE STRING "Directory to keep ccached data")
178+
set(LLVM_CCACHE_PARAMS "CCACHE_CPP2=yes CCACHE_HASHDIR=yes"
179+
CACHE STRING "Parameters to pass through to ccache")
180180

181+
if(NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
181182
set(CCACHE_PROGRAM "${LLVM_CCACHE_PARAMS} ${CCACHE_PROGRAM}")
182183
if (LLVM_CCACHE_MAXSIZE)
183184
set(CCACHE_PROGRAM "CCACHE_MAXSIZE=${LLVM_CCACHE_MAXSIZE} ${CCACHE_PROGRAM}")
@@ -186,6 +187,16 @@ if(LLVM_CCACHE_BUILD)
186187
set(CCACHE_PROGRAM "CCACHE_DIR=${LLVM_CCACHE_DIR} ${CCACHE_PROGRAM}")
187188
endif()
188189
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_PROGRAM})
190+
else()
191+
if(LLVM_CCACHE_MAXSIZE OR LLVM_CCACHE_DIR OR
192+
NOT LLVM_CCACHE_PARAMS MATCHES "CCACHE_CPP2=yes CCACHE_HASHDIR=yes")
193+
message(FATAL_ERROR "Ccache configuration through CMake is not supported on Windows. Please use environment variables.")
194+
endif()
195+
# RULE_LAUNCH_COMPILE should work with Ninja but currently has issues
196+
# with cmd.exe and some MSVC tools other than cl.exe
197+
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
198+
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
199+
endif()
189200
else()
190201
message(FATAL_ERROR "Unable to find the program ccache. Set LLVM_CCACHE_BUILD to OFF")
191202
endif()

0 commit comments

Comments
 (0)