title: Use cmake to conditionally generate source input files
body: <p>I'm using cmake with C++ project. I want to use precompiled headers in GCC.</p>
  
  <p>I want to run <code>cmake</code> once and then, when running <code>make</code>, I want this actions to happen:</p>
  
  <ol>
  <li>Run my custom tool (python script) on whole source tree. It generates precompiled.h headers in some subdirectories. It's purpose is to scan *.h and *.cpp for #include's and move them to common precompiled.h files.</li>
  <li>generate GCC's precompiled headers (<code>g++ -c precompiled.h -o precompiled.h.gch</code>) ONLY when precompiled.h file has changed after step 1.</li>
  <li>build outdated targets (after step 2. because I want to use .gch file)</li>
  </ol>
  
  <p>I've managed to add dependencies, so whenever I build any target, my python script's target is executed (this is ugly, because now every target has to depend on single global_init target). Also I can modify my python script, so it doesn't modify precompiled.h when it is not necessary.</p>
  
  <p>But I don't know what to do next. Is there any way to tell cmake that it should run my custom script and AFTER THAT determine if precompiled.h.gch must be created? Now it is always build (this file contains many #include's, so it takes some time). Basically:</p>
  
  <ol>
  <li>Execute python script -> precompiled.h MAY BE updated</li>
  <li>Examine precompiled.h timestamp and if it's newer -> build precompiled.h.gch</li>
  <li>Standard compilation steps</li>
  </ol>
  
  <p>I've looked in many places, but cmake's (and make's) way of calculating dependencies seems too weak to accomplish this task.</p>
  
  <p>In this question:
  <a href="https://stackoverflow.com/questions/2687136/how-do-i-make-build-rules-in-cmake-to-preprocess-lazy-c-lzz-files-that-generat">lazy c++</a>
  compilation always happens after lazycpp is executed. This would not be optimal in my case.</p>