I write many little script which inspire my life from 13 years, hope this may help others.
some of them learn from other place, I will add reference at the beginning if I remmember.
https://ccache.dev/download.html
Tips: You may need call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat" like stuff
Copy ccache.exe to cl.exe, masq as cl.exe and will forward work to real cl.exe,
cd c:\ccache\
copy c:\ccache\ccache.exe cl.exe
Put Directory.Build.props in any upper dir
Put Directory.Build.targets in any upper dir
Tips: You may need call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat" like stuff
Tips: put the file with your ccache.exe
@echo off
%~dp0\ccache.exe cl.exe %*
set CC=c:\ccache\ccache_cl_wrapper.bat
set CXX=c:\ccache\cmake -G Ninja -S your_src_dir -B your_build_dir
For work with vcpkg
set VCPKG_KEEP_ENV_VARS=CC;CXX
Ref: https://learn.microsoft.com/en-us/vcpkg/users/config-environment#vcpkg_keep_env_vars
cmake -G Ninja -DCMAKE_C_COMPILER_LAUNCHER="c:\ccache\ccache.exe" -DCMAKE_CXX_COMPILER_LAUNCHER="c:\ccache\ccache.exe" -S your_src_dir -B your_build_dir
For work with vcpkg
set CMAKE_C_COMPILER_LAUNCHER="c:\ccache\ccache.exe"
set CMAKE_CXX_COMPILER_LAUNCHER="c:\ccache\ccache.exe"
set VCPKG_KEEP_ENV_VARS=CMAKE_C_COMPILER_LAUNCHER;CMAKE_CXX_COMPILER_LAUNCHER
Ref: https://learn.microsoft.com/en-us/vcpkg/users/config-environment#vcpkg_keep_env_vars
some time, you may mix these way together, which does not work most of the time, windows is not friendly for build cache, as Visual Studio is a one in all solution?!
c:\ccache\ccache -s
c:\ccache\ccache --print-stats