Hi,

I learned something very valuable today about cmake after getting an
unexpected result with STREQUAL:

set(foo bar)
...
set(baz foo)
...
if("${baz}" STREQUAL "bar") # This evaluates to true.
...

I expected it to be false, because I was trying to get baz's value ("foo")
to compare with "bar".  I thought that parameters explicitly quoted were
treated as strings.

Then I learned that the interpreter is the only one that sees quotes around
parameters, for the sole purpose of string interpolation and preventing
whitespace from splitting a parameter.  Cmake commands do not see these
quotes. Therefore, STREQUAL can never know the difference between "baz" and
baz.

So, STREQUAL treats a parameter as a variable name if it is defined, but as
a string value if it is not.  (I verified this in cmIfCommand.cxx)

Is this quote behavior well-known among cmake users?  For others like me,
I'd like this behavior to be emphasized in the cmake docs for STREQUAL.

Happy Valentine's.

Shaun
--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to