Building Qt6 for Windows from source

The Qt docs are pretty hopeless when it comes to describing how to build Qt6 from source if you need the documentation (QDoc) to compile. This is because it needs LLVM, and that is not present for a WIndows distribution. So here’s how to do it. We are going to build LLVM 18.1.7, not 18.1.8 as that seems to have a couple of class methods dropped that Qt 6.7.2 still uses, at least when I tried it.

First download the source package – you want the llvm-project-18.1.7.src.tar.xz

For a 64 bit LLVM, we’re going to build at C:\Qt\LLVM-18.1.7-win64, and use NMAKE as the generator (or JOM which will build faster on multicore systems; Ninja would be another option) :

cmake -S llvm -B build-x64 -G “NMake Makefiles”
-DLLVM_ENABLE_PROJECTS=”clang;lld”
-DCMAKE_INSTALL_PREFIX=C:\Qt\LLVM-18.1.7-win64
-DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_RTTI=ON

cmake –build build-x64
cd build-x64
nmake install

Making a 32 bit LLVM is similar except we need to explicitly define the target:

cmake -S llvm -B build-x86 -G “NMake Makefiles”
-DLLVM_ENABLE_PROJECTS=”clang;lld”
-DCMAKE_INSTALL_PREFIX=C:\Qt\LLVM-18.1.7-win32
-DCMAKE_BUILD_TYPE=Release
-DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_ENABLE_RTTI=ON

cmake –build build-x86
cd build-x86
nmake install

Note we created a release build. As by default a debug build will be generated, and you can’t mix release and debug libs on Windows when building Qt.

Now for building Qt, first the 64 bit version. The following examples build Qt, I’m ignoring qtwebview/qtwebengine/qtlocation as I don’t need them and it speeds things up. Also I’m using existing OpenSSL and Python installations, YMMV.

mkdir C:\Qt\build-672-x64 (or wherever you want to create your build area)

In it create a configure_windows_64.bat file:
set LLVM_INSTALL_DIR=C:\Qt\LLVM-18.1.7-win64
set OPENSSL_DIR=C:\PROGRA~1\OpenSSL-Win64
set OPENSSL_CONF=%OPENSSL_DIR%\bin\openssl.cfg
set PATH=C:\Python383-x64;%OPENSSL_DIR%\bin;%LLVM_INSTALL_DIR%\bin;%PATH%
..\qt-everywhere-src-6.7.2-x64\configure -platform win32-msvc -prefix C:\Qt\6.7.2-x64 -opengl desktop -skip qtlocation -skip qtwebview -skip qtwebengine -nomake tests -nomake examples

then run:
configure_windows_64
cmake –build . –parallel
cmake –install .
cmake –build . –target docs
cmake –build . –target install_docs

The process for a 32 bit Qt build is similar:

Create work dir e.g. C:\Qt\build-672-x86

In it create a configure_windows_32.bat file:
set LLVM_INSTALL_DIR=C:\Qt\LLVM-18.1.7-win32
set OPENSSL_DIR=C:\PROGRA~2\OpenSSL-Win32
set OPENSSL_CONF=%OPENSSL_DIR%\bin\openssl.cfg
set PATH=C:\Python383-x86;%OPENSSL_DIR%\bin;%LLVM_INSTALL_DIR%\bin;%PATH%
..\qt-everywhere-src-6.7.2-x64\configure -platform win32-msvc -prefix C:\Qt\6.7.2-x86 -opengl desktop -skip qtlocation -skip qtwebview -skip qtwebengine -nomake tests -nomake examples

then run:
configure_windows_32
cmake –build . –parallel
cmake –install .
cmake –build . –target docs
cmake –build . –target install_docs

And that gets you a Qt installation with docs on Windows. Note you don’t need docs on both platforms, and you can use the precompiled LLVM for x64 that Qt has somewhere on its support site, however there is no x86 LLVM (as officially it is ‘unsupported’, despite there being countless end users still running 32 bit windows). So if you need to compile 32 bit Qt applications you’ll need to build LLVM as above.

Leave a Reply