[CMake] BOOL type

Bill Hoffman bill.hoffman at kitware.com
Tue Dec 18 09:48:40 EST 2007


James Bigler wrote:

> 
> I also agree that trying to maintain backwards compatibility to the 
> detriment of the future can become a hinderance.  I just had a collegue 
> who was extreemly frustrated for several hours with why his build didn't 
> work, only to discover that he should have been using ADD_SUBDIRECTORIES 
> instead of SUBDIRS.  There was no warning from CMake stating that he 
> shouldn't be using it (I would argue that CMake should warn about the 
> use of SUBDIRS).
> 
That would be lots of warnings!  SUBDIRS was the only way to do things 
for a long time.  CMake itself still uses them so it can be bootstrapped 
with older versions of CMake.  SUBDIRS still works, it just works 
different.  The behavior of both are documented.


> Aside from the backwards compatibility issue, this cmake code should 
> work, but it produces a FATAL_ERROR:
> 
> SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE)
> 
> SET(A TRUE)
> SET(B FALSE)
> 
> IF(A EQUAL B)
>   MESSAGE(FATAL_ERROR "${A} shouldn't equal ${B}")
> ELSE()
>   MESSAGE("${A} should equal ${B}")
> ENDIF()
> 
> SET(B 1)
> 
> IF(A EQUAL B)
>   MESSAGE("${A} should equal ${B}")
> ELSE()
>   MESSAGE(FATAL_ERROR "${A} shouldn't equal ${B}")
> ENDIF()
> 

Why should TRUE EQUAL 1?

 From the docs of IF:

   IF(variable LESS number)
   IF(string LESS number)
   IF(variable GREATER number)
   IF(string GREATER number)
   IF(variable EQUAL number)
   IF(string EQUAL number)

True if the given string or variable's value is a valid number and the 
inequality or equality is true.

TRUE is not a valid number, EQUAL only works on numbers.

-Bill



More information about the CMake mailing list