title: CMake: generate header using custom tool output
body: <p>I'm porting some obscure library from autotools to cmake.</p>
  
  <p>The library in question compiles custom tool that outputs header into stdout, and this header is used later in the project.</p>
  
  <p>How can I port that to cmake?</p>
  
  <p>I can compile "header generator" using</p>
  
  <pre><code>add_executable(generator generator.c)
  </code></pre>
  
  <p>But how can I run it and redirect its output to header file using cmake? I'll also need dependency handling of course... (i.e. if generator.c changes, generator must be recompiled and header must be regenerated).</p>