title: Use CMake add_custom_command to generate source for another target
body: <p>I tried this dummy example:</p>
  
  <h1>CMakeLists.txt</h1>
  
  <pre><code>cmake_minimum_required( VERSION 2.8 )
  project( testcmake )
  
  add_custom_command(
    OUTPUT testcmake.h
    COMMAND xxd -i testcmake.txt testcmake.h
    DEPENDS testcmake.txt
  )
  
  add_executable( testcmake testcmake.c testcmake.h )
  </code></pre>
  
  <h1>testcmake.c</h1>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include "testcmake.h"
  
  int main()
  {
      int i;
  
      for ( i = 0 ; i &lt; testcmake_txt_len ; i++ )
      {
          fputc( testcmake_txt[ i ] , stdout );
      }
  }
  </code></pre>
  
  <h1>testcmake.txt</h1>
  
  <pre><code>foo
  bar
  baz
  </code></pre>
  
  <h1>The problem</h1>
  
  <p>It fails with:</p>
  
  <pre><code>[...]
  xxd: testcmake.txt: No such file or directory
  [...]
  </code></pre>
  
  <p>Adding <code>WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}</code> makes everything works fine but I don't want the output of my custom command appears in my source directory, I want that all the intermediate files remain in the CMake build directory just like any non custom rule.</p>