Just in the project file contains a code before compiling the complete automatic packaging dependencies program . (End the source address)
Instructions
- Method one: Copy this code to your script project file (.pro) in.
- Method two: included in the project file pro in the script file can be.
Realization of the principle
- The qmake of
QT
obtaining the corresponding module variable, when the packaging will be selectively packaged . - Packed before will scan the local qml file , find the need to package dependent libraries (plug-in).
- Qmake by acquiring packaging tools provided by the official Qt path where the package and call the realization of the work program.
- Since acquiring Qt qmake official packaging tool where the path is easy, without having to manually set the path would be more convenient to use.
- The parameter determination may also be provided qmake packaging tools (
windeployqt.exe
) command parameters.
Additional features
About using the features described in detail in scripting tools.
- Since QtCreator originally included more
debug
andrelease
configuration variables, this will lead to very slow qmake, this script qmake tool can optimize the speed, but the default is not open , because it is an experimental feature. - Debug output macro, the default is not open .
- Automatically open the package after the completion of the target directory, enabled by default .
Subsequent updates
- Currently only supports windows platform, follow-up will support more platforms.
- For third-party libraries packaged function.
- Optimization module selectively packaged function.
- QML packed optimization function.
- Optimization package missing library.
Part of the source code
# 获取从QMake执行文件的所在目录得出Qt的bin路径
QT_BIN_DIR = $$replace(QMAKE_QMAKE, ^(\S*/)\S+$, \1)
# 获取Qt开发环境路径
QT_DIR = $${QT_BIN_DIR}../
# Qt打包工具参数配置集合
DEPLOY_OPTIONS += --force
# 可用的Qt模块
QT_AVAILABLE_LIBRARY_LIST = \
bluetooth concurrent core declarative designer designercomponents enginio \
gamepad gui qthelp multimedia multimediawidgets multimediaquick network nfc \
opengl positioning printsupport qml qmltooling quick quickparticles quickwidgets \
script scripttools sensors serialport sql svg test webkit webkitwidgets \
websockets widgets winextras xml xmlpatterns webenginecore webengine \
webenginewidgets 3dcore 3drenderer 3dquick 3dquickrenderer 3dinput 3danimation \
3dextras geoservices webchannel texttospeech serialbus webview
# 扫描QT变量用于打包模块的参数配置
for (LIBRARY_MODULE, QT_AVAILABLE_LIBRARY_LIST) {
if (contains(QT, $$LIBRARY_MODULE)) {
DEPLOY_OPTIONS += --$$LIBRARY_MODULE
}
else {
DEPLOY_OPTIONS += --no-$$LIBRARY_MODULE
}
}
# 针对Qml模块配置打包参数
if (contains(QT, quick)) {
DEPLOY_OPTIONS -= --no-qml
DEPLOY_OPTIONS += --qml
DEPLOY_OPTIONS -= --no-network
DEPLOY_OPTIONS += --network
DEPLOY_OPTIONS += --qmldir $${QT_DIR}qml/
}
if (!isEmpty(DESTDIR)) {
# 如有设置目标输出路径则定向于该路径
TARGET_OUT_DIR = $$OUT_PWD/$$DESTDIR/
}
else {
# 判断是debug版本还是release版本
CONFIG(debug, debug|release) {
TARGET_OUT_DIR = $${OUT_PWD}/debug/
DEPLOY_OPTIONS += --debug
}
else {
TARGET_OUT_DIR = $${OUT_PWD}/release/
DEPLOY_OPTIONS += --release
}
}
# 实验性功能
!isEmpty(EXPERIMENTAL) {
# 该功能(用于优化qmake调试输出)是否开放还需待定,因为会导致其他未知的问题。
CONFIG = $$remove_extra_config_parameter($$CONFIG)
}
# 调试输出
!isEmpty(DEBUG_LOGGER) {
message(TARGET_OUT_DIR: $$TARGET_OUT_DIR) # 生成文件的输出目录
message(QMAKE_POST_LINK: $$QMAKE_POST_LINK) # 打印命令
}
win32 {
# 拼接Qt部署程序的文件(windows平台下为windeployqt.exe)
WIN_DEPLOY_BIN = $${QT_BIN_DIR}windeployqt.exe
# 编译完成后执行打包命令
QMAKE_POST_LINK += $$WIN_DEPLOY_BIN $$DEPLOY_OPTIONS $$TARGET_OUT_DIR$${TARGET}.exe
# 扫描Qml依赖库,并在编译完成后自动复制qml依赖库到目标目录
QMAKE_POST_LINK += $$get_copy_qml_library_cmd_line($$QT_DIR, $$QT_BIN_DIR, $$TARGET_OUT_DIR, $$RESOURCES)
!isEmpty(DEPLOY_COMPLETE_AUTO_OPEN_EXPLORER) {
# 打包完成后自动打开目标路径
QMAKE_POST_LINK += && start $$TARGET_OUT_DIR
}
}
Source Address
Welcome to collaborate together to improve.
https://github.com/aeagean/DeployByQmake