qMake:qmake 究竟如何解释“CONFIG(debug, debug|release)"?句法 [英] qMake: How exactly does qmake interpret the "CONFIG(debug, debug|release)" syntax

查看:91
本文介绍了qMake:qmake 究竟如何解释“CONFIG(debug, debug|release)"?句法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了

I read though HERE, yet I still don't understand the syntax of the qmake CONFIG variable. for example, if I have the following CONFIG settings in my .pro file:

CONFIG(debug, debug|release) {
    message("debug mode")
}else {
    message("release mode")
}

然后,当运行qmake时,Qt-Creator中的编译输出中将显示以下内容:

then, when running qmake, the following will be displayed in the Compile Output in Qt-Creator:

Project MESSAGE: debug mode
Project MESSAGE: debug mode
Project MESSAGE: release mode

知道我正在调试模式"下构建我的项目,那么我的问题是:

knowing that I am building my project in a "debug mode", then my questions are:

  • why not showing the "debug mode" message only ? and why not showing it just once ?
  • Then, since I am building in a "debug mode", why the message "Project MESSAGE: release mode" is displayed ?
  • Exactly, what the syntax: CONFIG(debug, debug|release) really means? does it means that build in a debug mode, then again build in a debug mode and lastly build in a release mode ? I know that these brackets "{}" means a scope (old link was died, recommend scope) but how qmake interpret what is inside these brackets "()" ?

推荐答案

在你链接的文章中,一开始就说项目文件被处理了3次.这应该回答你的第一个问题;因为它被处理了三次,你的 message() 也被执行了三次.为什么要多次处理?因为 qmake 不会构建您的项目!它只生成构建指令,然后用于实际构建项目.为了为所有可能的配置生成构建指令,它需要多次处理项目文件,每个配置处理一次.

In the article you linked to, it's said in the very beginning that the project file is processed three times. This should answer your first question; since it's processed three times, your message() is executed three times too. Why is it processed multiple times? Because qmake does not build your project! It only generates build instructions which are then used to actually build the project. In order to generate build instructions for all possible configurations, it needs to process the project file multiple times, one time for each configuration.

对于您的第二个问题:如果您选择的是调试模式,则您的项目仅在调试模式下构建,但构建指令也是为发布模式创建的,如上所述.例如,当在 mingw 中使用make"(而不是 Visual Studio)时,您会得到两个 Makefile:Makefile.ReleaseMakefile.Debug.当它生成发布 makefile 时,即打印发布模式".

For your second question: your project is built only in debug mode if that's what you selected, but build instructions are created for release mode too, as already mentioned above. When using "make" with mingw for example (rather than Visual Studio), you get two Makefiles: Makefile.Release and Makefile.Debug. When it generates the release makefile, that's when "release mode" is printed.

最后,CONFIG(debug, debug|release) 如果 CONFIG 包含debug"但不包含release",或者它包含debug"和release"但包含release",则计算结果为真" 在最后一次出现 "debug" 后不会出现.例如你可能有这个:

Finally, CONFIG(debug, debug|release) evaluates to true if CONFIG contains "debug" but not "release", or if it contains both "debug" and "release" but "release" doesn't appear after the last occurrence of "debug". For example you might have this:

CONFIG += release debug release debug release debug

由于最后一个调试"出现在最后一个发布"之后,CONFIG(debug, debug|release) 为真.

Since the last "debug" comes after the last "release", CONFIG(debug, debug|release) is true.

CONFIG() 的第一个参数(在本例中为调试")是最后出现的值.第二个参数 ("debug|release") 是检查第一个参数的一组值.

The first argument of CONFIG() ("debug" in this case) is the value that has to appear last. The second argument ("debug|release") is the set of values that the first argument is checked against.

将其翻译成英语会得到如下结果:如果debug"至少出现一次,则评估为真,如果release"也出现,则debug"的最后一次出现在release"的最后一次出现之后.

Translating that to English would give something like this: evaluate to true if "debug" appears at least once and, in case "release" appears too, the last appearance of "debug" comes after the last appearance of "release".

这篇关于qMake:qmake 究竟如何解释“CONFIG(debug, debug|release)"?句法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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