Skip to content
This repository has been archived by the owner on Feb 4, 2020. It is now read-only.

Integration

Benjamin Fuchs edited this page Sep 22, 2018 · 5 revisions

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.

Table of Contents

  1. CMake Integration
  2. Generic Integration
  3. Distutils Integration
  4. Integration for Visual Studio
  5. Integration via wrapper batch file
  6. 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

  1. generate an executable build
  2. rename clcache.exe to cl.exe
  3. prepend the directory in which clcache.exe is stored to the PATH 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:

  1. Rename cl.exe to e.g. cl_original.exe
  2. Rename cl.exe.config to e.g. cl_original.exe.config
  3. Copy the generated clcache.exe file to cl.exe
  4. Set CLCACHE_CL environment variable to point to cl_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.

  1. generate an executable build
  2. add the directory in which clcache.exe is stored to the PATH 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.