[llvm] [cmake] Pass arguments to ccache on Windows (PR #218791)
Martin Storsjö via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 27 01:34:12 PDT 2026
================
@@ -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}")
----------------
mstorsjo wrote:
If you have mismatched options, they are just silently ignored. And in order to observe it with a PCH build, you'd have to rebuild and see if it actually ends up speeding anything up.
You can observe the issue like this:
```
$ CCACHE_DEBUG=1 ccache gcc test/hello.c -o hello; ls hello.*.ccache-log; rm -f hello.*.ccache-log
hello.20260827_113131_789033.ccache-log
$ ccache CCACHE_DEBUG=1 gcc test/hello.c -o hello; ls hello.*.ccache-log; rm -f hello.*.ccache-log
ls: cannot access 'hello.*.ccache-log': No such file or directory
$ ccache debug=true gcc test/hello.c -o hello; ls hello.*.ccache-log; rm -f hello.*.ccache-log
hello.20260827_113140_264271.ccache-log
```
So here the env variable `CCACHE_DEBUG=1` does have effect, likewise does passing `debug=true` as an argument, but passing `CCACHE_DEBUG=1` as an argument is silently ignored and has no observeable effect.
https://github.com/llvm/llvm-project/pull/218791
More information about the llvm-commits
mailing list