【发布时间】: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但$<CONFIG:cfgs> 1 if config is any one of the entries in cfgs, else 0. -
@KamilCuk 文档说:$
如果条件为 1,则计算为 true_string。否则计算为空字符串 -
文档说
$<CONFIG:cfgs> 1 if config is any one of the entries in cfgs, else 0.。我不明白CONFIG不是条件(在“语法”意义上)。 -
CMake 真是一头奇怪的野兽!谢谢
标签: cmake