前置要求
已经静态编译好的OpenSSL库,存放在C:\Program Files (x86)\OpenSSL
下:
├─bin
├─html
│ ├─man1
│ ├─man3
│ ├─man5
│ └─man7
├─include
│ └─openssl
└─lib
└─engines-1_1
Qt 5.15.2镜像: https://mirrors.tuna.tsinghua.edu.cn/qt/archive/qt/5.15/5.15.2/single/qt-everywhere-src-5.15.2.zip
执行脚本编译
运行x86 Native Tools Command Prompt for VS 2019
进入PowerShell
输入Set-ExecutionPolicy Unrestricted
.\msvc2019-build5.15.2-static.ps1
PowerShell脚本(可在编译时自行选择configure配置参数):
# OpenSSL
# 1.1.1d
$version_base = "5.15"
$version = "5.15.2"
# $qt_sources_url = "https://download.qt.io/official_releases/qt/" + $version_base + "/" + $version + "/single/qt-everywhere-src-" + $version + ".zip"
$qt_archive_file = "D:\QT\qt\5.15.2\qt-everywhere-src-5.15.2.zip"
$qt_src_base_folder = $pwd.Path + "\qt-everywhere-src-" + $version
$tools_folder = $pwd.Path + "\tools\"
$type = "static"
$prefix_base_folder = "qt-" + $version + "-" + $type + "-msvc2019-x86"
$prefix_folder = $pwd.Path + "\" + $prefix_base_folder
$build_folder = $pwd.Path + "\bld"
$openssl_base_folder = "C:\Program Files (x86)\OpenSSL"
$openssl_include_folder = $openssl_base_folder + "\include"
$openssl_libs_folder = $openssl_base_folder + "\lib"
$openssl_bin_folder = $openssl_base_folder + "\bin"
# Download Qt sources, unpack.
# $AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
# [System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols
# Invoke-WebRequest -Uri $qt_sources_url -OutFile $qt_archive_file
& "$tools_folder\7za.exe" x $qt_archive_file
# Configure.
mkdir $build_folder
cd $build_folder
& "$qt_src_base_folder\configure.bat" -debug-and-release -opensource -confirm-license -platform win32-msvc -opengl desktop -no-iconv -no-dbus -no-icu -no-fontconfig -no-freetype -qt-harfbuzz -qt-doubleconversion -nomake examples -nomake tests -no-feature-d3d12 -skip qt3d -skip qtactiveqt -skip qtcanvas3d -skip qtdatavis3d -skip qtdoc -skip qtgamepad -skip qtgraphicaleffects -skip qtlocation -skip qtpurchasing -skip qtscxml -skip qtsensors -skip qtspeech -skip qtwebview -skip qtscript -skip qtwebengine -mp -optimize-size -D "JAS_DLL=0" -static -feature-relocatable -ltcg -prefix $prefix_folder -openssl-linked -I $openssl_include_folder -L $openssl_libs_folder OPENSSL_LIBS="-lUser32 -lAdvapi32 -lGdi32 -lWS2_32 -lCRYPT32 -llibcrypto -llibssl"
# Compile.
nmake
nmake install
# Copy OpenSSL.
cp "$openssl_libs_folder\*" "$prefix_folder\lib\" -Recurse
cp "$openssl_include_folder\openssl" "$prefix_folder\include\" -Recurse
# Fixup OpenSSL DLL paths and MySQL paths.
$openssl_libs_folder_esc = $openssl_libs_folder -replace '\\','\\'
gci -r -include "*.prl" $prefix_folder | foreach-object { $a = $_.fullname; (get-content $a).Replace($openssl_libs_folder_esc, '$$$$[QT_INSTALL_LIBS]\\') | set-content $a }
# Create final archive.
& "$tools_folder\7za.exe" a -t7z "${prefix_base_folder}.7z" "$prefix_folder" -mmt -mx9
上述编译过程可能需要3至4小时不等,最终输出文件夹qt-5.15.2-static-msvc2019-x86即为编译好的源码,导入至Qt中使用即可。