Build Qt5.15.11 for Windows 10 and 11 Pro with Qt Webengine and VS2019 Community

We will do this in two steps. First, we build the Qt Lib and skip Qt Webengine. This is not mandatory, but will make your life much easier in case of some fails. Compiling the main lib is a piece of cake compared to QWebengine. You can also use all your cpu cores without concerns.

Dancing program,mer in front of a macbook and Qt cup

Build Qt Lib

The following sections will outline the prerequisites, tools, and setup necessary to compile Qt on your machine. So, let's get started first by mastering the Qt lib build process!

Requirements for Qt-Lib

  • OpenSSL 1.1.1w Source or Binaries You can take an older or newer version than w. It is only important to use 1.1.1 as Qt5.15 does not support older versions as default anymore.
  • Install vs2019 llvm from qt download server and set LLVM_INSTALL_DIR=YOUR_PATH if you want to create QDoc. Do not take the latest version from LLVM GitHub because Qt config won't recognize it.
  • Qt5.15.11 Source code. It is recommended to extract it in C:\Qt\
    You can unpack with on-board tools:
    Expand-Archive -Force .\qt-everywhere-opensource-src-5.15.11.zip C:\Qt\
    But that takes an incredible amount of time.

    Better solution: Install 7-Zip and use the command line.
    'C:\Program Files\7-Zip\7z.exe' x .\qt-everywhere-opensource-src-5.15.11.zip
  • Install Visual Studio 2019 Community and Windows 10.0.19041.0 SDK. It is important to install also C++ ATL for the correspondingh build-tools version. Otherwise compile can fail.

Build Steps for Qt-Lib

  1. Open the Visual Studio x64 native tool command line prompt.
  2. Create a shadow directory and enter it.

    A shadow build directory is very helpful when building Qt software or C++ in general. Using a shadow build directory, keeps the source code separate from build artifacts, allows for multiple build configurations, simplifies cleanup and more.

    mkdir build_qt
    cd build_qt
    
  3. Call configure.bat in the directory of the source.
    \PATH_TO_QT_SOURCE\configure -platform win32-msvc -opensource -confirm-license ^
     -I "C:\Program Files\OpenSSL-Win64\include" -L "C:\Program Files\OpenSSL-Win64\lib" ^
     -prefix C:\Qt\5.15.11 ^
     -debug-and-release -nomake examples -nomake tests -silent ^
     -skip qtwayland ^
     -skip qtactiveqt ^
     -skip qtserialport ^
     -skip qtwebengine
    

    Some hints

    • Wayland, ActiveQt, and SerialPort are not necessary for garlic-player. As said above, we handle Webengine later.
    • The parameter -debug-and-release will build both. It is helpful if you want to debug things. If not, you can use -release only.
    • -prefix C:\Qt\5.15.11 says that a nmake install will install created Qt binaries on this directory.

    This will build qmake.exe and some other stuff. It will complain about QDoc if you do not install LLVM.

    In case of errors or something is missing, you will get a more or less detailed notice. If everything is fine, continue to the next step.

  4. Call nmake with multicore support.
    set CL=/MP
    nmake
    

    There is also a nmake replacement from Qt-labs called jom. Jom is a parallel make tool for Windows. You can use it here securely, but better not for Qt Webengine. If you previously installed Qt via their Maintenance Tool, you will find it in %QtDIR%\Tools\QtCreator\bin\jom\jom.exe

    Sit back, drink some beverage, or do start to brainstorm a plan to conquer the world. Depending on your CPU, this process will need some time to finish. My Geekom AS6 required about 20 min. It consumed 100% CPU and about 11 GB of memory.

  5. Install compiled lib to -prefix directory.
    nmake install
    This will take some minutes.

The Pain Queen: Qt Webengine

Welcome to the exclusive club of compiling Qt Webengine, where the only thing more unpredictable than the British weather is whether your build will breeze through or crash and burn at 80%. To find out the correct parameters how to compile this on a fresh installed Geekom AS6 NUC with 32 GB RAM, 1 TB NVMe, and a Ryzen 7735HS with Windows 11 Pro costs me some time.

Requirements and Preparatory Work for Qt Webengine

  • Install GNU Bison, Flex, and GPerf.
  • Install ActivePerl or StrawberryPerl.
  • Install Python 2.7. Do not use Python 3, as it is not compatible.
  • Install Node.js version 18 or newer. LTS version is recommended.
  • Optional: Install ninja.

    Ninja is a small build system with a focus on speed, but with some caveats. Webengine comes with an own ninja implementation. You activate it with the qmake option: -no-feature-webengine-system-ninja. Sometimes it helps, sometimes not. Qt also comes with a ninja.exe in C:\Qt\Tools\Ninja.

    If you decide to use the latest ninja.exe from GitHub or the version from Qt, put it in your search path.

  • You should also turn on NTFS long path name support to reduce the risk of the compilation failing. Keep also for sure the paths as short as possible.
    • Windows 10: Navigate to Local Computer Policy > Computer Configuration > Administrative Templates > System > Filesystem > NTFS.
    • Windows 11: Navigate to Local Computer Policy > Computer Configuration > Administrative Templates > System > Filesystem.
    Double-click the “Enable NTFS long paths option” and activate it.
  • Patch file ./qtwebengine/src/buildtools/config/common.pri
    Find:
    precompile_header {
    	gn_args += enable_precompiled_headers=true
    } else {
    	gn_args += enable_precompiled_headers=false
    }
    
    and change it to:
    precompile_header {
    	gn_args += enable_precompiled_headers=false
    } else {
    	gn_args += enable_precompiled_headers=false
    }
    

    Background: The job of a precompiled header is to fasten builds. This works well in most cases for the Qt-Lib, but not for QWebengine. According to reports like QTBUG-65677 and other, it works for some people and for some not. Unfortunately, I seem to be permanently in category two. My advice: Deactivate this crap! This will increase your build time, but this was the only way to make it work on my machine.

  • Time, coffee, tea, popcorn, and some frustration residence

Build Steps for Qt Webengine

  1. Open a new Visual Studio x64 command line prompt.
  2. Create a new shadow directory and enter it.
    mkdir build_qt_webengine
    cd build_qt_webengine
    
  3. Set maximum core usage and start with the qmake you created previously.
    set CL_MPCount=8
    set NINJAFLAGS=-j8
    C:\Qt\5.15.11\bin\qmake %QT_SRC%\qtwebengine\qtwebengine.pro -- -no-webengine-jumbo-build ^
     -no-feature-webengine-system-ninja ^
     -proprietary-codecs
    

    Explanations

    You can add qmake parameters in command line after a --.

    • Restrict core usage: As maybe mentioned, ;) a chromium build demands a high amount of RAM and resources. Furthermore, Every core requires some gigabyte. If we let ninja free decide to use all available cores, the build can crash because of low memory. That is the reason we limit the core usage for nmake and ninja with CL_MPCount and NINJAFLAGS to 8. If You have 32 GB Ram ore more, you can try to raise the number.
    • -no-webengine-jumbo-build

      Jumbo build refers to a technique used to speed up the compilation of the large Chromium codebase. It combines several C++ files into one "jumbo" file before compiling, which can significantly reduce the overall build time because there are fewer files for the compiler to process individually. This method takes advantage of parallel processing and reduces overhead, making the build process more efficient.

      If it works for you fine. If not set this flag to prevent jumbo files.

    • -no-feature-webengine-system-ninja

      As mentioned before. This uses the ninja comes with QWebengine source. As long as you do not need special features of the current ninja versions, you should activate this flag.

    • -proprietary-codecs

      This flag enables support for proprietary media codecs that are not included in the standard build, such as AAC, H.264, and MP3. It allows the playback of a wider range of media formats in applications using Qt Webengine, which might be necessary for compatibility with certain web content that uses these codecs.

    • Optional -feature-pdf-v8

      This included support for the embedded V8 JavaScript engine in PDF files. This allows for interactive features within PDF documents, like forms and dynamic content, that are powered by JavaScript when rendered in the application.

      Enabling JavaScript in PDFs with the V8 engine can have security concerns. JavaScript in PDFs can be used maliciously, similar to how it can be exploited on web pages, to run harmful scripts on a user's machine. It can potentially open up avenues for various attacks, such as phishing, if a user opens a malicious PDF.

      I would recommend not to use this flag if you do not have special projects1 which require interactive PDF. I would recommend not to use this flag if you do not have special projects1 which require interactive PDF. As a side note.: PDFs are not ideal for digital signage.

  4. Call nmake and do not use jom. The build time on Ryzen 7735HS with this configuration took about 5 hours. So, prepare some dinner or continue your plan to rule the world. If everything work fine, you can try to optimize.

    Optimizations

    If you have at least 32 GB of RAM and are an adventures nature try -webengine-jumbo-build 100 or an other amount instead of -no-webengine-jumbo-build. This will allow to combine until 100 files to a jumbo compile. Furthermore, do not set CL_MPCount and NINJAFLAGS and use jom. Alternative raise the values of CL_MPCount and NINJAFLAGS with nmake.

  5. Finishing with installing compiled lib to -prefix directory.
    nmake install

Share Your Thoughts

Congratulations on completing this tutorial! By now, you should have some moore understanding of how build Qt WebEngine.

Your feedback is invaluable. If you have any comments, suggestions, or enhancements, please don't hesitate to reach out. Send your thoughts to me via email or Linked (links in footer). Whether it's a simple thank-you, a question, or a proposal for improvement, your input is what shapes the quality and direction of future content.

Thank you for following along, and happy coding!