View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0013376CMakeCMakepublic2012-07-04 22:592012-12-03 07:46
ReporterBruce Cartland 
Assigned To 
PrioritylowSeverityminorReproducibilityalways
StatusclosedResolutionno change required 
PlatformWindowsOSXP OS VersionSP3
Product VersionCMake 2.8.8 
Target VersionFixed in Version 
Summary0013376: For unset variables IF(${var}) and IF(NOT ${var}) both return FALSE which fails to work for predefined vars such as CYGWIN
Description(I'm a noob so please excuse if this is already report, not formatted correctly, or invalid :)

See steps to reproduce.
Steps To Reproducemessage(STATUS "CYGWIN = '${CYGWIN}'")
if(${CYGWIN})
    message(STATUS "CYGWIN set")
else()
    set(CYGWIN 0) #this "fixes" the problem and results in expected behaviour
    message(STATUS "CYGWIN not set")
endif()
if(NOT ${CYGWIN})
    message(STATUS "CYGWIN not set")
else()
    message(STATUS "CYGWIN set - or is it?")
endif()
Additional InformationThe script in steps to reproduce results in the following output:

-- CYGWIN = ''
-- CYGWIN not set
-- CYGWIN set - or is it?

Seems to me that FALSE should be defined to include blank as well as NO, etc OR variables such as CYGWIN should be set to 0 and not left blank.
TagsNo tags attached.
Attached Files

 Relationships

  Notes
(0029909)
Bruce Cartland (reporter)
2012-07-04 23:02

Oops! Sorry!

The line in the script steps to reproduce
   set(CYGWIN 0) #this "fixes" the problem and results in expected behaviour
should be commented out
   #set(CYGWIN 0) #this "fixes" the problem and results in expected behaviour

to get the output I listed.
(Can't edit the original text).
(0030002)
Brad King (manager)
2012-07-09 09:37

When CYGWIN is not set the code

 if(NOT ${CYGWIN})

expands to just

 if(NOT)

which is somewhat non-sensical but evaluates to false. Using double quotes ensures a value is treated as a single argument:

 if(NOT "")

is true.

Anyway, to test variables that may or may not be set just use the name of the variable:

 if(CYGWIN)
   message(STATUS "This is Cygwin")
 else()
   message(STATUS "This is not Cygwin")
 endif()

Please see full behavior of if() in the reference documentation:

 http://www.cmake.org/cmake/help/v2.8.8/cmake.html#command:if [^]

and/or join the mailing list to ask for further help:

 http://www.cmake.org/mailman/listinfo/cmake [^]
(0031810)
David Cole (manager)
2012-12-03 07:46

Closing resolved issues that have not been updated in more than 4 months.

 Issue History
Date Modified Username Field Change
2012-07-04 22:59 Bruce Cartland New Issue
2012-07-04 23:02 Bruce Cartland Note Added: 0029909
2012-07-09 09:37 Brad King Note Added: 0030002
2012-07-09 09:37 Brad King Status new => resolved
2012-07-09 09:37 Brad King Resolution open => no change required
2012-12-03 07:46 David Cole Note Added: 0031810
2012-12-03 07:46 David Cole Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team