Building Qt5 for Windows 10

These notes were originally adapted from the information provided at this link: https://wiki.qt.io/Building_Qt_5_from_Git and focus on Windows 10, Visual Studio 2019 (64 bit), Qt v5.15.X and some nuances and issues encountered. They have also evolved as I’ve needed to come back and refer to them (or have discovered changes in the Qt scripts).

Setup build tools

  • Remove “sh” command: Ensure the “sh” command is not in the path (simply run “sh” and see if it runs – it should not). This may involve removing “C:\cygwin64\bin” in System Properties, Environment Variables, System variables, Path. 
  • Install VS2019: Install Microsoft Visual Studio 2019 64-bit for C++
  • Install Perl: e.g. from http://strawberryperl.com (ensure perl is in path – run “perl -version”)
  • Install Python (lots of options):
    • Python 3.7 from Microsoft Store (open a command prompt, type “python”, hit enter, sell your sour to the Microsoft Store).
    • From python.org – https://www.python.org (ensure python is in path – run “python –version”)
    • Python development option in Visual Studio installer
    • ActivePython
  • Install git client CLI: e.g. from Git – Downloads (git-scm.com)

VS2019 command prompt

Start the “right” command prompt/environment: Run all commands below from the “x64 Native Tools Command Prompt for VS 2019” (just search for this after hitting the Windows key). You can pin this to your taskbar (or make some other kind of shortcut) to open it later. You may be using Community or Professional edition depending on your needs.

Unsetting problematic environment variables

Unset some variables that might cause Qt grief at this point

set QMAKESPEC=
set XQMAKESPEC=
set QMAKEPATH=
set QMAKEFEATURES=

Acquiring/preparing source code

cd %HOMEPATH%
git clone git://code.qt.io/qt/qt5.git
cd qt5
git checkout v5.15.2
./init-repository -f --module-subset=qtbase

Configuring the build

cd %HOMEPATH%
mkdir qt5-build
cd qt5-build
..\qt5\configure -opensource -platform win32-msvc -nomake examples -nomake tests -confirm-license -mp

You should see a message that looks like this…

Qt is now configured for building. Just run 'nmake'.
Once everything is built, you must run 'nmake install'.
Qt will be installed into 'C:\Qt\Qt-5.15.2'.

Build the libraries and tools

cd %HOMEPATH%\qt5-build
nmake

Install the libraries and tools

cd %HOMEPATH%\qt5-build
nmake install

Add Qt5 tools to path

Add C:\Qt\Qt-5.15.2\bin to Path (System Properties, Advanced, Environment Variables). Setting for just the user (not entire system) is probably preferred. This will allow things like “qmake” to run from any command prompt.

Notes on mirroring Qt repos

Note: this is not legal advice for anyone that might trip across this. Read and understand Qt’s guidance for your own use and use the instructions here at your own risk.

These instructions assume you have “your own” git repo server setup at “yourdomain.com/path-to-repos”

Qt’s LGPL guidance states that sourcecode (or instructions to obtain sourcecode) must be provided, and it is insufficient to simply point to Qt’s repos. To mirror Qt repos, start with mirroring the “main” repo (the idea being that you can refer to your own sourcecode location rather than the Qt original source location, but keep in mind that Qt’s guidance might change)…

git clone --mirror git://code.qt.io/qt/qt5.git
cd qt5.git
git remote set-url --push origin https://www.yourdomain.com/path-to-repos/qt5.git

(set its default branch to 5.15.2)

To fetch/push:

git fetch -p origin
git push --mirror

Submodule example (for qtbase)…

git clone --mirror git://code.qt.io/qt/qtbase.git
cd qtbase.git
git remote set-url --push origin https://www.yourdomain.com/path-to-repos/qtbase.git

Again, to fetch/push:

git fetch -p origin
git push --mirror

(set its default branch to 5.15.2)

After setting these up in remote, you can do a normal clone, etc…

git clone https://www.yourdomain.com/path-to-repos/qt5.git
git clone https://www.yourdomain.com/path-to-repos/qtbase.git
cd qt5
./init-repository -f --module-subset=qtbase

Then follow the basic instructions for building/installing above.

Leave a Comment