Source code compilation Qt 5.15.9+msvc2019

Detailed steps are given in the official documentation:
Building Qt Sources
Building Qt 5 from Git (Wiki)

Note: This article is based on windows11 + vs2019x64 + qt5.15.9, Qt WebEngine is not compiled

The summary is as follows:

Preparatory phase

Qt for Windows-Requirements

  • Install python. I am using anaconda python 3.11, which requires 2.7 or above. You can also download it directly from the official website: https://www.python.org/downloads/

  • Install perl. What I installed here is strawberry-perl-5.32.1.1-64bit.msi, which requires 5.12 or above. Download address: https://strawberryperl.com/releases.html

  • Install ruby (optional). Ruby is used to compile WebKit. If you don’t compile this module, you probably won’t need it (I haven’t tested it). What I installed here is rubyinstaller-3.2.2-1-x64.exe, download address: https://rubyinstaller.org/2023/04/01/rubyinstaller-3.2.2-1-3.1 .4-1-3.0.6-1-and-2.7.8-1-released.html

  • Install clang (optional), which is required when compiling qtdoc. It affects the reference documentation in Qt Assistant. If it is compiled, you can view the reference documentation in the help of qt designer. What I installed here is LLVM-11.0.0-win64.exe. In fact, the qt official website provides the vs2019 version libclang-release_140-based-windows-vs2019_64, download address: https://download. qt.io/development_releases/prebuilt/libclang/

  • Install openssl (optional), required when compiling Qt Network, in order to support Secure Sockets Layer (SSL). Here I download the source code and compile it myself (tutorial), openssl-1.1.1w.tar.gz, download address: https://www.openssl.org/source/

  • Install ICU (optional), which is also required when compiling WebKit. For UNICODE and Localization, since I have not used it, I have not studied it.

  • Install jom (optional), a tool provided by Qt, which can achieve parallel compilation and improve compilation speed. What I installed here is jom_1_1_4.zip. The official website often cannot be opened. You can download it from the mirror source https://mirrors.tuna.tsinghua.edu.cn/qt/official_releases/jom/

  • Download the Qt source code. The official website often cannot be opened. You can go to the mirror source to download qt-everywhere-opensource-src-5.15.9.zip.

Install all the above things under the English path. Pay attention to the directory name as short as possible and without spaces. Check the system environment PATH to ensure that the environment is set up. My settings are as follows:

E:\qt-everywhere-src-5.15.9\gnuwin32\bin
E:\qt-everywhere-src-5.15.9\qtbase\bin
E:\anaconda3
C:\Strawberry\c\bin
C:\Strawberry\perl\site\bin
C:\Strawberry\perl\bin
E:\Ruby\bin
E:\jom

in,
E:\qt-everywhere-src-5.15.9 is the qt source code directory
E:\anaconda3 is the python directory,

Compilation phase

1. Find x64 Native Tools Command Prompt for VS 2019 in the start and run it with administrator privileges

2. Go to the Qt source code directory

E:
cd E:\qt-everywhere-src-5.15.9

3. Configuration

Note: Each configure must be based on a clean source code directory. If you have configured it before, you must first execute jom distclean (or nmake distclean). Actual testing is very time-consuming, so it is better to do it directly Delete the source code directory and re-unzip it

set LLVM_INSTALL_DIR=E:\LLVM
configure -prefix "E:\Qt\5.15.9\msvc2019_64" -shared -debug-and-release -verbose -nomake tests -skip qtwebengine -opensource -confirm-license -opengl dynamic -openssl-runtime OPENSSL_INCDIR="D:\ openssl\vc16_x64\include"

in,
set LLVM_INSTALL_DIR=E:\LLVM is the environment for setting LLVM. If it is not specified, the qtdoc module will not be compiled. This sentence is only needed to compile qtdoc.

configure -help can view the parameter description of configure. Only the parameters used above are given here.

-prefix "E:\Qt\5.15.9\msvc2019_64" installation path, which will be output to this path after executing install
-shared generates a dynamic link library. Correspondingly, -static is a static library. If neither is specified, the default is -shared.
-debug-and-release generates two versions of the library, debug and release. You can also specify one of them separately, -debug or -release. If neither is specified, the default is -release.
-verbose prints detailed information during the configure process to facilitate troubleshooting
-nomake tests generates the following parts (parts) by default: libs, examples, tools, tests. This is to tell the compiler not to generate the tests part.
-skip qtwebengine skips a certain module, qtwebengine is not compiled here, it will be very time-consuming
-opensource means that we are compiling an open source version. Correspondingly, -commercial means a commercially licensed version.
-confirm-license Automatically confirm license
-opengl dynamic dynamically loads graphics drivers. This method is officially recommended. For details, see the "Graphics Drivers" section of "Qt for Windows - Requirements".
-openssl-runtime OPENSSL_INCDIR="D:\openssl\vc16_x64\include" Set openssl, you can also not fill in this parameter. Here is the dynamic link method. There are dynamic link display loading, dynamic link implicit loading, and static library 3 For details, see the "Libraries" section of "Qt for Windows - Requirements"

After configure is completed, it will print the status of each module, which can also be viewed in the config.summary file in the source directory.

Build type: win32-msvc (x86_64, CPU features: sse sse2)
Compiler: msvc 192930152
Configuration: sse2 aesni sse3 ssse3 sse4_1 sse4_2 avx avx2 avx512f avx512bw avx512cd avx512dq avx512er avx512ifma avx512pf avx512vbmi avx512vl compile_examples f16c largefile precompile _header rdrnd rdseed shani x86SimdAlways shared shared debug_and_release release debug build_all c++11c++14c++17c++1z concurrent dbus no-pkg-config release_tools stl
Build options:
  Mode ........................................ debug and release; default link: debug; optimized tools
  Optimize release build for size ........no
  Building shared libraries............ yes
  Using C standard......................C89
  Using C++ standard........................C++17
  Relocatable........................ yes
  Using precompiled headers ............ yes
  Using LTCG ........................ no
  Target compiler supports:
    SSE .................................. SSE2 SSE3 SSSE3 SSE4.1 SSE4.2
    AVX ............................ AVX AVX2
    AVX512 ............................ F ER CD PF DQ BW VL IFMA VBMI
    Other x86 ............................ AES F16C RDRAND SHA
  Build parts ........................ libs examples tools
  App store compliance........................no
Qt modules and options:
  Qt Concurrent........................ yes
  Qt D-Bus........................ yes
  Qt D-Bus directly linked to libdbus .... no
  QtGui ............................. yes
  Qt Network ............................ yes
  Qt SQL ........................................ yes
  Qt Testlib ........................................ yes
  Qt Widgets ............................. yes
  QtXml ............................. yes
  ...

4. Compile

jom -j20

The following -j20 represents the number of threads, because my CPU is i5-13500HX, 14 cores and 20 threads
Of course, you can also use the nmake command. Regardless of whether you use jom or nmake, subsequent instructions must use the corresponding ones, otherwise an error will be reported.
CPU usage of the compilation process:

This is what it looks like after successful compilation

Time taken on my machine (i5-13500HX + SSD PCIE4.0 7000MB/s) 70 minutes

5. Installation

jom -j20 install

If you just used nmake to compile, you need to use nmake install here.
It will copy the compiled files to the directory specified by -prefix in configure
It took 60 minutes on my machine

6. Compile reference documents

jom docs

If you just used nmake to compile, you need to use nmake docs here.

7. Installation reference documents

jom install_docs

If you just used nmake to compile, you need to use nmake install_docs here.

During the actual measurement, it was stuck in sqldriver for a long time, and ctrl + c skipped it.
After the installation is successful, run the designer and open “Qt Designer Help” to see the reference document. If the following information is printed in step 3, steps 6 and 7 will not succeed. The content in “Qt Designer Help” is: null

Qt Tools:
  QDoc........................ no
  
  WARNING: QDOC will not be compiled, probably because libclang could not be located. This means theat you cannot build the Qt ducomentation.
...
On Windows, you must set LLVN_INSTALL_DIR to the installation path.
...