title: cmake bind custom command to a existed top level target fails
body: <p>I want to have one top level custom target, and nested submodules which are able to extend this already existed target by adding/binding custom_command to it. For now I face a problem: if <code>add_custom_command(TARGET target_name ...)</code> is used not in a file where the target is defined (target is defined on top level CMakeLists.txt), then this custom_command is simply ignored. </p>
  
  <p><strong>Details:</strong></p>
  
  <p>1) custom_target created on the top-level <em>CMakelists.txt</em></p>
  
  <pre><code>cmake_minimum_required(VERSION 2.8)
  
  add_custom_target(custom_tg
  COMMAND ls &gt; custom_target.txt
  )
  
  add_custom_command(TARGET custom_tg
  COMMAND ls &gt; custom_command1.txt
  )
  
  add_subdirectory(sub)
  </code></pre>
  
  <p>2) In subdirectory "sub" there is other <em>CMakeLists.txt</em> (module) which I was hoping is able to extend the existed target with custom command.</p>
  
  <pre><code>add_custom_command(TARGET custom_tg
  COMMAND ls &gt; custom_command2.txt 
  )
  </code></pre>
  
  <p>3) When I create build directory and run</p>
  
  <pre><code>cmake .. &amp;&amp; make custom_tg
  </code></pre>
  
  <p>the output files are <em>custom_target.txt</em> and <em>custom_command1.txt</em>, but there is no <em>custom_command2.txt</em>, and that's actually my problem is.</p>
  
  <p>If I look into <em>build/CMakeFiles/custom_tg.dir/build.make</em> I see no mention about <em>custom_command2.txt</em> there. Here is content of <em>build.make</em> file: <a href="http://pastebin.com/zVVS4sYL" rel="nofollow">http://pastebin.com/zVVS4sYL</a>.</p>
  
  <p>Actually I can't find any mention about <em>custom_command2.txt</em> in tree of files generated by Cmake, and this looks weird to me.</p>
  
  <p>Looking forward for you help.</p>