[CMake] NOT operator gotchas for newbies

Michael Hertling mhertling at online.de
Sat Nov 5 16:18:08 EDT 2011


On 11/05/2011 03:24 AM, Dan Kegel wrote:
> On Fri, Nov 4, 2011 at 6:09 PM, Michael Hertling <mhertling at online.de> wrote:
>> NOT isn't a constant but a boolean operator like AND/OR/EXISTS etc.,
>> and none of the latters is case-sensitive at the moment, so why
>> should NOT be the sole exception?
> 
> Right, I meant to suggest the other operators should be
> case insensitive, too.  Isn't that the general direction cmake
> has been going?

Not that I know of; the commands are case-insensitive, but the sub-
commands/clauses/switches/flags or however they're to name must be
uppercase with only a few exceptions, e.g. debug/optimzed/general
in TARGET_LINK_LIBRARIES(). However, the latters are obsolete in
favor of imported targets anyway.

>>> Also, people who mistakenly use !foo instead of NOT foo
>>> get a surprise: the result is always silently false.
>>> It might be nice to catch this possibly common error
>>> and output an error message.
>>
>> !foo seems to be a valid indentifier for a variable ...
>> Besides the fact that you can not refer to it via ${!foo}, it's highly
>> inadvisable to name a variable in this way, of course. Anyway, if one
>> considers to introduce "!" as an equivalent for NOT,
> 
> I was proposing instead to output a good error message
> in this case, not to support ! as a synonym for NOT.

Even then, you'd need to be consistent and warn about the other
C-style operators like "&&" or "||", too, which might also be
used accidentally.

Regards,

Michael


More information about the CMake mailing list