[CMake] IF(string) is false. Why?

David Cole david.cole at kitware.com
Tue Oct 30 18:59:33 EDT 2007


Because "WHATEVER" is not empty...

I frequently use:
IF("${literal_string}" STREQUAL "")

or:
IF(NOT "${literal_string}" STREQUAL "")

...to achieve this goal. It's verbose, but it works and doesn't take too
much getting used to.

HTH,
David


On 10/30/07, Brandon Van Every <bvanevery at gmail.com> wrote:
>
> IF("WHATEVER")
>   MESSAGE("WHATEVER string is true")
> ELSE("WHATEVER")
>   MESSAGE("WHATEVER string is false")
> ENDIF("WHATEVER")
>
> C:\devel\src\cbugs\trueorfalse>cmake -P trueorfalse.cmake
> WHATEVER string is false
>
> I would expect the literal string "WHATEVER" to evaluate to true.  By
> analogy to IF(variable) as per the docs.  The practical application is
> I'm trying to sanity check an argument that's a literal string.
>
> MACRO(DOSOMETHING literal_string result)
>   IF(${literal_string})
>     SET(result "valid")
>   ELSE(${literal_string})
>     MESSAGE(SEND_ERROR "I don't like the input!")
>   ENDIF(${literal_string})
> ENDMACRO(DOSOMETHING)
> DOSOMETHING("WHATEVER" out)
>
> C:\devel\src\cbugs\trueorfalse>cmake -P trueorfalse.cmake
> CMake Error: I don't like the input!
>
>
> Cheers,
> Brandon Van Every
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/cmake/attachments/20071030/3b2b67ec/attachment.html


More information about the CMake mailing list