如何在qmake/qtcreator中添加预构建步骤? [英] How to add pre-build step in qmake/qtcreator?

查看:567
本文介绍了如何在qmake/qtcreator中添加预构建步骤?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望编译后的应用程序具有提交号,源文件校验和以及其他在编译过程中可用的东西.

I want the compiled application to have the commit number, source files checksums and other things to be available during the compilation.

在普通的Makefile中,我喜欢这样:

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

如何在qmake中使用类似的东西?

How to use something similar with qmake?

推荐答案

如果将版本信息作为包含文件(例如"version.h")而不是#define传递,则可以添加以下内容到您的qmake文件中

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

# Define how to create version.h
version.target = version.h
version.commands = <PUT_YOUR_COMMANDS_HERE>
version.depends = .git

QMAKE_EXTRA_TARGETS += version

PRE_TARGETDEPS += version.h

前三行介绍了如何创建一个新的目标对象,该目标对象称为"version",该对象将生成"version.h".通过执行命令< PUT_YOUR_COMMANDS_HERE>"来完成.目标取决于".git"

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"

"QMAKE_EXTRA_TARGETS"表示存在一个称为版本"的新目标.

The "QMAKE_EXTRA_TARGETS" says there is a new target known as "version".

"PRE_TARGETDEPS"表示"version.h"必须存在,然后才能执行其他任何操作(如果尚未创建,则将其强制创建).

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).

这篇关于如何在qmake/qtcreator中添加预构建步骤?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆