【问题标题】:CMake Generator Expressions and CONFIG variable queryCMake 生成器表达式和 CONFIG 变量查询
【发布时间】:2021-09-02 14:57:05
【问题描述】:

这个 CMake 文档:https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html 告诉我们:

$<CONFIG> Configuration name.

还有:

Conditional generator expressions depend on a boolean condition that must be 0 or 1.

$<condition:true_string> Evaluates to true_string if condition is 1. Otherwise evaluates to the empty string.

$<IF:condition,true_string,false_string> New in version 3.8.

Evaluates to true_string if condition is 1. Otherwise evaluates to false_string.

Typically, the condition is a boolean generator expression. For instance,

$<$<CONFIG:Debug>:DEBUG_MODE> expands to DEBUG_MODE when the Debug configuration is used, and otherwise expands to the empty string.

如果我理解正确,在 Visual Studio 中,如果我从 Debug 切换到 Release 这行:

$<$<CONFIG:Debug>:DEBUG_MODE>

也应该扩展到DEBUG_MODE,不是吗?因为根据我的理解,CONFIG 将包含“Release”并且它是一个非空字符串,因此它将扩展为 Debug,而不是由于文档中的此语句,最后一个生成器表达式将扩展为 DEBUG_MODE:

$condition:true_string 如果条件为 1,则计算为 true_string。 否则计算为空字符串。

我知道我错了,请帮助我理解它是如何工作的。

【问题讨论】:

  • because CONFIG will contain, according to my understanding "Release" and it's a non empty string, thus it will expand to Debug$&lt;CONFIG:cfgs&gt; 1 if config is any one of the entries in cfgs, else 0.
  • @KamilCuk 文档说:$ 如果条件为 1,则计算为 true_string。否则计算为空字符串
  • 文档说$&lt;CONFIG:cfgs&gt; 1 if config is any one of the entries in cfgs, else 0.。我不明白CONFIG 不是条件(在“语法”意义上)。
  • CMake 真是一头奇怪的野兽!谢谢

标签: cmake


【解决方案1】:

因为 CONFIG 将包含

CONFIG 不包含,不是条件,是特定的Variable query 有特殊规则。

$<CONFIG:cfgs>

1 if config is any one of the entries in cfgs, else 0. [...]

假设它是这样工作的:

  • 提取AB 部分,如$&lt;A:B&gt;
  • 如果部分ACONFIG - 然后做与CONFIG相关的事情
  • 如果部分A 是,例如,STREQUAL - 然后在B 上做与STREQUAL 相关的事情。
  • 针对每种情况...
  • 否则是condition,所以如果是1,则返回B,否则为空字符串。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多