title: CMake: How to add a custom command that is only executed for one configuration?
body: <p>I want to add a cmake custom command that is only executed when the custom target is build in the Debug configuration while using the Visual Studio multi-config generator. Is there a clean way to do this?</p>
  
  <p>In order to implement this, I first tried wrapping the whole command list in a generator expression like this.
  </p>
  
  <pre><code>add_custom_command(
      ...
      COMMAND $&lt;$&lt;CONFIG:Debug&gt;:cmake;-E;echo;foo&gt;
  )
  </code></pre>
  
  <p>But this gives me a syntax error when the command is executed. After some trial-and-error I got the following hacky solution to work. This wraps each word of the command list in a generator expression like this.</p>
  
  <pre><code>add_custom_command(
      ...
      COMMAND $&lt;IF:$&lt;CONFIG:Debug&gt;,cmake,echo&gt;;$&lt;IF:$&lt;CONFIG:Debug&gt;,-E, &gt;;$&lt;IF:$&lt;CONFIG:Debug&gt;,echo, &gt;;$&lt;IF:$&lt;CONFIG:Debug&gt;,foo, &gt;
  )
  </code></pre>
  
  <p>This executes the <code>cmake -E echo foo</code> command when compiling the Debug configuration and the dummy command <code>echo " " " " " "</code> for all other configurations.</p>
  
  <p>This is quite ugly and the dummy command must be changed depending on the host system. On Linux it could be <code>":" ":" ":" ":"</code>. So Is there a cleaner way to do this?</p>
  
  <p>Thank you for your time!</p>