In this blog post I will go through the process of building a 32 bit Qt 5.4 with OpenSSL support on Windows. I will use Windows 8.1 64 bit and Visual Studio 2013, but there should only be minor things you need to change for other versions.

Whether you should build Qt yourself is not the topic of this blog but I’ll give it a bit of consideration here. I personally prefer using the binary Qt builds on Windows and compile Qt myself on Linux. But sometimes project requirements demand modifications you can only do by building Qt yourself, and then I’ll build it on Windows as well. This could for example be because you add patches to your build, use special compiler options or to build Qt with certain features on or off. However, I would still suggest that you stay with the binary builds when you can.

I don’t compile webkit here. In 5.4, we have the new blink based QWebEngine, and I suggest that you use this unless there is a very good reason for you to stay with webkit. Webkit is a dead end, and it’s big and ugly.

I will compile everything in \Qt\5.4.0\src and install to \Qt\5.4.0.

Downloads

First step is to download the sources. You can find version 5.4 here: http://download.qt-project.org/official_releases/qt/5.4/5.4.0/single/qt-everywhere-opensource-src-5.4.0.zip. Unzip this in C:\Qt\5.4.0 and rename the directory to src.

For the compiler, you can choose any Visual Studio version from 2010 and up and the SDK for it. I don’t use MinGW, but that is an option as well. However, with MinGW you won’t be able to follow this recipe completely.

In this build we will have OpenSSL support. On the OpenSSL download page for binaries page https://www.openssl.org/related/binaries.html there are a couple of Windows builds. OpenSSL is really annoying to build on Windows, so you probably want to use this. I chose the SLP build http://slproweb.com/products/Win32OpenSSL.html because this has an installer with include files. The indy.fulgan doesn’t have the include files, and we need those for the build. If you want to use the OpenSLL binary itself (to make certificates or other things) you should install the appropriate VS redistributable package. Otherwise, don’t worry about the installer error message that this is missing. Get the 32 bit full version (not the light) of the latest version. I chose Qt\OpenSSL-Win32 as the install directory and to copy ssl binaries to the OpenSSL bin directory.

We need perl for the configure step. I use the ActiveState perl distribution, but the Strawberry should be okay as well. Get it from http://www.activestate.com/activeperl/downloads. I chose to install the 64 bit version and it installs itself in C:\Perl64.

Python is needed to build QML, the JS engine and webkit. If you build a very small Qt with basically just base, you should be able to build without python. Download the latest version from https://www.python.org/downloads.

If you choose to build webkit, you also have to install ruby.

You have a choice between using ICU and the native Windows support. In this build I don’t use ICU because I prefer that the application follow other Windows applications over the added unicode support that ICU supports. If you choose to use it, download the library from http://site.icu-project.org/ and add -icu to the configure options.

There can easily be more things you need to install. For example the headers and libraries for database connectivity, native OpenGL drivers etc. But I prefer to keep this build process as simple as I can.

The Build

Open a visual studio developer command prompt, go to the Qt dir and set up the environment variables for the build:

cd \Qt\5.4.0\src
set PATH=%CD%\qtbase\bin;%CD%\gnuwin32\bin;C:\Python34;%PATH%
SET QMAKESPEC=win32-msvc2013
set CL=/MP

My perl installation added the perl bin dir to PATH. Make sure yours did as well or add it to PATH. Depending on your python version, you might have to adjust the path for this as well.

Now we run the configure script. In this case I do a debug build with most of the default options. If your purpose is to create a Qt that can be used to build production level installers, you should change -debug to -release and not set -developer-build.

configure -prefix C:\Qt\5.4.0 -debug -developer-build -opensource -c++11 -nomake examples -skip qtwebkit -plugin-sql-sqlite -openssl -I C:\Qt\OpenSSL-Win32\include -L C:\Qt\OpenSSL-Win32

Check that all the features you want is in the build. When you are satisfied, run nmake. The build will take several hours. And finally run nmake install.

That’s it, you now have a complete Qt on Windows.

If you use Qt Creator, you should go in to the options dialog, go to Qt Versions in the Build & Run tab and add a new Qt version. In the dialog that comes up, choose the new qmake.exe in C:\Qt\5.4.0\bin. After this, add a kit with your new Qt version, the x86 visual C++ compiler 12.0 and the cdb debugger.

64 Bit Build

To build a 64 bit version, you only need a few modifications to this.

Install an OpenSSL 64 bit package instead of the 32 bit (or next to it if you want to build both of them) and change QMAKESPEC from win32-msvc2013 to win64-msvc2013.

On the configure line, you change the two OpenSSL directory locations to where you install the 64 bit version.