How to build Qt¶
The official documentation for building Qt from sources is available at https://doc.qt.io/qt-6/build-sources.html.
Note: These instructions are for building the open-source version of Qt. If you have a commercial license, please use the corresponding binaries using the official Qt Installer.
System Requirements¶
Git >= 1.6.x
CMake >= 3.18.4
Ninja (required on Windows for Qt > 6.8 and on MacOS for all versions)
A C++ compiler supporting C++17
For Qt < 6.7: Perl >= 5.14 (e.g. Strawberry Perl)
Python >= 2.6
Windows: A C++ development environment such as MS Visual Studio >= 2019 or MinGW >= 11.2
Linux: OpenGL development libraries (libgl-dev, libegl-dev, libinput-dev, libfontconfig1-dev)
MacOS: Xcode with the clang toolchain (Xcode 13 for Qt < 6.5, Xcode 15 for Qt >= 6.5)
Getting the Sources¶
Official source code is available at code.qt.io:
cd <source_folder>
git clone https://code.qt.io/qt/qt5.git
Note: Although the URL contains Qt5, the sources also contain the Qt6 code.
Alternatively, the exact source files used to build the current Qat version can be provided: please open an issue on the Qat’s Gitlab project and an archive will be sent to you.
Checkout the version you want to use:
# Switch to latest version of branch X.Y
git switch X.Y
# or use specific version
git switch X.Y.Z
Run the init-repository script to get the submodules:
Linux and MacOS:¶
./init-repository --module-subset=default,-qtwebengine
Windows:¶
For Qt < 6.7:
perl .\init-repository.pl --module-subset=default,-qtwebengine
For Qt >= 6.7:
.\init-repository.bat --module-subset=default,-qtwebengine
Please refer to Building_Qt_5_from_Git or Building_Qt_6_from_Git for more details.
Setup¶
Windows only:¶
Make sure your your compiler and Python executables are found in your PATH environment variable.
[Qt < 6.7] Make sure your compiler is before Perl in the PATH variable since Perl comes with version of g++ (8.3) that is not compatible with Qt 5.
[Qt < 6.7] Also make sure that Perl is before Git in the PATH variable since Git comes with version of Perl that is not compatible with Qt.
You may also need to add <source_folder>/qtbase/bin, <source_folder>/gnuwin32/bin to the PATH variable.
Configure¶
Create an empty build folder and call the configure script. It is recommended to create the build folder as a sibling of the source folder.
Windows:¶
Make sure to use a Visual Studio command prompt “x64 Native Tools Command Prompt for VS 20XX”
cd <source_folder>
cd ..
mkdir <build_folder>
cd <build_folder>
..\<source_folder>\configure -opensource -confirm-license -nomake examples -nomake tests -release -prefix <install_folder>
Where <install_folder> if the folder where the Qt binaries will be generated. This is the folder the CMAKE_PREFIX_PATH CMake variable should point to when building Qat or any other Qt application.
To select the C++ toolchain, you can pass the additional -platform argument to the configure script. Supported toolchain values are:
Linux:¶
linux-clang
linux-g++
linux-g++-32
Windows:¶
win32-g++
win32-msvc
MacOS:¶
On MacOS, you can select the target architecture(s) with a CMake variable and create universal libraries:
./configure <other arguments> -- -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64"
Note: arm64 and universal builds are not supported on Qt5.
Note: Intel architecture (“x86_64”) must be specified first, otherwise Qt may not enable all the x86 functionality.
Note: When building Qt < 6.5 with a recent MacOS version (e.g. Sonoma), the configure script may generate errors related to OpenGL. In such cases, a workaround is to remove the following lines from <qt_sources>/qtbase/cmake/FindWrapOpenGL.cmake:
if (NOT __opengl_fw_path)
# Just a safety measure...
set(__opengl_fw_path "-framework OpenGL")
endif()
Build¶
The build process is managed by CMake:
cd <build_folder>
cmake --build . --parallel
cmake --install .
When building Qt 5.X on Windows, the build process is managed by make or mingw32-make:
cd <build_folder>
mingw32-make
mingw32-make install
At this point, Qt should be available in your <install_folder> so you can use it in other applications.