There may indeed be a bug (at least in the documentation).<br><br>In CMake &#39;if&#39; statements are a little different than you might think.  From the documentation of &#39;if&#39; (cmake --help-command if):<br><br>         if(variable STREQUAL string)<br>

         if(string STREQUAL string)<br><br>Now with your code you had:<br><br><span style="font-family: courier new,monospace;">foreach(opt ${options})</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">  message(STATUS &quot;opt = ${opt}&quot;)</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">  if(${opt} STREQUAL fine)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">  ...</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">endforeach()</span><br style="font-family: courier new,monospace;"><br>Now what the expression states is &#39;if (${opt} STREQUAL fine)&#39; or if (fine STRQUAL fine).  ${opt} gets replaced by its value and you compare &#39;fine&#39; with &#39;fine&#39;.  It might have appeared to work had you used opt instead of ${opt}, but you wouldn&#39;t have been able to turn the option(fine) on and off.  The if statement would have always been false.<br>

<br>Things get tricky when the right side of the STREQUAL is a string that matches the name of a variable:<br><br><span style="font-family: courier new,monospace;">set(var &quot;stuff&quot;)</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">set(stuff ON)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">if(var STREQUAL &quot;stuff&quot;)</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">  message(&quot;var STREQUAL stuff&quot;)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">else()</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">  message(&quot;NOT var STREQUAL stuff&quot;)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">endif()</span><br style="font-family: courier new,monospace;">

<br>According to the docs, I would expect this to return &quot;var STREQUAL ON&quot;, but it instead returns &quot;NOT var STREQUAL ON&quot;, meaning that it dereferenced the value of stuff in the if statement rather than treating it as a string literal.  This is inconsistent with the documentation that indicates that right side operator is a string and not a variable.<br>

<br>To get what you want in your code, you need the following:<br><br><span style="font-family: courier new,monospace;">option(fine_on &quot;Fine&quot; OFF)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">option(good_on &quot;Good&quot; ON)</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">option(bad_on &quot;Bad&quot; OFF) # This isn&#39;t actually used</span> <br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">foreach(opt ${options})</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">  message(STATUS &quot;opt = ${opt}&quot;)\</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">  # Only accept opt == fine when fine_on is true</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">  if(fine_on AND opt STREQUAL &quot;fine&quot;)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    message(STATUS &quot;This is fine&quot;)</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">  # Only accept opt == good when good_on is true</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">  elseif(good_on AND opt STREQUAL &quot;good&quot;)</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    message(STATUS &quot;This is good&quot;)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">  # Everything else is bad</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">  else()</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    message(ERROR &quot; This is bad!&quot;)</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">  endif()</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">endforeach(opt ${options})</span><br><br>James<br style="font-family: courier new,monospace;">

<br>On Mon, Mar 30, 2009 at 4:28 AM, Marcel Loose &lt;<a href="mailto:loose@astron.nl">loose@astron.nl</a>&gt; wrote:<br>&gt; Hi all,<br>&gt;<br>&gt; I am running cmake version 2.6-patch 2.<br>&gt; I stumbled over the following, and I think it is a bug.<br>

&gt;<br>&gt; If I run cmake on this CMakeLists.txt:<br>&gt;<br>&gt; cmake_minimum_required(VERSION 2.6)<br>&gt; set(options<br>&gt;  fine<br>&gt;  good<br>&gt;  bad)<br>&gt; #option(fine &quot;Fine&quot; OFF)<br>&gt; #option(good &quot;Good&quot; OFF)<br>

&gt; option(bad &quot;Bad&quot; OFF)<br>&gt; foreach(opt ${options})<br>&gt;  message(STATUS &quot;opt = ${opt}&quot;)<br>&gt;  if(${opt} STREQUAL fine)<br>&gt;    message(STATUS &quot;This is fine&quot;)<br>&gt;  elseif(${opt} STREQUAL good)<br>

&gt;    message(STATUS &quot;This is good&quot;)<br>&gt;  else(${opt} STREQUAL fine)<br>&gt;    message(FATAL_ERROR &quot;This is bad!&quot;)<br>&gt;  endif(${opt} STREQUAL fine)<br>&gt; endforeach(opt ${options})<br>&gt;<br>

&gt; I get the following output:<br>&gt; ...<br>&gt; -- val = fine<br>&gt; -- fine<br>&gt; -- val = good<br>&gt; -- good<br>&gt; -- val = bad<br>&gt; CMake Error at CMakeLists.txt:14 (message):<br>&gt;  bad<br>&gt; ...<br>

&gt;<br>&gt; which is to be expected.<br>&gt;<br>&gt; However, when I uncomment the line option(fine...), I get the following<br>&gt; output:<br>&gt; ...<br>&gt; -- opt = fine<br>&gt; -- This is fine<br>&gt; -- opt = good<br>

&gt; -- This is good<br>&gt; -- opt = bad<br>&gt; -- This is fine<br>&gt; -- Configuring done<br>&gt; ...<br>&gt;<br>&gt; which is clearly wrong! Uncommenting the line option(good...) yields<br>&gt; almost the same output, but now the elseif branch is followed.<br>

&gt;<br>&gt; Is this a bug, or am I overlooking something?<br>&gt;<br>&gt; Best regards,<br>&gt; Marcel Loose.<br>&gt;<br>&gt;<br>&gt;<br>&gt; _______________________________________________<br>&gt; Powered by <a href="http://www.kitware.com">www.kitware.com</a><br>

&gt;<br>&gt; Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a><br>&gt;<br>&gt; Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ">http://www.cmake.org/Wiki/CMake_FAQ</a><br>

&gt;<br>&gt; Follow this link to subscribe/unsubscribe:<br>&gt; <a href="http://www.cmake.org/mailman/listinfo/cmake">http://www.cmake.org/mailman/listinfo/cmake</a><br>&gt;<br><br>