As of version 4.6.1, ccache supports compilation with msvc.
On my Windows environment, I have ccache installed and available via the command line. I try to integrate ccache to my cmake project in the following way:
Root CMakeLists.txt:
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
message("CCACHE is found")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) # Less useful to do it for linking, see edit2
else(CCACHE_FOUND)
message("CCACHE is NOT found")
endif(CCACHE_FOUND)
Here is my cmake configuration in CMakePresets.json:
{
"name": ",
"hidden": false,
"generator": "Visual Studio 17 2022",
"toolset": {
"value": "host=x64",
"strategy": "external"
},
"architecture": {
"value": "x64",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_C_COMPILER": "cl.exe",
"CMAKE_CXX_COMPILER": "cl.exe",
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
"CMAKE_TOOLCHAIN_FILE": {
value": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"type": "FILEPATH"
},
"VCPKG_INSTALLED_DIR": "${sourceDir}/build/packages",
"VCPKG_TARGET_TRIPLET": "x64-windows-static-md"
},
"vendor": { "microsoft.com/VisualStudioSettings/CMake/1.0": { "hostOS": [ "Windows" ] } }
}
When Running the build, I can see ccache is found but I see no indication that it works or called by the build system.
Running ccache -s
shows every stat is 0 as if ccache is never called.
Questions:
- How to correctly configure ccache with MSVC & cmake?
- How can I ensure ccache is working and the right commands are being used by the build system? is there a "verbose" option I can provide to cmake / ccache to debug this?