MantisBT - CMake
View Issue Details
0005835CMakeCMakepublic2007-10-08 15:262011-05-02 14:46
Brandon Van Every 
David Cole 
normalfeaturealways
closedno change required 
 
CMake 2.8.4 
0005835: define TRUE and FALSE constants
TRUE and FALSE are not constants, as the following code illustrates:

SET(FALSE "whatever")
IF(FALSE)
  MESSAGE("FALSE is a variable")
ELSE(FALSE)
  MESSAGE("You'll never see this")
ENDIF(FALSE)
IF(TRUE)
  MESSAGE("You'll never see this")
ELSE(TRUE)
  MESSAGE("TRUE is an uninitialized variable")
ENDIF(TRUE)

C:\devel\src\cbugs\trueorfalse>cmake -P trueorfalse.cmake
FALSE is a variable
TRUE is an uninitialized variable

The documentation says, "IF(variable) - True if the variable's value is not empty, 0, N, NO, OFF, FALSE, NOTFOUND, or <variable>-NOTFOUND." They also mention TRUE in conjunction with some Find* functions. This can mislead the programmer into believing that TRUE and FALSE are available as constants, and that the statement IF(TRUE) does what you'd expect.

Defining TRUE and FALSE to be constants would be safer. Compatibility issues probably wouldn't happen in practice, because people probably aren't using TRUE or FALSE as variables.
No tags attached.
Issue History
2007-10-08 15:26Brandon Van EveryNew Issue
2007-10-12 09:40Bill HoffmanStatusnew => assigned
2007-10-12 09:40Bill HoffmanAssigned To => Ken Martin
2008-01-31 04:14Brandon Van EveryNote Added: 0010352
2010-12-14 11:30David ColeAssigned ToKen Martin => David Cole
2011-01-28 11:13David ColeNote Added: 0025127
2011-01-28 11:13David ColeStatusassigned => resolved
2011-01-28 11:13David ColeFixed in Version => CMake 2.8.4
2011-01-28 11:13David ColeResolutionopen => no change required
2011-05-02 14:46David ColeNote Added: 0026380
2011-05-02 14:46David ColeStatusresolved => closed

Notes
(0010352)
Brandon Van Every   
2008-01-31 04:14   
Perhaps YES, NO, ON, and OFF should be defined as constants as well.

I don't think Y and N should be. Actually I think treatment of "Y" and "N" as true/false values should be removed from CMake. A regex match of a single character can be "N".
(0025127)
David Cole   
2011-01-28 11:13   
The IF command documentation has been improved since this report was filed.

Once a CMake developer gets used to the way IF stuff evaluates... this issue is not so critical. I do not see a lot of added value to adding "constants" into the mix.

Please feel free to re-open this issue and discuss things further if you strongly disagree.

Thanks,
David
(0026380)
David Cole   
2011-05-02 14:46   
Closing resolved issues that have not been updated in more than 3 months.