这用于设置 MacOSX 应用程序的应用程序包。我有一个脚本可以复制一些文件并执行其他一些操作。所以我想在构建之后执行脚本(即在链接步骤之后)。我希望它每次都执行,因为无法指定其依赖项。
我知道有
QMAKE_POST_LINK
(例如描述的here或here),但它仅在目标不存在时运行,即需要完成链接时。但是,我希望脚本每次都运行,即使目标已经存在。
还有
QMAKE_EXTRA_TARGETS
和 POST_TARGETDEPS
(例如,here 所描述的),但这总是强制重新链接,但我实际上只想重新运行脚本,并且它在链接之前运行脚本。 (目前,这就是我正在使用的方法,因为我没有看到更好的方法。Here是我的 QMake 源代码。)
在过去的几个月里,我已经为此绞尽脑汁了几个人日,但我还没有找到“纯粹”的解决方案。但是,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)
我做了什么(使用 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”