Building Qt on MinGW-w64

This article explain you how to prepare a Qt build environment with using of MinGW-w64 toolchain on Windows operating system. Reason of creating this article is that official MinGW assemblies of Qt are 32-bit only. MinGW-w64 gives you able to have native 64-bit builds with MinGW without usage of Visual Studio.

Prepare MinGW-w64
At first, you need to install MinGW-w64 itself!

Download MinGW-w64 installer
Open official download page: http://mingw-w64.org/doku.php/download and find the "Mingw-builds", and then open "Installation: Sourceforge" link to download the installer.

Installing MinGW-w64 assemblies

 * After starting installer, you will see the greeting page, just press "next".
 * On the settings page choose:
 * Version: Choose the latest (7.1.0 on moment of writing this article)
 * Architecture: i686 for 32-bit builds and x86_64 for 64-bit builds
 * Threads: POSIX (suggested) threads are required for std::thread, std::mutex and std::future. Works slower since it's a proxy over Win32 threads. Win32 threads model will work faster, but to use std::thread, std::mutex and std::future you will need to use extra headers for them.
 * Exception:
 * DWARF (32-bit only, suggested for i686 ) can cause executables to be slightly bloated because large call stack unwinding tables have to be included in th executables.
 * A method based on setjmp/longjmp (SJLJ). SJLJ-based EH is much slower than DW2 EH (penalising even normal execution when no exceptions are thrown), but can work across code that has not been  compiled with GCC or that does not have call-stack unwinding  information.
 * Structured Exception Handling (SEH). (suggested for x86_64) Windows uses its own exception handling mechanism known as Structured Exception Handling (SEH).
 * Revision: Usually has 0 only.
 * Choose the installation path: Suggested to don't install into "Program files" and install just into root of any drive (for example, C:\mingw-w64\i686-7.1.0-posix-dwarf-rt_v5-rev0 )
 * Wait when installer will download and install your file.

To have able to build for multiple architectures please run installer again, but choose different architecture than installed.

Preparing Qt sources
At first, download the pack of Qt source code here: (the link is points on Qt 5.9.1 which is latest on moment of creating this article. To get newer version you can browse the archive (you will need to open /X.X/X.X.X/single/ folder and take the packed archive) )

When you have to download the archive, please unpack it into any ASCII-only path (for example, into C:\Qt\QtSrc\).

Run build of Qt
Then inside path where you have unpacked create the .bat script with content below. Then find "CONFIGURE BEFORE RUN SCRIPT!!" section and change values of those variables into actual:
 * QtSrcDir must point the actual folder with source code of Qt you have unpacked
 * QtPrefixDir must point the output folder where built Qt assembly will be saved
 * MingwDir must point the MinGW assembly (32-bit or 64-bit) you want to use for Qt building
 * BuildType can contain "-release" for release-only build or "-debug-and-release" to have both debug and release builds

Script for building of 64-bit Shared debug-and-release set of Qt 5.12.0

Script for building of 32-bit Shared debug-and-release set of Qt 5.6.3

Script for building of 64-bit Static Release set (debug is not recommended for static builds)

Build and install
When you done everything, run your build script and wait 1.5 ~ 3 hours (dependent to your CPU power) until everything will be built.

Usage
When script will finish it's work, you will have to use the bin/qmake.exe from installation target directory to configure your qt projects to build with static Qt version. You can plug it into Qt Creator with adding reference to bin/qmake.exe from the "Settings" / "Building and debug" tab.