title: cmake add_custom_command issue with multiple output files
body: <p>I'm noticing some potential incorrect behavior in cmake when working with <code>add_custom_command</code> and multiple output files.  I've been able to isolate the problem to a minimal example (see below). It seems that when I have two output files specified in my <code>add_custom_command</code>, the second output file's upstream dependencies are not being tracked correctly in some cases.  The <a href="http://www.cmake.org/cmake/help/v2.8.12/cmake.html#command%3aadd_custom_command">cmake documentation</a> clearly mentions that multiple output files are allowed.  What's interesting here is that swapping the order of the output files causes different behavior, suggesting that the first <code>OUTPUT</code> file is being treated differently.</p>
  
  <p>Please refer to the toy example below that exhibits this behavior. The first call to make runs just fine. After touching <code>a.txt</code>, the <code>Copying baz.cpp to baz2.cpp</code> rule doesn't execute on the first call to <code>make</code>, but runs on the second call to <code>make</code>. This means that the build will still be stale after a single call to <code>make</code>.  Note that this issue is fixed by changing the order of the outputs in <code>add_custom_command</code> to <code>OUTPUT baz.cpp bar.cpp</code></p>
  
  <p><code>Example CMakeLists.txt:</code></p>
  
  <pre><code>cmake_minimum_required(VERSION 2.8)
  
  add_library(mybaz baz.cpp)
  
  add_custom_command(
    OUTPUT  baz2.cpp
    COMMAND cp baz.cpp baz2.cpp
    DEPENDS baz.cpp
    COMMENT "Copying baz.cpp to baz2.cpp")
  
  add_custom_target(mytarget
    DEPENDS baz2.cpp
    COMMENT "Running mytarget")
  
  add_dependencies(mybaz mytarget)
  
  add_custom_command(
    OUTPUT  bar.cpp baz.cpp
    COMMAND cat a.txt &gt; bar.cpp
    COMMAND cat a.txt &gt; baz.cpp
    DEPENDS a.txt
    COMMENT "Generating bar.cpp and baz.cpp")
  </code></pre>
  
  <p>Below are the commands that I run:</p>
  
  <pre><code>&gt; touch a.txt
  &gt; cmake .
      ...snip... (configuration runs fine)
  &gt; make
  Scanning dependencies of target mytarget
  [ 20%] Generating bar.cpp and baz.cpp
  [ 40%] Copying baz.cpp to baz2.cpp
  [ 60%] Running mytarget
  [ 60%] Built target mytarget
  Scanning dependencies of target mybaz
  [ 80%] Building CXX object CMakeFiles/mybaz.dir/baz.cpp.o
  Linking CXX static library libmybaz.a
  [100%] Built target mybaz
    (everything looks good)
  
  &gt; touch a.txt
  &gt; make
  [ 20%] Generating bar.cpp and baz.cpp
  [ 40%] Running mytarget
  [ 60%] Built target mytarget
  Scanning dependencies of target mybaz
  [ 80%] Building CXX object CMakeFiles/mybaz.dir/baz.cpp.o
  Linking CXX static library libmybaz.a
  [100%] Built target mybaz
    (I seem to be missing the 'Copying baz.cpp to baz2.cpp' line)
  
  &gt; make
  [ 20%] Copying baz.cpp to baz2.cpp
  [ 40%] Running mytarget
  [ 60%] Built target mytarget
  [100%] Built target mybaz
    ( The 'Copying baz.cpp to baz2.cpp' executes this time )
  </code></pre>
  
  <p>This has been tested using CMake version 2.8.12.2 on a linux machine.</p>
  
  <p>Thanks in advance for your help!</p>