title: In CMake how do I create a file needed at configure time?
body: <p><strong>Edit:</strong> my question targets the early <strong>configure</strong> stage where CMake input files are still being parsed and thus have to be present before <code>include()</code> is being called. So the answer found here: <a href="https://stackoverflow.com/questions/31057208/">Force CMake to generate configure_file target every build</a> does <em>not</em> solve my problem since it generates files <em>after</em> <code>include()</code> statements have been interpreted.</p>
  
  <hr>
  
  <p>I have a <code>CMakeLists.txt</code> that <strong>includes</strong> a file which is generated in the <em>configure</em> stage:</p>
  
  <pre><code>execute_process(COMMAND "my-generator -o generated.cmake")
  include(generated.cmake)
  </code></pre>
  
  <p>Apart from the fact that this approach doesn't feel right (not to say elegant) I now need to re-generate that file <em>before every build</em> (<code>my-generator</code> produces output that incorporates the current time).</p>
  
  <p>My assumption is that I can't use <code>add_custom_command()</code> or <code>add_custom_target()</code> because the file would be generated at compile time but needed in the configure-step.</p>
  
  <p><a href="http://cmake.3232098.n2.nabble.com/How-to-force-the-configure-step-to-start-over-td5698661.html" rel="nofollow noreferrer">This</a> very old post suggests to <code>touch</code> the input file so I did this:</p>
  
  <pre><code>execute_process(
      COMMAND "my-generator -o generated.cmake"
      COMMAND cmake -E touch "${CMAKE_CURRENT_LIST_FILE}")
  </code></pre>
  
  <p>.. which does not produce errors but calling <code>make</code> multiple times won't run the configure step more than once.</p>
  
  <p>What do I do wrong? Is there a better approach?</p>