Using ccache together with qmake and QtCreator

Reading time ~1 minute

ccache is a simple tool that speeds up your builds/rebuilds. It builds up a cache that is used when building and rebuilding. This cache can make a huge performance impact on your build time. On there web page it says.

ccache is a compiler cache. It speeds up recompilation by caching previous compilations and detecting when the same compilation is being done again. Supported languages are C, C++, Objective-C and Objective-C++.

Integrating ccache into your build

I’ve been searching the web for a simple solution to add ccache into a qmake-based project with out any real luck. I found some solutions were people have done some minor hacks like:

# TLDR? No there are better ways...

Put that in your .pro-file and ccache will sort of work. But since version 5.9.2 of Qt there is a much simpler solution. Tor Arne Vestbø made a nice commit that simplifies this alot.

To use this feature you either add load(ccache) into your .pro-file or add CONFIG+=ccache to your qmake command line.

How much performance gain your project gets is hard to say - so test and see if it will improve your build.

ccache installation

Unfortunately the ccache feature in qmake doesn’t check whether you have ccache installed or not. This is something that is assumed. To install ccache on a Ubuntu based Linux machine run sudo apt install ccache. To solve it on other platforms/distributions I would recommend just simply Google it!

ccache configuration

One can configure ccache in many different ways. The default config (on Ubuntu 18.04) seems to be a maximum cache size of 5 GB. This can easily be changed. More information can be found here.

Build Qt with ccache

The commit I mentioned above also add support for ccache into the Qt5 build. This is something that will speed up your build and also fill your chache :).


Thanks to Cristian Adam for pointing out that this isn’t working on Windows. You see, I don’t own a Windows computer and I hope I never will… But still a big thanks for pointing it out.

To run it on Windows with MinGW you need to pass QMAKE_CXX=ccache g++ when compiling.

Let QQmlFileSelecor select which QML file to use

One problem I've been facing now and then when developing QML is the need for selecting different QML files depending on hardware, operating system, customer brand etc. QML has a pretty unknown feature for this called QQmlFileSelecor Continue reading

Using QML:s new DelegateChooser

Published on March 01, 2019

Integrate Clang-Tidy into CMake

Published on February 06, 2019