QMake:构建后执行脚本

问题描述 投票:0回答:3

这用于设置 MacOSX 应用程序的应用程序包。我有一个脚本可以复制一些文件并执行其他一些操作。所以我想在构建之后执行脚本(即在链接步骤之后)。我希望它每次都执行,因为无法指定其依赖项。

我知道有

QMAKE_POST_LINK
(例如描述的herehere),但它仅在目标不存在时运行,即需要完成链接时。但是,我希望脚本每次都运行,即使目标已经存在。

还有

QMAKE_EXTRA_TARGETS
POST_TARGETDEPS
(例如,here 所描述的),但这总是强制重新链接,但我实际上只想重新运行脚本,并且它在链接之前运行脚本。 (目前,这就是我正在使用的方法,因为我没有看到更好的方法。Here是我的 QMake 源代码。)

makefile qmake
3个回答
1
投票

有相关问题那里那里。我引用我对第一个问题的回答:

按给定顺序制作东西的另一种方法是使用空的“super” 目标:

super.depends = target_pre first target_post
QMAKE_EXTRA_TARGETS += super

其中

first
- 是默认的 qmake 目标,并且
target_pre
target_post
一些自定义目标。现在
make super
就去做吧。

编辑:看起来在 Qt 的最新版本中,依赖项构建是并行运行的,因此该解决方案不起作用。


0
投票

在过去的几个月里,我已经为此绞尽脑汁了几个人日,但我还没有找到“纯粹”的解决方案。但是,FWIW,如果您不介意每次都强制重新链接,请执行以下操作:

(“post-build-events”的这种实现类似于“pre-build-events”的this实现。)

注意事项:

  • 每次都会重新连接力量
  • 仅适用于具有链接步骤的项目,因此不适用于

    TEMPLATE=aux
    TEMPLATE=subdirs

    FORCELINK_CPP_FILE = force_link.cpp
    
    #This batch of statements causes the dummy file to be touched each build.
    forcelink.target = $$FORCELINK_CPP_FILE
    #FORCE is a nonexistent target, which will cause Make to always re-execute the recipe.
    forcelink.depends = FORCE
    forcelink.commands = touch $$FORCELINK_CPP_FILE
    QMAKE_EXTRA_TARGETS += forcelink
    
    #This statement ensures that touching the above file at Make time will force relinking.
    SOURCES += $$FORCELINK_CPP_FILE
    
    #QMake will complain unless the file actually exists at QMake time,
    # too, so we make sure it does.
    #I used to touch this on QMake build_pass runs, too,
    # but it caused transient access-denied errors.
    # I guess the release and debug makefiles are generated in parallel.
    !build_pass : write_file($$FORCELINK_CPP_FILE)
    

0
投票

我做了什么(使用 innosetup): 我使用模板“aux”创建一个项目并定义一个新的编译器:

TEMPLATE = aux
IS_INPUT = $$PWD/install.iss
IS_OUTPUT = $$PWD/installer.exe
is.name = "innosetup"
is.input = IS_INPUT
is.output = IS_OUTPUT
is.commands =  "C:/Program Files (x86)/Inno Setup 6/iscc.exe" ${QMAKE_FILE_IN}
QMAKE_EXTRA_COMPILERS += is

最重要的是is.commands这行

然后,我使用模板“子目录”创建一个项目,添加所有项目,最后添加新的“aux”项目。

TEMPLATE = subdirs

SUBDIRS += \
    ./project1/sources/project1.pro \
    ./project2/sources/project2.pro \
    ./project3/sources/project3.pro \
    ./installer/installer.pro

CONFIG += ordered 

不要忘记添加“CONFIG +=ordered”

© www.soinside.com 2019 - 2024. All rights reserved.