如何在 qmake/qtcreator 中添加预构建步骤?
我希望编译后的应用程序具有提交号、源文件校验和以及编译期间可用的其他内容。
在普通的 Makefiles 中,我确实喜欢这样:
prog: VERSION source.c
gcc -DVERSION=\"$(shell cat VERSION)\" source.c -o prog
VERSION: .git
git describe > VERSION
How to use thingsimilar with qmake?
I want the compiled application to have the commit number, source files checksums and other things to be available during the compilation.
In plain Makefiles I do like this:
prog: VERSION source.c
gcc -DVERSION=\"$(shell cat VERSION)\" source.c -o prog
VERSION: .git
git describe > VERSION
How to use something similar with qmake?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您要将版本信息作为包含文件(假设为“version.h”)而不是 #define 传递,那么您可以将以下内容添加到 qmake 文件中。
前 3 行告诉如何创建一个名为的新目标对象生成“version.h”的“version”。它是通过执行命令“”来完成的。目标依赖于“.git”。
“QMAKE_EXTRA_TARGETS”表示有一个称为“版本”的新目标。
“PRE_TARGETDEPS”表示“version.h”需要先存在,然后才能执行其他操作(如果尚未创建,则强制创建它)。
If you were to pass the version information as an included file (let's say "version.h") instead of a #define, then you could add the following to your qmake file
The first 3 lines tell how to make a new target object called "version" that generates "version.h". It is made by executing the commands "<PUT_YOUR_COMMANDS_HERE>". The target is dependent on ".git"
The "QMAKE_EXTRA_TARGETS" says there is a new target known as "version".
The "PRE_TARGETDEPS" indicates that "version.h" needs to exist before anything else can be done (which forces it to be made if it isn't already made).
一个更简单的解决方案,即使 @jwernemy 是解决它的好方法:
A simpler solution even if @jwernemy as nice way to solve it: