If you are working on the Qt source code, you likely want to compare your work with the latest stable branches for benchmarking or testing. However, once you checkout a different branch, make will often rebuild everything that you were working on. This can take a long time, making it hard to quickly compare with the latest stable build.

Use ccache

As a first measure, if you are working on Linux or macOS I recommend installing ccache , which will cache the results of each compiled object file. By putting ccache before the compiler in PATH, it will fetch the latest result from cache instead of recompiling whenever possible. On Ubuntu, you install ccache with:

sudo apt install ccache

Then add it to your PATH by adding the following to ~/.profile and ~/.bashrc:

export PATH="/usr/lib/ccache:$PATH"

This reduces the compile time drastically one rebuilds, but an even better option is to have different versions of the Qt sources in different folders, and to keep separate build folders for each build target. This is easy to set up and allows you to quickly change between build targets. In addition, it is possible to save disk space by only keeping one complete git clone of all the Qt modules. The following strategy is now the one I prefer to work on multiple Qt sources simultaneously.

Checkout each branch in a separate directory

First, create a directory for each version of Qt that you want to build:

mkdir dev 5.8 5.9 myfeature

Then, in dev, clone the Qt repository and run the init-repository script:

cd dev # ./dev
git clone git://code.qt.io/qt/qt5.git
cd qt5 # ./dev/qt5
git checkout dev
perl init-repository --codereview-username yourusername --module-subset=default,qtcharts,qtdatavis3d,-qtwebkit,-qtwebkit-examples,-qtwebengine,-qtwebview
cd ../..  # ./

Now, clone once more for 5.9, but note that we use the --alternates= option in init-repository to point to the dev directory where the sources are already checked out:

cd 5.9 # ./5.9
git clone git://code.qt.io/qt/qt5.git
cd qt5 # ./5.9/qt5
git checkout 5.9
perl init-repository --codereview-username yourusername --module-subset=default,qtcharts,qtdatavis3d,-qtwebkit,-qtwebkit-examples,-qtwebengine,-qtwebview --alternates=../../dev/qt5
cd ../.. # ./

Repeat this for 5.8, myfeature and any other version of the sources you want to work with.

Create separate build folders for each target

Now, for each version of Qt you want to target, create one build directory for release and one for debug, and run the configure script in each. In the below example, we do this for the dev branch. I have chosen only to build the Qt3D, QtQuickControls, QtDatavisualization and QtCharts modules and their dependencies:

cd dev
# Build debug and release versions
mkdir build-debug
cd build-debug # ./dev/build-debug
../qt5/configure -developer-build -nomake tests -nomake examples -force-debug-info -no-pch -debug
make module-qt3d module-qtquickcontrols module-qtquickcontrols2 module-qtdatavis3d module-qtcharts -j4
cd .. # ./dev/
mkdir build-release
cd build-release # ./dev/build-release
../qt5/configure -developer-build -nomake tests -nomake examples -force-debug-info -no-pch -release
make module-qt3d module-qtquickcontrols module-qtquickcontrols2 module-qtdatavis3d module-qtcharts -j4
cd .. # ./dev/

If you are only debugging or only testing performance, you can choose to build only one of the two versions.

Once you have done this, you can add each version of Qt to your kits in Qt Creator and target them when testing your examples.

Happy building!