CMake的STREQUAL无法正常工作

时间:2011-10-06 16:15:13

标签: cmake

根据CMake文档,STREQUAL比较允许将VARIABLE或STRING作为参数。因此,在下面的这个例子中,消息不打印,这是打破的:

set( FUBARTEST "OK" )
if( FUBARTEST STREQUAL "OK" )
    message( "It Worked" )
endif()

为什么这不符合记录的原因?

3 个答案:

答案 0 :(得分:28)

问题是我的缓存。我删除了我的缓存并重新配置,现在代码正常工作。

答案 1 :(得分:14)

我最初没有测试你的例子,但是当我这样做时,我看到你的代码在cmake 2.8.0上运行正常,而且在文档中宣传的其他组合也是如此:

set( FUBARTEST "OK" )
if( FUBARTEST STREQUAL "OK" )
    message( "FUBARTEST Worked" )
else()
    message( "FUBARTEST FAILED" )
endif()

set( FOO "OK" )
if( ${FOO} STREQUAL "OK" )
    message("string STREQUAL string works" )
else ()
    message("string STREQUAL string FAILED" )

endif()

set( FOO "OK" )
set( BAR "OK" )
if( FOO STREQUAL BAR )
    message("variable STREQUAL variable works" )
else ()
    message("variable STREQUAL variable FAILED" )

endif()

set( FOO "OK" )
if( FOO STREQUAL "OK" )
    message("variable STREQUAL string works" )
else ()
    message("variable STREQUAL string FAILED" )

endif()

给出输出:

FUBARTEST Worked
string STREQUAL string works
variable STREQUAL variable works
variable STREQUAL string works

答案 2 :(得分:0)

使用[ { "_id" : ObjectId("5cee224b97e765079c8c2839"), "name" : "Dairy", "supplier" : [ { "supplierId" : ObjectId("5cee12a7a01ad50f5c2229ac"), "supplierName" : "Bhagwandas Bherumal", "items" : 10 } ] }, { "_id" : ObjectId("5cee1a19a01ad50f5c2229f2"), "name" : "dairy/fruit", "supplier" : [ { "supplierId" : ObjectId("5cee12a7a01ad50f5c2229ac"), "supplierName" : "Bhagwandas Bherumal", "items" : 65 }, { "supplierId" : ObjectId("5cee11f7a01ad50f5c2229a2"), "supplierName" : "Agron India PVT. LTD", "items" : 55 } ] }] 而不是'进行字符串比较时会发生同样的事情

这行不通:

"

这有效(除非存在如上所述的缓存问题)

if( FUBARTEST STREQUAL 'OK' )
    message( "It Worked" )
endif()