Yes, that did help. Works perfectly without the $ character.<br><br>--<br>Glenn<br><br><div class="gmail_quote">On 11 October 2011 19:55, Michael Wild <span dir="ltr"><<a href="mailto:themiwi@gmail.com">themiwi@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div><div></div><div class="h5">On 10/11/2011 06:02 PM, Glenn Coombs wrote:<br>
> Hi,<br>
><br>
> I've just had a CMakeLists.txt fail to work as expected because somebody<br>
> was testing to see whether an environment variable was set with the<br>
> syntax: if (DEFINED $ENV{VAR}). This short example shows the problem:<br>
><br>
> cmake_minimum_required(VERSION 2.8)<br>
><br>
> project(foo)<br>
><br>
> message("HOME: $ENV{HOME}")<br>
> if (DEFINED $ENV{HOME})<br>
> message("HOME is defined")<br>
> else()<br>
> message("HOME is NOT defined")<br>
> endif()<br>
><br>
> if (DEFINED FOO)<br>
> message("At 1: FOO is defined")<br>
> else()<br>
> message("At 1: FOO is NOT defined")<br>
> endif()<br>
><br>
> set(FOO "foo")<br>
><br>
> if (DEFINED FOO)<br>
> message("At 2:FOO is defined")<br>
> else()<br>
> message("At 2:FOO is NOT defined")<br>
> endif()<br>
><br>
> When run it prints this:<br>
><br>
> HOME: /user/grc<br>
> HOME is NOT defined<br>
> At 1: FOO is NOT defined<br>
> At 2:FOO is defined<br>
><br>
> So the test for if a variable is defined works for cmake variables but<br>
> not for environment variables. I can work around this by testing if the<br>
> environment variable is the empty string I guess. Is the current<br>
> behaviour what is wanted, or is this a bug ?<br>
><br>
> --<br>
> Glenn<br>
<br>
</div></div>That's because it should read<br>
<br>
if(DEFINED ENV{VAR})<br>
<br>
notice the missing $. Otherwise you are testing whether a variable is<br>
defined whose name is given by the content of the VAR environment variable.<br>
<br>
HTH<br>
<br>
Michael<br>
<font color="#888888"><br>
--<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br>
</font></blockquote></div><br>