6

Is there any way to use ccache with Xcode 4, to improve C++ build time?

Using environment variables I've set CC and CXX to ccache, but the build fails since ccache does not recognise some of the parameters that Xcode 4 outputs.

Cœur
  • 37,241
  • 25
  • 195
  • 267
amfcosta
  • 1,049
  • 10
  • 21
  • Why do you want to use `ccache` in the first place? Xcode by default works the way `ccache` does; it will only re-compile files that have changed since the last time you hit compile (unless you cleaned the project prior to build or changed a build setting). Thus I doubt you would see any speed-up using `ccache` in Xcode. – Mecki Jan 14 '13 at 19:00
  • 2
    @Mecki, xcode does not cache the build product. E.g. if you switch between branches, xcode will re-compile a lot of files, it has already compiled before. In this case ccache will improve compile times massively. – timblechmann Jul 10 '13 at 08:56

2 Answers2

3

Ccache has Clang support from version 3.2 and newer.

See here for a possible solution on how to use ccache in Xcode: https://pspdfkit.com/blog/2015/ccache-for-fun-and-profit/

Cœur
  • 37,241
  • 25
  • 195
  • 267
Joel Rosdahl
  • 846
  • 9
  • 12
0

This answer shows a technique where ccache can be used with Xcode by setting the CC and CXX user-defined variables in the Xcode project. That particular answer was using CMake to create the Xcode project files, but the same principle applies to manually created Xcode projects. The CC and CXX variables act like overrides to the compiler used, so diverting them to a wrapper script which invokes ccache with the compiler you want achieves the desired functionality. Note that I've only tested it with Xcode 7, but I'd expect earlier versions probably work too. This article by Peter Steinberger also covers essentially the functionality you want without using CMake, but it uses the same technique of setting CC and CXX Xcode project variables.

Community
  • 1
  • 1
Craig Scott
  • 9,238
  • 5
  • 56
  • 85