A “shadow build” is an out-of-source build, where the source code is kept in one place and the build tree in another. I use this method to compile Qt on windows with Visual Studio (as of writing this post with VS2010).


Preparation

First download the latest Qt source code package. I usually download the latest qt-everywhere-opensource-src-x.x.x from http://get.qt.nokia.com/qt/source/.

Unpack it into the directory you want the source code kept, I choose D:\dev\qt-src. Create also the destination directory where you want your build to be, I chose D:\dev\qt-build. The directories can be anything and they can be in different drives, but I recommend avoiding to use directory names with spaces, as this may cause problems.

You will also need to have Perl installed to run the configure script of Qt. If you don’t already have it, I recommend using the portable version of Strawberry Perl for Windows. You can download it here. As this is a one-off step and you won’t need to do this next time you want to build Qt, unpack it into a suitable location in your system. I chose D:\dev\perl. Notice the batch file portableshell.bat, as we will need this in a bit.

Strawberry Perl for Windows

Directory of Strawberry Perl for Windows


Configuring and Compiling Qt

Now, open the Visual Studio Command Prompt, as shown here:

Visual Studio Command Prompt

Visual Studio Command Prompt

You have to open the VS Command Prompt instead of a normal Command Prompt (cmd.exe), as this will load the Visual Studio variables into your environment, e.g. location of the Visual C++ compiler, linker etc. You also have to setup your environment with Perl support, so execute from within the VS Command Prompt the portableshell.bat. You can easily do this:

D:\dev\perl\portableshell.bat

Now that your environment is setup with both VS and Perl support, change into the directory you intend to build and run the configure script in the source directory:

cd D:\dev\qt-build
D:\dev\qt-src\configure -ltcg -opensource -mp

You may want to have other switches for your Qt, so investigate the options with configure -help, but these will work just fine if you don’t have any special needs. Briefly:

  • -ltcg enables Link-time Code Generation, which tells the linker to call the compiler and perform whole program optimization.
  • -opensource tells Qt you’re building for Open Source development, not commercial.
  • -mp enables building Qt with multiple processes, which will speed up your build. Use this if you have a computer with multiple cores or cpus.

The configure script will run for a while to compile some basic tools required and configure the Qt build for your system. Once configuration is finished you are ready to compile Qt. This may take a couple of hours and around 15-20GB of free space may be required to build everything in D:\dev\qt-build. To compile the code use either the default nmake or jom. jom has the advantage of utilizing all cpus and cores on multicore machines and therefore it will build qt much faster than nmake.

So, while still in D:\dev\qt-build, to start the compilation:

nmake -f D:\dev\qt-src\Makefile

or

jom -f D:\dev\qt-src\Makefile

Once the compilation is finished you may also want to build the documentation for Qt Assistant, which isn’t built by default, you can do this with:

nmake -f D:\dev\qt-src\Makefile docs
jom -f D:\dev\qt-src\Makefile docs

If everything goes according to plan Qt will be built in D:\dev\qt-build and may occupy some 15-17GB of hard disk space. If you don’t want to rebuild Qt, you can clean up the build from intermediate files:

nmake -f D:\dev\qt-src\Makefile clean
jom -f D:\dev\qt-src\Makefile clean

Keep in mind that you cannot delete or move the sources from D:\dev\qt-src as the shadow build files in D:\dev\qt-build reference headers in this directory and will not work when you try to compile software against it. If you really need to move your Qt build elsewhere then take a look at QtMove.


Software used

(versions here are updated each time I update the toolset and libraries)

0