[CMake] NOT operator gotchas for newbies
Michael Hertling
mhertling at online.de
Fri Nov 4 21:09:22 EDT 2011
On 11/04/2011 11:22 PM, Dan Kegel wrote:
> I just ran into two little newbie problems having to do with booleans.
>
> CMP0012 made various boolean constants case insensitive,
> but NOT is still case sensitive.
> If you use it in lowercase, you get the warning
>
> CMake Warning (dev) at CMakeLists.txt:2 (if):
> given arguments:
> "not" "foo"
> Unknown arguments specified
>
> That's fairly clear, and anyone who's been around cmake will
> suspect that uppercase is required.
> Still, it might be nice to accept lowercase not at some point.
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?
> 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:
CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
PROJECT(FOO NONE)
SET(!foo "bar")
GET_DIRECTORY_PROPERTY(VARS VARIABLES)
MESSAGE("VARS: ${VARS}")
IF(!foo STREQUAL "bar")
MESSAGE("!foor==bar")
ELSE()
MESSAGE("!foo!=bar")
ENDIF()
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, one should also
add "&" and "|" for AND/OR, or better "&&" and "||"? What's about
"=/==", "!=", "<", "<=", ">", ">=" for strings and/or numbers?
How to distinguish the latters? Nocturnal thoughts... ;-)
Regards,
Michael
More information about the CMake
mailing list