# Using ccache with Visual Studio generator and ClangCL toolset

**URL:** https://discourse.cmake.org/t/using-ccache-with-visual-studio-generator-and-clangcl-toolset/15497
**Category:** Code
**Tags:** os:windows, gen:vs
**Created:** [February 4, 2026, 7:56pm UTC](https://discourse.cmake.org/t/using-ccache-with-visual-studio-generator-and-clangcl-toolset/15497 "2026-02-04T19:56:04Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![retif](https://discourse.cmake.org/user_avatar/discourse.cmake.org/retif/32/1776_2.png) [@retif](https://discourse.cmake.org/u/retif)
#### Post date: [February 4, 2026, 7:56pm UTC](https://discourse.cmake.org/t/using-ccache-with-visual-studio-generator-and-clangcl-toolset/15497/1 "2026-02-04T19:56:05Z")

</div>

I am looking at enabling [ccache](https://ccache.dev/) in my projects, and I got it working on/with almost all the platforms/generators that I need. The [“Professional CMake”](https://crascit.com/professional-cmake/) book was a great help with that (_big thanks to @craig.scott, as usual_).

But one specific combination of a generator and a [toolset](https://cmake.org/cmake/help/latest/manual/cmake.1.html#cmdoption-cmake-T) turned out to be problematic - it is Visual Studio generator and ClangCL toolset (_with the intention to use [Clang/LLVM](https://learn.microsoft.com/en-us/cpp/build/clang-support-msbuild)_). To clarify, it is all good with a “bare” Visual Studio generator and “default” toolset value (_such as `v143`_), the problem only occurs when `-T ClangCL` is provided.

I’ve made a minimal example project [here](https://github.com/retifrav/MREs/tree/647dd5cdefbcb05f933e7c2e08d4a6aabf941acd/discourse-cmake-org/15497). The [ccache.cmake](https://github.com/retifrav/MREs/blob/647dd5cdefbcb05f933e7c2e08d4a6aabf941acd/discourse-cmake-org/15497/cmake/ccache.cmake) module is based on a reduced fragment of Appendix A from the book (_won’t copy-paste the entire contents, besides only Visual Studio part is relevant here_).

First, like I said, default MSVC toolset configures and builds fine:

```cmd
> cd e:/path/to/project
> mkdir build
> cd build
> cmake -G "Visual Studio 17 2022" -DCMAKE_INSTALL_PREFIX="../install" -DUSING_CCACHE=YES ..
> cmake --build . --target install --config Release -- /m 

```

generated `launch-cl.cmd` contains the following:

```cmd
@echo off
set CCACHE_SLOPPINESS=pch_defines,time_macros
"D:\programs\ccache\ccache.exe" "E:/tools/vs/vs2022/VC/Tools/MSVC/14.44.35207/bin/Hostx64/x64/cl.exe" %*

```

and the generated `*.vcxproj` contains this:

```xml
<PropertyGroup Label="Globals">
  <ProjectGuid>{9AA40D43-2AF4-391C-BE32-E755F2A361D0}</ProjectGuid>
  <Keyword>Win32Proj</Keyword>
  <CLToolExe>launch-cl.cmd</CLToolExe>
  <CLToolPath>e:/path/to/project/build</CLToolPath>
  ...

```

But then, if I add `-T ClangCL` to the configuration (_in a clean/fresh build_):

```cmd
> cd e:/path/to/project
> mkdir build
> cd build
> cmake -G "Visual Studio 17 2022" -DCMAKE_INSTALL_PREFIX="../install" -DUSING_CCACHE=YES -T ClangCL ..

```

then generated `launch-cl.cmd` will contain the following:

```cmd
@echo off
set CCACHE_SLOPPINESS=pch_defines,time_macros
"D:\programs\ccache\ccache.exe" "E:/tools/vs/vs2022/VC/Tools/Llvm/x64/bin/clang-cl.exe" %*

```

so now it correctly got the `clang-cl.exe` compiler. And the generated `*.vcxproj` will contain the same part as before:

```xml
<PropertyGroup Label="Globals">
  <ProjectGuid>{9AA40D43-2AF4-391C-BE32-E755F2A361D0}</ProjectGuid>
  <Keyword>Win32Proj</Keyword>
  <CLToolExe>launch-cl.cmd</CLToolExe>
  <CLToolPath>e:/path/to/project/build</CLToolPath>
  ...

```

although the full `*.vcxproj` will have some differences, such as:

 ![msvc-vs-clangcl](https://discourse.cmake.org/uploads/default/original/2X/c/c75bee277d43b4c2915fd8381b847c14476ac4c5.png)

but that is to be expected, I reckon, and what’s important is that `CLToolExe` and `CLToolPath` properties have the correct values.

However, trying to build this configuration will fail:

```cmd
> cmake --build . --target install --config Release -- /m

  Building Custom Rule E:/path/to/project/CMakeLists.txt
E:\tools\vs\vs2022\MSBuild\Microsoft\VC\v170\Microsoft.Cpp.ClangCl.Common.targets(235,5): error : Building with "clang-cl.exe". [E:\path\to\project\build\thingy.vcxproj]
E:\tools\vs\vs2022\MSBuild\Microsoft\VC\v170\Microsoft.Cpp.ClangCl.Common.targets(235,5): error MSB6004: The specified task executable location "E:/path/to/project/build\clang-cl.exe" is invalid. [E:\path\to\project\build\thingy.vcxproj]

```

From that output I gather that this time MSBuild(?) ignored(?) the `CLToolExe` value from `*.vcxproj`, while still respecting the `CLToolPath` property from the same file, and that results in an invalid path `E:/path/to/project/build\clang-cl.exe` (_with a wrong slash?_), where `E:/path/to/project/build` is a correct value from the `CLToolPath` property, but `clang-cl.exe` is a wrong value, because instead there should be `launch-cl.cmd` value here from the `CLToolExe` property, shouldn’t it.

So far it looks like there is something wrong with MSBuild(?), as CMake generates a correct(?) project file, which does work fine without `-T ClangCL`, so it’s MSBuild who ignores `CLToolExe` property with this particular toolset and instead uses a hardcoded (_somewhere?_) `clang-cl.exe` value.

For now I’ve managed to find a workaround which is to simply provide `/p:CLToolExe` inline, and then MSBuild will finally respect it, and the build will go fine:

```cmd
> cmake --build . --target install --config Release -- /m /p:CLToolExe=launch-cl.cmd

```

Theoretically, one would also provide `/p:CLToolPath=e:/path/to/project/build`, but it is already present in `*.vcxproj`, and MSBuild does not ignore that one (_for some reason_).

I get the same results no matter what shell is used: it can be “plain” cmd, Git BASH or that special Visual Studio Developer Command Prompt / Developer PowerShell environment - makes no difference. So unless I have missed some more configuration parameters, this looks like a bug in MSBuild, because what else can CMake do to make it respect the `CLToolExe` property in the generated `*.vcxproj` file (_so one would not need to “enforce” it via inline CLI override_)? And once again, it all works fine with the “default” toolset (_so without `-T ClangCL`_).

If anything, I mostly use Ninja generator, so normally I wouldn’t care about something not working with VS generators, but unfortunately I do need to make this work with VS generators too.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [February 9, 2026, 3:44am UTC](https://discourse.cmake.org/t/using-ccache-with-visual-studio-generator-and-clangcl-toolset/15497/2 "2026-02-09T03:44:31Z")

</div>

Without knowing what CMake _should_ write, I would lean towards a Visual Studio issue. If you file one on their bug tracker, maybe they could provide information about what CMake could do about this.

---

<div class="post-metadata">

### Author: ![retif](https://discourse.cmake.org/user_avatar/discourse.cmake.org/retif/32/1776_2.png) [@retif](https://discourse.cmake.org/u/retif)
#### Post date: [February 16, 2026, 11:06am UTC](https://discourse.cmake.org/t/using-ccache-with-visual-studio-generator-and-clangcl-toolset/15497/3 "2026-02-16T11:06:25Z")

</div>

I was going to do that, but did not want to jump through the hoops of creating a Microsoft account and fighting with their web-forms. Anyway, the problem is now reported [here](https://developercommunity.visualstudio.com/t/MSBuild-ignores-the-CLToolExe-value-from/11044817), so we’ll see how it goes.
