title: How to chain custom_targets from different directories in CMake without global variables?
body: <p>According to this tutorial (Part 5):</p>
  
  <p><a href="https://samthursfield.wordpress.com/2015/11/21/cmake-dependencies-between-targets-and-files-and-custom-commands/" rel="nofollow noreferrer">https://samthursfield.wordpress.com/2015/11/21/cmake-dependencies-between-targets-and-files-and-custom-commands/</a></p>
  
  <blockquote>
    <p>File-level dependencies of custom targets are not propagated</p>
  </blockquote>
  
  <p>So when I have two custom targets in chain, second custom command should depend both on <strong>first custom target</strong> and <strong>first custom command output</strong></p>
  
  <p>But what if I have custom targets in different sub-directories. How can I get path to files generated by first target?</p>
  
  <pre><code>project
  ├── gen1
  │   └── CMakeLists.txt
  ├── gen2
  │   └── CMakeLists.txt
  └── CMakeLists.txt
  </code></pre>
  
  <p>gen1 CMakeLists.txt:</p>
  
  <pre><code>set(SPECIAL_TEXT foo)    
  add_custom_command(
      OUTPUT gen1
      COMMAND cmake -E echo ${SPECIAL_TEXT} &gt; gen1
      )
  
  add_custom_target(
      gen1-wrapper
      DEPENDS gen1
      )
  </code></pre>
  
  <p>gen2 CMakeLists.txt:</p>
  
  <pre><code>add_custom_command(
      OUTPUT gen2
      DEPENDS gen1-wrapper **????????**
      COMMAND cmake -E copy gen1 gen2
      )
  
  add_custom_target(
      all-generated ALL
      DEPENDS gen2
      )
  </code></pre>
  
  <p>top CMakeList.txt</p>
  
  <pre><code>add_subdirectory(gen2)
  add_subdirectory(gen1)
  </code></pre>
  
  <p>Is it possible to propagate dependencies without introducing global variables?</p>