CMake 语法:如何否定 if(<constant>) 和 if(<variable|string>)

CMake syntax: how to negate if(<constant>) and if(<variable|string>)

CMake 的 if 命令 [1] 支持多个签名,从

开始
if(<constant>)
if(<variable|string>)
if(NOT <expression>)

如何取反前两个?

如果 CMake 文档是正确的(根据我的经验,这远非确定),那么我的问题归结为:

如何将常量、变量或字符串 X 转换为表达式,并附加要求 X 被计算为布尔值?

[1] https://cmake.org/cmake/help/latest/command/if.html

实际上,<expression>只是任何参数的占位符,可以传递给if。甚至可能的 if 结构列表也被命名为 "Possible expressions are".

if(NOT <constant>) # Revert 'if(<constant>)'
if(NOT <variable|string>) # Revert 'if(NOT <variable|string>)'