Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake's STREQUAL not working

Tags:

cmake

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?

like image 895
void.pointer Avatar asked Oct 06 '11 16:10

void.pointer


2 Answers

The issue was my cache. I deleted my cache and reconfigured and now the code works.

like image 150
void.pointer Avatar answered Nov 20 '22 03:11

void.pointer


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:

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()

gives output:

FUBARTEST Worked
string STREQUAL string works
variable STREQUAL variable works
variable STREQUAL string works
like image 17
Rian Sanderson Avatar answered Nov 20 '22 04:11

Rian Sanderson