<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Perhaps this example will help... Or perhaps it's time to find that
beer.<br>
<br>
With a valid environment variable named COMPUTERNAME, evaluating (oddly
enough) to the name of my computer, on Windows XP, using CMakeSetup
2.0.5, the following CMake script yields messages <b>only </b>from IF
statements 5 and 6.<br>
<br>
If you must use environment variables, try modelling your CMake IF
statements after cases 5 and 6 where you compare against expected
string values of the evaluated environment variables.<br>
<br>
IF($ENV{COMPUTERNAME})<br>
MESSAGE("1. $ENV{COMPUTERNAME} is true")<br>
ENDIF($ENV{COMPUTERNAME})<br>
<br>
IF(ENV{COMPUTERNAME})<br>
MESSAGE("2. ENV{COMPUTERNAME} is true")<br>
ENDIF(ENV{COMPUTERNAME})<br>
<br>
IF(DEFINED $ENV{COMPUTERNAME})<br>
MESSAGE("3. DEFINED $ENV{COMPUTERNAME} is true")<br>
ENDIF(DEFINED $ENV{COMPUTERNAME})<br>
<br>
IF(DEFINED ENV{COMPUTERNAME})<br>
MESSAGE("4. DEFINED ENV{COMPUTERNAME} is true")<br>
ENDIF(DEFINED ENV{COMPUTERNAME})<br>
<br>
IF("$ENV{COMPUTERNAME}" STREQUAL "$ENV{COMPUTERNAME}")<br>
MESSAGE("5. STREQUAL compare is true - COMPUTERNAME equals itself -
COMPUTERNAME='$ENV{COMPUTERNAME}'")<br>
ENDIF("$ENV{COMPUTERNAME}" STREQUAL "$ENV{COMPUTERNAME}")<br>
<br>
IF(NOT "$ENV{COMPUTERNAME}" STREQUAL "")<br>
MESSAGE("6. NOT of STREQUAL compare is true - thankfully COMPUTERNAME
is not the empty string. COMPUTERNAME='$ENV{COMPUTERNAME}'")<br>
ELSE(NOT "$ENV{COMPUTERNAME}" STREQUAL "")<br>
MESSAGE("6. NOT of STREQUAL compare is false - COMPUTERNAME is the
empty string. Go have that beer now.")<br>
ENDIF(NOT "$ENV{COMPUTERNAME}" STREQUAL "")<br>
<br>
Given Ken's explanation from yesterday on this list, it makes sense to
me that cases 1 and 3 fail because of the string substitution that
occurs prior to executing the IF statements. In fact, if I then set a
CMake variable with the CMake variable name equal to my computer's name
and a value of 1, then cases 1 and 3 will be true because I have a
CMake variable of the name that gets evaluated when substitution
occurs. If I make the value 0, case 1 is false again, but case 3 is
still true.<br>
<br>
Just to reiterate: If you must use environment variables, try modelling
your CMake IF statements after cases 5 and 6 where you compare against
expected string values of the environment variables.<br>
<br>
<br>
Hope this helps,<br>
David<br>
<br>
<br>
Brad King wrote:
<blockquote cite="mid429602DE.7010809@kitware.com" type="cite"><a class="moz-txt-link-abbreviated" href="mailto:alaterale@elitemail.org">alaterale@elitemail.org</a>
wrote:
<br>
<blockquote type="cite">if you run that before you run something like
"export S5300=TRUE" it
<br>
should print out the lower message because it's not defined, right?
<br>
Then after you run that export (or setenv or whatever) the first
message
<br>
should print and not the other one, since it is defined. However, this
<br>
is not what happens for some reason. Any idea on what could be causing
<br>
this? Is this something specific to ENV{}? I'm trying to get the hang
<br>
of this IF statement in terms of environment variables (as those are
<br>
easier for us to set) if you can't tell :P Any help would be greatly
<br>
appreciated :)
<br>
</blockquote>
<br>
Yes, it is specific to ENV. Currently there is no way to tell apart an
empty variable from one that is not set. The IF command was never
designed to be used with environment variables. It is not really safe
anyway because there are alot of cases where CMake runs behind the
scenes and might not be in the same environment in which it was first
run. If you want to control build settings on the CMake command line,
you need to use cache variables set with the -D option. The settings
will be saved in CMakeCache.txt so that they don't have to be repeated
every time CMake is run on the same build tree.
<br>
<br>
-Brad
<br>
_______________________________________________
<br>
CMake mailing list
<br>
<a class="moz-txt-link-abbreviated" href="mailto:CMake@cmake.org">CMake@cmake.org</a>
<br>
<a class="moz-txt-link-freetext" href="http://www.cmake.org/mailman/listinfo/cmake">http://www.cmake.org/mailman/listinfo/cmake</a>
<br>
<br>
</blockquote>
</body>
</html>