@@ -271,30 +271,51 @@ set(LLVM_CCACHE_BUILD OFF CACHE BOOL "Set to ON for a ccache enabled build")
271
271
if (LLVM_CCACHE_BUILD)
272
272
find_program (CCACHE_PROGRAM ccache)
273
273
if (CCACHE_PROGRAM)
274
+ # ccache --version example output: "ccache version 4.9.1\n(..)"
275
+ execute_process (COMMAND ${CCACHE_PROGRAM} --version OUTPUT_VARIABLE CCACHE_VERSION_STR)
276
+ string (REGEX MATCH "[0-9]+\. [0-9]+\. ?[0-9]*" CCACHE_VERSION "${CCACHE_VERSION_STR} " )
277
+
274
278
set (LLVM_CCACHE_MAXSIZE "" CACHE STRING "Size of ccache" )
275
279
set (LLVM_CCACHE_DIR "" CACHE STRING "Directory to keep ccached data" )
276
- set (LLVM_CCACHE_PARAMS "CCACHE_CPP2=yes CCACHE_HASHDIR=yes"
277
- CACHE STRING "Parameters to pass through to ccache" )
278
280
279
- if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows" )
280
- set (CCACHE_PROGRAM "${LLVM_CCACHE_PARAMS} ${CCACHE_PROGRAM} " )
281
+ # ccache only supports passing options on the command line from version 4.8.0
282
+ # use a workaround with ad-hoc environment variables for older versions
283
+ if (CCACHE_VERSION VERSION_LESS "4.8.0" )
284
+ set (LLVM_CCACHE_PARAMS "CCACHE_CPP2=yes;CCACHE_HASHDIR=yes"
285
+ CACHE STRING "Parameters to pass through to ccache" )
286
+
287
+ if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows" )
288
+ set (launcher_params ${LLVM_CCACHE_PARAMS} )
289
+ if (LLVM_CCACHE_MAXSIZE)
290
+ set (launcher_params CCACHE_MAXSIZE=${LLVM_CCACHE_MAXSIZE} ${launcher_params} )
291
+ endif ()
292
+ if (LLVM_CCACHE_DIR)
293
+ set (launcher_params CCACHE_DIR=${LLVM_CCACHE_DIR} ${launcher_params} )
294
+ endif ()
295
+ set (launcher ${launcher_params} "${CCACHE_PROGRAM} " )
296
+ else ()
297
+ if (LLVM_CCACHE_MAXSIZE OR LLVM_CCACHE_DIR OR
298
+ NOT LLVM_CCACHE_PARAMS MATCHES "CCACHE_CPP2=yes;CCACHE_HASHDIR=yes" )
299
+ message (FATAL_ERROR "Ccache configuration through CMake is not supported on Windows. Please use environment variables." )
300
+ endif ()
301
+ set (launcher "${CCACHE_PROGRAM} " )
302
+ endif ()
303
+ else ()
304
+ set (LLVM_CCACHE_PARAMS "run_second_cpp=true;hash_dir=true"
305
+ CACHE STRING "Parameters to pass through to ccache" )
306
+
307
+ set (launcher_params ${LLVM_CCACHE_PARAMS} )
281
308
if (LLVM_CCACHE_MAXSIZE)
282
- set (CCACHE_PROGRAM "CCACHE_MAXSIZE =${LLVM_CCACHE_MAXSIZE} ${CCACHE_PROGRAM} " )
309
+ set (launcher_params max_size =${LLVM_CCACHE_MAXSIZE} ${launcher_params} )
283
310
endif ()
284
311
if (LLVM_CCACHE_DIR)
285
- set (CCACHE_PROGRAM "CCACHE_DIR =${LLVM_CCACHE_DIR} ${CCACHE_PROGRAM} " )
312
+ set (launcher_params cache_dir =${LLVM_CCACHE_DIR} ${launcher_params} )
286
313
endif ()
287
- set_property (GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_PROGRAM} )
288
- else ()
289
- if (LLVM_CCACHE_MAXSIZE OR LLVM_CCACHE_DIR OR
290
- NOT LLVM_CCACHE_PARAMS MATCHES "CCACHE_CPP2=yes CCACHE_HASHDIR=yes" )
291
- message (FATAL_ERROR "Ccache configuration through CMake is not supported on Windows. Please use environment variables." )
292
- endif ()
293
- # RULE_LAUNCH_COMPILE should work with Ninja but currently has issues
294
- # with cmd.exe and some MSVC tools other than cl.exe
295
- set (CMAKE_C_COMPILER_LAUNCHER ${CCACHE_PROGRAM} )
296
- set (CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_PROGRAM} )
314
+ set (launcher "${CCACHE_PROGRAM} " ${launcher_params} )
297
315
endif ()
316
+
317
+ set (CMAKE_C_COMPILER_LAUNCHER ${launcher} )
318
+ set (CMAKE_CXX_COMPILER_LAUNCHER ${launcher} )
298
319
else ()
299
320
message (FATAL_ERROR "Unable to find the program ccache. Set LLVM_CCACHE_BUILD to OFF" )
300
321
endif ()
0 commit comments