CMake 生成器表达式和 CONFIG 变量查询

CMake Generator Expressions and CONFIG variable query

这个 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 中,如果我从调试切换到发布这一行:

$<$<CONFIG:Debug>:DEBUG_MODE>

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

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

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

because CONFIG will contain

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

$<CONFIG:cfgs>

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

假设它是这样工作的:

  • 提取 AB 部分,如 $<A:B>
  • 如果 A 部分是 CONFIG - 然后做与 CONFIG
  • 相关的事情
  • 如果 A 部分是,例如 STREQUAL - 然后在 B 上做一些与 STREQUAL.
  • 相关的事情
  • 每个案例...
  • 否则是condition,所以如果是1,则return B,否则为空字符串。