title: add_custom_command -- update dependency list over rebuilds
body: <p><em>See last status update</em></p>
  
  <p><strong>Initial conditions</strong> </p>
  
  <ul>
  <li>code generator that generates set of c++ sources taking one input file as parameter</li>
  <li>input file may include other input files</li>
  <li><p>already solved task of getting list of output files, parsing input codegen files to get full list of codegen inputs.
   I.e. add_custom_command is provided with correct set of dependencies for the first time:</p>
  
  <pre><code>add_custom_command(OUTPUT ${generatedSources}
                     COMMAND ${codegenCommand} ARGS ${codegenArgs}
                     DEPENDS ${codegenInputFiles})
  </code></pre></li>
  </ul>
  
  <p><strong>Problem scenario</strong></p>
  
  <ul>
  <li>current system works well until someone modifies one of codegen input files to include new input file or remove include of existing one. 
   This case, it is required to update list of codegen input file provided to add_custom_command as dependencies, but I have no idea how</li>
  </ul>
  
  <p><strong>What is missing</strong></p>
  
  <ul>
  <li>ability to update add_custom_command dependencies over project rebuilds</li>
  </ul>
  
  <p>Is there any way to solve it without making full project rebuild ?</p>
  
  <p><strong>UPDATE - Alternative (better?) problem description</strong></p>
  
  <p>I`ve found similar not answered question on cmake mailing list, post it here for better clarity:
  <a href="http://article.gmane.org/gmane.comp.programming.tools.cmake.user/52279" rel="nofollow">http://article.gmane.org/gmane.comp.programming.tools.cmake.user/52279</a></p>
  
  <p><em>I am trying to get a code generation tool to behave "the same as" a C source file with respect to dependencies. By that I mean, suppose you have a C file "a.c". Because it can #include files, every time the content of <code>a.c</code> changes, its dependencies may have changed also. The dependencies get rescanned with -MMD. I would like some way to emulate this for my code generator.
  First I tried add_custom_command, which takes a fixed DEPENDS list, determined at the time the custom command is defined. Concretely, I mean something like this:</em></p>
  
  <pre><code>function(add_generated_library)
     figure_out_dependencies(deps ${ARGN})
     add_custom_command(... DEPENDS ${deps})
  endfunction()
  </code></pre>
  
  <p><em>But that only captures the dependencies at build-system-generation time. Every time the custom command runs, the DEPENDS list may need to change, because the changes may imply new dependencies.How should I go about doing this?</em></p>
  
  <p><strong>UPDATE 2 - Possible solution</strong></p>
  
  <p>Following I consider as facts
   - there are voices across the web regarding cmake support of dynamic
     dependencies, which is required for smooth integration of many
     non-trivial code generation tools
   - there`s no ready-for-use optimal solution available, as what we actually need is hook to add support of custom DSL to IMPLICIT_DEPENDS </p>
  
  <p>From cmake manual:</p>
  
  <p><em>The IMPLICIT_DEPENDS option requests scanning of implicit dependencies of an input file. The language given specifies the programming language whose corresponding dependency scanner should be used. Currently only C and CXX language scanners are supported. The language has to be specified for every file in the IMPLICIT_DEPENDS list. <strong>Dependencies discovered from the scanning are added to those of the custom command at build time</strong>.</em> </p>
  
  <p>Solution below adheres (hopefully) to following criteria:</p>
  
  <ul>
  <li>avoid not necessary dependency scanning on rebuild</li>
  <li>avoid not necessary code generator run on rebuild</li>
  <li>allow providing cmake functions to clients to register their models and 
  generate code/create libraries from that code, without imposing any project structure requirements (i.e. no sub-project responsible for code generation, models are distributed across project hierarchy using project-specific policy)</li>
  </ul>
  
  <p>Solution idea</p>
  
  <p>It is not possible to register custom language scanner, but it is possible to reuse existing one. The idea is that dependencies / hierarchy of custom model files get reflected as hierarchy of "C" header files. Each hierarchy node get added on registering of model file and C file includes match model file includes. If model file includes get changed, C file includes get changed. Therefore, each codegen invocation would depend on just one generated C header reflecting passed model. Each reflected file will have a dependency on the model file and get touched on model file change.</p>
  
  <p><strong>To sum up : probably, my wording is not that clear at this point, but with respect to other people needs and community helped me to investigate this problem, I will post generic solution (+ link to github or new cmake wiki page) without my project specifics once it is ready (in 1-3 days).</strong></p>