title: How to only build auto generated code when the generator or input changes in CMake?
body: <p>I am working on a source code repository that generates some C++ code by running a python script outputting headers and implementation. This code is subsequently compiled and linked to my libraries and executables. I know that the generated code will only change if one of two conditions are true:</p>
  
  <ol>
  <li>The generator code itself changes </li>
  <li>The input (an XML file) to the generator changes</li>
  </ol>
  
  <p>I want to use cmake to manage the build process. At the moment, I am using <code>execute_process</code> to fire off the generator. However, this runs every time I run cmake and it touches the files, causing my generated code to be recompiled and adding to my total compile time.</p>
  
  <p>I also want to make sure that the generated code is always run before my libraries. In other words, I want the libraries to depend on the generator to have run.</p>
  
  <p>What is the proper way to handle such a situation in cmake? I have seen this previous answer: "<a href="https://stackoverflow.com/questions/5385148/get-cmake-to-execute-a-target-in-project-before-building-a-library">Get CMake to execute a target in project before building a library</a>". But this relies on the output of the code generator being known in advance. My code generator will generate a variable number of files.</p>