问题描述
我可以轻松编辑 Makefile 以添加自定义步骤.例如,我有一行:
I can easily edit Makefile to add custom step. For example, I have a line:
first: release
如果我把它改成
first: pre-build release
然后我就可以在pre-build:"标签之后放置一些操作了.
Then I'll be able to place some operations after "pre-build:" label.
问题是如何在.pro文件中写入相应的指令,强制qmake工具在Makefile中生成需要的行?
The question is how to write corresponding instruction to .pro file, to force qmake tool generate required lines in Makefile?
推荐答案
您可以使用 QMAKE_EXTRA_TARGETS
变量将自定义目标添加到生成的 Makefile
中,如下所示:
You can add a custom target to your resulting Makefile
using QMAKE_EXTRA_TARGETS
variable, kind of that:
QMAKE_EXTRA_TARGETS += beforebuild
beforebuild.commands = echo Hello world!
beforebuild.CONFIG = phony
然而,你不能把这个目标放到first: all
行,除非你已经修补了qmake
的源代码(考虑以下来自 makefile.cpp
的片段:t << "first: " << targets.first()->target << endl
).
However, you cannot put this target onto first: all
line, unless you've patched qmake
's source code (consider the following snippet from makefile.cpp
: t << "first: " << targets.first()->target << endl
).
原则上,可以在 all
(或 release
/debug
)和你的 beforebuild
之间引入一些依赖> 目标,所以 beforebuild
仍然会被 make
自动执行,如 这篇文章(俄语).然而,最终的解决方案在我看来太丑陋且容易出错.
In principle, it's possible to induce some dependency between all
(or release
/ debug
) and your beforebuild
target, so beforebuild
would still get executed by make
automatically, as described in this article (Russian language). Yet the resulting solution seems to me too ugly and error-prone.
我认为简单地执行 make beforebuild first
(可能,使用 shell 脚本)要容易得多.除非您使用 Qt Creator,否则在这种情况下,您应该尝试上面链接中的方法.
I think that simply executing make beforebuild first
(probably, using a shell script) is much easier. Unless you're using Qt Creator, in this case you should try the recipe from the link above.
这篇关于qmake:每个拨打电话的自定义步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!