title: Cmake generator expression command
body: <p>If some boolean condition is true (such as ENABLE_TESTING) then I want to run something like:</p>
  
  <pre><code>COMMAND ./b2 --with-filesystem --with-program_options --with-test
  </code></pre>
  
  <p>And if the boolean condition is false, then I instead want:</p>
  
  <pre><code>COMMAND ""
  </code></pre>
  
  <p>It seems like I can achieve that with this very ugly code:</p>
  
  <pre><code>COMMAND $&lt;$&lt;BOOL:${ENABLE_TESTING}&gt;:./b2&gt; $&lt;$&lt;BOOL:${ENABLE_TESTING}&gt;:--with-filesystem&gt; $&lt;$&lt;BOOL:${ENABLE_TESTING}&gt;:--with-program_options&gt; $&lt;$&lt;BOOL:${ENABLE_TESTING}&gt;:--with-test&gt;
  </code></pre>
  
  <p>But as you can see, I have to repeat the boolean test over and over. If I naively try to combine them into a single expression:</p>
  
  <pre><code>COMMAND $&lt;$&lt;BOOL:${ENABLE_TESTING}&gt;:./b2 --with-filesystem --with-program_options --with-test&gt;
  </code></pre>
  
  <p>Then I get the error <code>/bin/sh: 1: $&lt;1:./b2: not found</code>. The spaces, apparently, get parsed before the generator expression is evaluated. So I quote the whole thing:</p>
  
  <pre><code>COMMAND "$&lt;$&lt;BOOL:${ENABLE_TESTING}&gt;:./b2 --with-filesystem --with-program_options --with-test&gt;"
  </code></pre>
  
  <p>But this produces the error <code>/bin/sh 1: /b2 --with-filesystem --with-program_options --with-test: not found</code>. I suppose it's treating the whole thing as the name of a command rather than a command with options. How can I write this in a way that is clean and works?</p>
  
  <p>EDIT: I've tried to simplify the code for a minimum example, but there's an extra complication I left out. This command is happening in an <code>ExternalProject_Add</code> section, and I need to rely on special tokens such as <code>&lt;BINARY_DIR&gt;</code>.</p>
  
  <pre><code>COMMAND ./b2 "--stagedir=&lt;BINARY_DIR&gt;" --with-filesystem --with-program_options --with-test
  </code></pre>
  
  <p>I can't move the commands into an if statement elsewhere, because if I do then the directory tokens aren't expanded.</p>