On 05/09/2010 12:01 PM, Esben Mose Hansen wrote:
> On Sunday 09 May 2010 11:12:54 Esben Mose Hansen wrote:
>> I quote from the documentation (2.8)
>>
>>>   if(<constant>)
>>>
>>>
>>> True if the constant is 1, ON, YES, TRUE, Y, or a non-zero number. False
>>> if the constant is 0, OFF, NO, FALSE, N, IGNORE, "", or ends in the
>>> suffix '-NOTFOUND'. Named boolean constants are case-insensitive.
>>
>> So what is the value of say "/home/esben/kde/lib/mylibrary.so"?
>> Experimental  test and common sense say true, but the documentation
>> doesn't say so. Wouldn't the correct documentation be
>>
>>   if(<constant>)
>> False if the constant is 0, OFF, NO, FALSE, N, IGNORE, "", or ends in the 
>> suffix '-NOTFOUND'. Named boolean constants are case-insensitive. IF the 
>> constant has any other value, it is true.
>>
>> Right?
> 
> Wrong. I made some experiments, and as far as I have been able to determine, 
> anything not on the true list (1 being there twice?!) is actually false, 

>From the CMake 2.8.1 documentation of IF():

"[...] The convenience feature that sometimes throws new authors is how
CMake handles values that do not match the true or false list. Those
values are treated as variables and are dereferenced [...]"

Thus, the observed behaviour, i.e. the interpretation of IF()'s single
argument as a variable if it doesn't equal one of the explicitly listed
true'n'false values and the subsequent evaluation of that "variable's"
content, is regular as AN and HS have pointed out in the meantime, and
it's also documented. IMO, there's no bug in the CMake docs w.r.t. this.

> including non-zero numbers with space appended (but not prefixed) [...]

This is a quite common behaviour, cf. strtol(): Leading white-space is
consumed implicitly, but trailing white-space is left alone. Obviously,
CMake decides that explicitly trailing white-space also disqualifies a
string literal from being considered as a non-zero number.

> [...] That means 
> that the -NOTFOUND suffix is actually quite useless, [...] 

No: "IF(mylibrary.so)" and "IF(mylibrary.so-NOTFOUND)" both evaluate to
FALSE, indeed, but while "SET(VAR mylibrary.so)...IF(VAR)" evaluates to
TRUE note that "SET(VAR mylibrary.so-NOTFOUND)" makes "IF(VAR)" to
yield FALSE which is essential for commands like FIND_LIBRARY().

In summary, the crucial moment is the distinction between evaluating a
literal constant and evaluating a variable during IF()'s execution.

Best regards,

Michael
_______________________________________________
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