CMake 的 STREQUAL 不起作用
根据 CMake 文档,STREQUAL
比较允许采用 VARIABLE 或 STRING 作为任一参数。因此,在下面的示例中,该消息不会打印,这是损坏的:
set( FUBARTEST "OK" )
if( FUBARTEST STREQUAL "OK" )
message( "It Worked" )
endif()
有什么原因导致这不能按记录工作?
According to the CMake documentation, the STREQUAL
comparison is allowed to take either a VARIABLE or a STRING as either parameter. So, in this example below, the message does NOT print, which is broken:
set( FUBARTEST "OK" )
if( FUBARTEST STREQUAL "OK" )
message( "It Worked" )
endif()
Any reason why this isn't working as documented?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
问题是我的缓存。我删除了缓存并重新配置,现在代码可以工作了。
The issue was my cache. I deleted my cache and reconfigured and now the code works.
我一开始没有测试你的示例,但是当我测试时,我发现你的代码在 cmake 2.8.0 上运行良好,并且文档中宣传的其他组合也这样做:
给出输出:
I didn't test your example at first, but when I did, I see your code works fine on cmake 2.8.0, and the other combinations advertised in the docs do too:
gives output:
当使用
'
而不是"
进行字符串比较时,也会发生同样的情况这不起作用:
这有效(除非存在如上所述的缓存问题):
The same thing happens when using
'
instead of"
for the string comparisonThis won't work:
This works (except if there is a cache issue like mentioned above):
我在 Windows 上遇到了这样的问题,在 Linux 上一切正常。
结果问题是,在 Linux 上,逻辑操作可以写在 cmake_minimum_required 和项目之前,而在 Windows 上,它们必须放在后面。
工作示例:
此示例仅适用于使用 CMake 3.16 的 Linux,但不适用于 Windows:
I had such problem on Windows, when on Linux all worked fine.
Turns out issue was, that on Linux logical operations can be written before cmake_minimum_required and project, when on Windows they must be placed after.
Working example:
And this example works only on Linux with CMake 3.16, but not on Windows: