如何制作qmake目标来创建QtIFW安装程序

时间:2017-06-08 17:19:04

标签: qmake qt-installer

我想在构建过程中自动生成安装程序,并在构建过程中对其进行一些控制。如何使用qmake设置make target来生成安装程序?

我有一个包含多个组件的subdirs项目。安装程序配置位于子目录(“installer-qt”)中。需要将文件复制到安装程序包的数据目录,然后自动运行安装程序生成器。除了构建的二进制文件之外,我还想安装文档,标题和其他资源。

1 个答案:

答案 0 :(得分:0)

这就是我想出来的。

步骤1:将文件复制到安装程序包

使用make install: 将其添加到子项目:

package_build {
    INSTALLER_PACKAGE=$$PWD/installer-qt/packages
    INSTALL_PREFIX=$$INSTALLER_PACKAGE/com.example.component1/data
} else {
    isEmpty(INSTALL_PREFIX): INSTALL_PREFIX="/opt/ExampleCorp"
}
message("Install to $$INSTALL_PREFIX")
unix {
    target.path = "$$INSTALL_PREFIX/bin"
    documentation.path = "$$INSTALL_PREFIX/doc"
    includes.path = "$$INSTALL_PREFIX/include"
    testcase|staticlib {
        INSTALLS -= target
    } else {
        INSTALLS += target
        INSTALLS += documentation
        INSTALLS += includes
    }
}
documentation.files += readme.txt
includes.files += header.h

现在,您可以在运行qmake时使用默认/ opt安装,在使用qmake INSTALL_PREFIX=/my/prefix运行qmake时指定前缀,或者在使用qmake CONFIG+=package_build运行qmake时指定复制到安装程序包

(开放式问题:如何最好地将所有内容复制到安装程序数据而不会覆盖正常的“make install”?)

第2步:构建安装程序包

在installer-qt:

中添加qmake .pro项目
TEMPLATE = subdirs # Empty project

CONFIG(release, debug|release) {
    unix: INSTALLER_OFFLINE = $$PWD/MYPROJECT-linux-x64.run
    win32: INSTALLER_OFFLINE = $$PWD/MYPROJECT-win32-x64.exe
}
CONFIG(debug, debug|release) {
    unix: INSTALLER_OFFLINE = $$PWD/MYPROJECT-linux-x64-debug.run
    win32: INSTALLER_OFFLINE = $$PWD/MYPROJECT-win32-x64-debug.exe
}
OTHER_FILES += $$PWD/config/config.xml \
    $$PWD/packages/com.example.component1/meta/package.xml
# Create the target assembly Offline Installer
QTIFWDIR = $$(HOME)/Qt/QtIFW2.0.5
offlineInstaller.target = $$INSTALLER_OFFLINE
offlineInstaller.commands = $$QTIFWDIR/bin/binarycreator --offline-only \
    -c $$PWD/config/config.xml -p $$PWD/packages $$offlineInstaller.target
offlineInstaller.depends = install
offlineInstallerTarget.target = package # This is the real name of the target
offlineInstallerTarget.depends = offlineInstaller
QMAKE_EXTRA_TARGETS += offlineInstaller offlineInstallerTarget

这足以在子目录中运行“make package”,但我们希望从顶级构建目录运行它。为此,请将其添加到顶级子目录项目:

SUBDIRS += installer-qt
offlineInstaller.target = package
offlineInstaller.depends = installer-qt mysubproject install
offlineInstaller.CONFIG = recursive
offlineInstaller.recurse = installer-qt
offlineInstaller.recurse_target = package
QMAKE_EXTRA_TARGETS += offlineInstaller

现在,您可以从构建目录运行“qmake CONFIG+= package_build /path/to/project.pro && make package”来构建安装程序。 通过转到Add Deploy Step>将其添加到QtCreator部署配置中。为“制造参数”制作并放入“包”。

资源:

https://evileg.com/en/post/164/

http://doc.qt.io/qt-5/qmake-advanced-usage.html#adding-custom-targets