-
Notifications
You must be signed in to change notification settings - Fork 83
Integration
There are various approaches to integrating clcache in a build system. In principle, about any build system works with clcache but there are some things to consider.
- CMake Integration
- Generic Integration
- Distutils Integration
- Integration for Visual Studio
- Integration via wrapper batch file
- MSBuild Integration
Make sure that you have a recent Python installed. Then, just run the following in a powershell prompt:
pip install git+https://github.com/frerich/clcache.git
$env:CC = "clcache"
$env:CXX = "clcache"
cmake --build .
A generic approach to integrating clcache into a build process is to
- generate an executable build
- rename
clcache.exe
tocl.exe
-
prepend the directory in which
clcache.exe
is stored to thePATH
environment variable
This way, most build systems will pick up clcache transparently by calling cl.exe
as before, and clcache will forward calls to the original compiler as needed by scanning the PATH
environment variable for another executable named cl.exe
.
Clcache will automatically monkeypatch distutils if the USE_CLCACHE
environment variable is set to 1
.
pip install git+https://github.com/frerich/clcache.git
$env:USE_CLCACHE = "1"
Some users have reported (see e.g. #18) that in order to make Visual Studio pick up clcache
, the original compiler binary needs to be moved out of the way and replaced with an executable file:
- Rename
cl.exe
to e.g.cl_original.exe
- Rename
cl.exe.config
to e.g.cl_original.exe.config
- Copy the generated
clcache.exe
file tocl.exe
- Set
CLCACHE_CL
environment variable to point tocl_original.exe
.
The last step will tell clcache that the original compiler to forward calls to is no longer available using the default name.
This method is especially handy when there are multiple Python installations on a system (but Chocolatey is not available), or when hacking on the clcache source code:
Create a file clcache.bat
and put it in a directory mentioned in the PATH
environment variable (e.g. %HOME%\bin
):
@echo off
@setlocal
rem this is a good place for clcache environment variables
set CLCACHE_HARDLINK=1
C:\Python35\python.exe C:\clcache\clcache.py %*
Now set your compiler to clcache.bat
in the build system, e.g. for CMake
set CC=clcache.bat
set CXX=clcache.bat
cmake ..
nmake
Check stats via clcache.bat -s
, clear cache clcache.bat -C
and so on.
- generate an executable build
- add the directory in which
clcache.exe
is stored to thePATH
environment variable
Now you can invoke MSBuild with following parameter:
msbuild.exe /p:CLToolExe=clcache.exe /p:CLToolPath=c:\path\to\the\clcache
This way clcache will be invoked instead of cl.exe
and clcache will forward calls to the original compiler as needed by scanning the PATH
environment variable for another executable named cl.exe
.
Also see Caveats wiki page for further discussions how to integrate clcache with MSBuild.