Windows 上源码构建 Qt5
Table of Contents
1. 系统要求
- Perl 5.8 或更高版本,安装 Strawberry Perl
- Python 2.7 或更高版本,安装 Python
- 支持 C++11 标准的 C++ 编译器,安装 VS 2022
有关其他平台的具体要求,请参阅以下页面的 "Setting up your machine" 部分 | 获取源码
2. 许可证
- 开源用户 <license> = -opensource
- 商业用户 <license> = -commercial
3. Windows
打开命令提示符。确保以下工具可以在路径中找到:
- 支持的编译器(Visual Studio 2012 或更高版本, MinGW-builds gcc 4.9 或更高版本)
- Perl 5.12 或更高版本 http://www.activestate.com/activeperl/
- Python 2.7 或更高版本 http://www.activestate.com/activepython/
Ruby 1.9.3 或更高版本 http://rubyinstaller.org/
unzip qt-everywhere-opensource-src-5.15.18.zip cd qt-everywhere-src-5.15.18 set CL=/MP32 rem configure -prefix qtbase -opensource -nomake tests rem configure -prefix "C:\Qt\Qt5.15.8" -shared -release -nomake tests -opensource -confirm-license configure -prefix "C:\Qt\Qt5.15.8" -shared -release -nomake tests -skip qtwebengine -opensource -confirm-license nmake nmake --install
为了加速 MSVC 下 qmake 的引导过程,可以在 configure 命令行中传递 "-make-tool jom"。如果不使用 jom, 将 "/MP" 添加到 CL 环境变量中是个不错的主意。
4. 构建!
使用典型的 `configure; make` 构建过程。一些相关的 configure 选项(请参阅 configure -help):
- -release 编译和链接 Qt 时关闭调试功能。
- -debug 编译和链接 Qt 时打开调试功能。
- -nomake tests 禁用测试构建以加快编译速度
- -nomake examples 禁用示例构建以加快编译速度
- -confirm-license 自动确认 LGPL 2.1 许可证。
4.1. 构建示例
C:\Qt\qt-everywhere-src-5.15.18> configure -prefix "C:\Qt\Qt5.15.8" -shared -release -nomake tests -skip qtwebengine -opensource -confirm-license
+ cd qtbase
+ C:\Qt\qt-everywhere-src-5.15.18\qtbase\configure.bat -top-level -prefix "C:\Qt\Qt5.15.8" -shared -release -nomake tests -skip qtwebengine -opensource -confirm-license
Bootstrapping qmake ...
Microsoft (R) 程序维护实用工具 14.44.35222.0 版
版权所有 (C) Microsoft Corporation。 保留所有权利。
cl -c -Fo./ -Fdqmake.pdb -W2 -nologo -O2 /MP /wd4577 -IC:\Qt\qt-everywhere-src-5.15.18\qtbase\qmake -IC:\Qt\qt-everywhere-src-5.15.18\qtbase\qmake\library -IC:\Qt\qt-everywhere-src-5.15.18\qtbase\qmake\generators -IC:\Qt\qt-everywhere-src-5.15.18\qtbase\qmake\generators\unix -IC:\Qt\qt-everywhere-src-5.15.18\qtbase\qmake\generators\win32 -IC:\Qt\qt-everywhere-src-5.15.18\qtbase\qmake\generators\mac -IC:\Qt\qt-everywhere-src-5.15.18\qtbase/src/3rdparty/tinycbor/src -IC:\Qt\qt-everywhere-src-5.15.18\qtbase/include -IC:\Qt\qt-everywhere-src-5.15.18\qtbase/include\QtCore -IC:\Qt\qt-everywhere-src-5.15.18\qtbase/include\QtCore\5.15.18 -IC:\Qt\qt-everywhere-src-5.15.18\qtbase/include\QtCore\5.15.18\QtCore -I..\src\corelib\global -IC:\Qt\qt-everywhere-src-5.15.18\qtbase\mkspecs\win32-msvc -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS -DQT_VERSION_STR=\"5.15.18\" -DQT_VERSION_MAJOR=5 -DQT_VERSION_MINOR=15 -DQT_VERSION_PATCH=18 -DQT_BUILD_QMAKE -DQT_BOOTSTRAPPED -DPROEVALUATOR_FULL -DQT_NO_FOREACH -DUNICODE -D_ENABLE_EXTENDED_ALIGNED_STORAGE -c -Yc -Fpqmake_pch.pch -TP C:\Qt\qt-everywhere-src-5.15.18\qtbase\qmake\qmake_pch.h
qmake_pch.h权所有 (C) Microsoft Corporation。 保留所有权利。
>>>>>>>>>> 此处省略一千万字 <<<<<<<<<<
Configure summary:
Build type: win32-msvc (x86_64, CPU features: sse sse2)
Compiler: msvc 194435222
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 release c++11 c++14 c++17 c++1z concurrent dbus no-pkg-config stl
Build options:
Mode ................................... release
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
Qt Gui ................................. yes
Qt Network ............................. yes
Qt Sql ................................. yes
Qt Testlib ............................. yes
Qt Widgets ............................. yes
Qt Xml ................................. yes
Support enabled for:
Using pkg-config ....................... no
udev ................................... no
Using system zlib ...................... no
Zstandard support ...................... no
Qt Core:
DoubleConversion ....................... yes
Using system DoubleConversion ........ no
GLib ................................... no
iconv .................................. no
ICU .................................... no
Built-in copy of the MIME database ..... yes
Tracing backend ........................ <none>
Logging backends:
journald ............................. no
syslog ............................... no
slog2 ................................ no
PCRE2 .................................. yes
Using system PCRE2 ................... no
Qt Network:
getifaddrs() ........................... no
IPv6 ifname ............................ no
libproxy ............................... no
Schannel ............................... no
OpenSSL ................................ no
Qt directly linked to OpenSSL ........ no
OpenSSL 1.1 ............................ no
DTLS ................................... no
OCSP-stapling .......................... no
SCTP ................................... no
Use system proxies ..................... yes
GSSAPI ................................. no
Qt Gui:
Accessibility .......................... yes
FreeType ............................... yes
Using system FreeType ................ no
HarfBuzz ............................... yes
Using system HarfBuzz ................ no
Fontconfig ............................. no
Image formats:
GIF .................................. yes
ICO .................................. yes
JPEG ................................. yes
Using system libjpeg ............... no
PNG .................................. yes
Using system libpng ................ no
Text formats:
HtmlParser ........................... yes
CssParser ............................ yes
OdfWriter ............................ yes
MarkdownReader ....................... yes
Using system libmd4c ............... no
MarkdownWriter ....................... yes
EGL .................................... yes
OpenVG ................................. no
OpenGL:
ANGLE ................................ yes
Combined ANGLE Library ............... no
Desktop OpenGL ....................... no
Dynamic OpenGL ....................... yes
OpenGL ES 2.0 ........................ no
OpenGL ES 3.0 ........................ no
OpenGL ES 3.1 ........................ no
OpenGL ES 3.2 ........................ no
Vulkan ................................. no
Session Management ..................... yes
Features used by QPA backends:
evdev .................................. no
libinput ............................... no
INTEGRITY HID .......................... no
mtdev .................................. no
tslib .................................. no
xkbcommon .............................. no
X11 specific:
XLib ................................. no
XCB Xlib ............................. no
EGL on X11 ........................... no
xkbcommon-x11 ........................ no
QPA backends:
DirectFB ............................... no
EGLFS .................................. no
LinuxFB ................................ no
VNC .................................... no
Windows:
Direct 2D ............................ yes
DirectWrite .......................... yes
DirectWrite 2 ........................ yes
Qt Sql:
SQL item models ........................ yes
Qt Widgets:
GTK+ ................................... no
Styles ................................. Fusion Windows WindowsVista
Qt PrintSupport:
CUPS ................................... no
Qt Sql Drivers:
DB2 (IBM) .............................. no
InterBase .............................. no
MySql .................................. no
OCI (Oracle) ........................... no
ODBC ................................... yes
PostgreSQL ............................. no
SQLite2 ................................ no
SQLite ................................. yes
Using system provided SQLite ......... no
TDS (Sybase) ........................... no
Qt Testlib:
Tester for item models ................. yes
Serial Port:
ntddmodm ............................... yes
Qt SerialBus:
Socket CAN ............................. no
Socket CAN FD .......................... no
SerialPort Support ..................... yes
Further Image Formats:
JasPer ................................. no
MNG .................................... no
TIFF ................................... yes
Using system libtiff ................. no
WEBP ................................... yes
Using system libwebp ................. no
Qt QML:
QML network support .................... yes
QML debugging and profiling support .... yes
QML just-in-time compiler .............. yes
QML sequence object .................... yes
QML XML http request ................... yes
QML Locale ............................. yes
Qt QML Models:
QML list model ......................... yes
QML delegate model ..................... yes
Qt Quick:
Direct3D 12 ............................ yes
AnimatedImage item ..................... yes
Canvas item ............................ yes
Support for Qt Quick Designer .......... yes
Flipable item .......................... yes
GridView item .......................... yes
ListView item .......................... yes
TableView item ......................... yes
Path support ........................... yes
PathView item .......................... yes
Positioner items ....................... yes
Repeater item .......................... yes
ShaderEffect item ...................... yes
Sprite item ............................ yes
QtQuick3D:
Assimp ................................. yes
System Assimp .......................... no
Qt Scxml:
ECMAScript data model for QtScxml ...... yes
Qt Gamepad:
SDL2 ................................... no
Qt 3D:
Assimp ................................. yes
System Assimp .......................... no
Output Qt3D GL traces .................. no
Use SSE2 instructions .................. yes
Use AVX2 instructions .................. no
Aspects:
Render aspect ........................ yes
Input aspect ......................... yes
Logic aspect ......................... yes
Animation aspect ..................... yes
Extras aspect ........................ yes
Qt 3D Renderers:
OpenGL Renderer ........................ yes
RHI Renderer ........................... no
Qt 3D GeometryLoaders:
Autodesk FBX ........................... no
Qt Wayland Client ........................ no
Qt Wayland Compositor .................... no
Qt Bluetooth:
BlueZ .................................. no
BlueZ Low Energy ....................... no
Linux Crypto API ....................... no
Native Win32 Bluetooth ................. no
WinRT Bluetooth API (desktop & UWP) .... yes
WinRT advanced bluetooth low energy API (desktop & UWP) . yes
Qt Sensors:
sensorfw ............................... no
Qt Quick Controls 2:
Styles ................................. Default Fusion Imagine Material Universal
Qt Quick Templates 2:
Hover support .......................... yes
Multi-touch support .................... yes
Qt Positioning:
Gypsy GPS Daemon ....................... no
WinRT Geolocation API .................. yes
Qt Location:
Qt.labs.location experimental QML plugin . no
Geoservice plugins:
OpenStreetMap ........................ yes
HERE ................................. yes
Esri ................................. yes
Mapbox ............................... yes
MapboxGL ............................. no
Itemsoverlay ......................... yes
Qt Multimedia:
ALSA ................................... no
GStreamer 1.0 .......................... no
GStreamer 0.10 ......................... no
Video for Linux ........................ no
OpenAL ................................. no
PulseAudio ............................. no
Resource Policy (libresourceqt5) ....... no
Windows Audio Services ................. yes
DirectShow ............................. yes
Windows Media Foundation ............... yes
Qt TextToSpeech:
Flite .................................. no
Flite with ALSA ........................ no
Speech Dispatcher ...................... no
Qt Tools:
Qt Assistant ........................... yes
Qt Designer ............................ yes
Qt Distance Field Generator ............ yes
kmap2qmap .............................. yes
Qt Linguist ............................ yes
Mac Deployment Tool .................... no
makeqpf ................................ yes
pixeltool .............................. yes
qdbus .................................. yes
qev .................................... yes
Qt Attributions Scanner ................ yes
qtdiag ................................. yes
qtpaths ................................ yes
qtplugininfo ........................... yes
Windows deployment tool ................ yes
WinRT Runner Tool ...................... no
Qt Tools:
QDoc ................................... no
Note: No wayland-egl support detected. Cross-toolkit compatibility disabled.
WARNING: QDoc will not be compiled, probably because libclang could not be located. This means that you cannot build the Qt documentation.
Either ensure that llvm-config is in your PATH environment variable, or set LLVM_INSTALL_DIR to the location of your llvm installation.
On Linux systems, you may be able to install libclang by installing the libclang-dev or libclang-devel package, depending on your distribution.
On macOS, you can use Homebrew's llvm package.
On Windows, you must set LLVM_INSTALL_DIR to the installation path.
Qt is now configured for building. Just run 'nmake'.
Once everything is built, you must run 'nmake install'.
Qt will be installed into 'C:\Qt\Qt5.15.8'.
Prior to reconfiguration, make sure you remove any leftovers from
the previous build.
// 下面开启多核并行编译
C:\Qt\qt-everywhere-src-5.15.18> set CL=/MP8
C:\Qt\qt-everywhere-src-5.15.18> nmake
Microsoft (R) 程序维护实用工具 14.44.35222.0 版
版权所有 (C) Microsoft Corporation。 保留所有权利。
cd qtbase\ && ( if not exist Makefile C:\Qt\qt-everywhere-src-5.15.18\qtbase\bin\qmake.exe -o Makefile C:\Qt\qt-everywhere-src-5.15.18\qtbase\qtbase.pro ) && "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\bin\HostX64\x64\nmake.exe" -f Makefile
Info: creating cache file C:\Qt\qt-everywhere-src-5.15.18\qtbase\.qmake.cache
Microsoft (R) 程序维护实用工具 14.44.35222.0 版
版权所有 (C) Microsoft Corporation。 保留所有权利。
cd src\ && ( if not exist Makefile C:\Qt\qt-everywhere-src-5.15.18\qtbase\bin\qmake.exe -o Makefile C:\Qt\qt-everywhere-src-5.15.18\qtbase\src\src.pro ) && "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\bin\HostX64\x64\nmake.exe" -f Makefile
4.2. 开发者版本构建示例
./configure -developer-build <license> make -j4
有关 configure 的各种选项的文档,请参阅 `./configure -help' 的输出。
上述示例将构建构建系统中默认启用的所有 Qt5 模块。
可以通过执行 `make module-<foo>' 来构建选定的模块及其依赖项。例如,仅构建 qtdeclarative 及其依赖的模块:
./configure -prefix $PWD/qtbase <license>
make -j4 module-qtdeclarative
如果您只对 Qt5 的一个子集感兴趣,这可以节省大量时间。
4.3. 提示
子模块仓库 qtrepotools 包含对开发人员和发布工程师有用的脚本。考虑将 qtrepotools/bin 添加到您的 PATH 环境变量中以访问它们。
qtrepotools 中的 qt5_tool 有一些可能感兴趣的更多功能。 请尝试 `qt5_tool –help'。
5. 从 git 构建 Qt5
有关更多信息,请参阅 http://wiki.qt.io/Building_Qt_5_from_Git 和 README.git。 有关参考平台,请参阅 http://wiki.qt.io/Qt_5。
6. 文档
配置和编译 Qt 后,可以通过运行 "make docs" 来构建文档。
构建文档后,您需要使用以下命令安装它:
make install_docs
文档安装在设置为 $QT_INSTALL_DOCS 的路径中。 运行 "qmake -query" 将列出 QT_INSTALL_DOCS 的值。
有关 Qt 5 文档的信息位于 qtbase/doc/README 中,或在以下页面:http://wiki.qt.io/Qt5DocumentationProject
注意:文档构建仅在桌面平台上进行了测试。