title: cmake, add_custom_command with dependencies from a different directory
body: <p>I have a question about CMake which seems to be commonly asked here, but none of the answers seem to solve my problem.</p>
  
  <p>In the <code>details</code> subdirectory, there is a <code>CMakeLists.txt</code> which contains:</p>
  
  <pre><code>add_custom_command(OUTPUT part.out
                     COMMAND foo --input=part.src --output=part.out
                     DEPENDS part.src)
  
  add_custom_target(part_out
                    DEPENDS part.out)
  </code></pre>
  
  <p>In the main directory there is a <code>CMakeLists.txt</code> which uses <code>part.out</code> for generating another file:</p>
  
  <pre><code>add_custom_command(OUTPUT full.out
                     COMMAND bar --input=./details/part.out --output=full.out)
  
  add_custom_target(full_out
                    DEPENDS full.out)
  </code></pre>
  
  <p>The problem is that I want 3 things to happen here:</p>
  
  <ol>
  <li>if <code>part.out</code> doesn't exist it needs to be generated</li>
  <li>if <code>part.out</code> is out of date (<code>part.src</code> is newer than <code>part.out</code>) I want it to be regenerated</li>
  <li>if <code>full.out</code> is out of date (<code>part.out</code> is newer than <code>full.out</code>, or <code>full.out</code> desn't exist) I want it to be (re)generated</li>
  </ol>
  
  <p>So if I add <code>DEPENDS ./details/part.out</code> to <code>add_custom_command(OUTPUT full.out)</code> I will achieve points 2 and 3, but not point 1, because if I delete <code>part.out</code> and then I call <code>make full_out</code> I'll get an error that there is no rule to make <code>./details/part.out</code> (as it is a rule from another directory).</p>
  
  <p>If I add <code>DEPENDS full_out</code> to <code>add_custom_command(OUTPUT full.out)</code> or to <code>add_custom_target(full_out)</code> I'll achieve points 1 and 2, but not 3, because even if <code>part.out</code> was regenerated, a <code>full.out</code> will not be regenerated, as it doesn't depend on the <code>part.out</code> file itself.</p>
  
  <p>So how can I connect both scenarios?
  I was thinking about adding both <code>DEPENDS</code> but how do I know if that will always work? I mean in such case the order of build will matter here.</p>