title: Execute output of cmake target as dependency for another
body: <p>I have the following directory structure:</p>
  
  <pre><code>.
  ├── CMakeLists.txt
  ├── generator
  │   ├── CMakeLists.txt
  │   └── main.cpp
  ├── include
  └── src
      ├── CMakeLists.txt
      └── mylib.cpp
  </code></pre>
  
  <p>I would like to build <code>generator</code>, then use generator to generate a source file that will be used to build mylib. I tried this:</p>
  
  <p>generator/CMakeLists.txt:</p>
  
  <pre><code>add_executable(gen main.cpp)
  
  add_custom_command(
      OUTPUT
          ${CMAKE_BINARY_DIR}/generated.cpp
      DEPENDS
          gen
      COMMAND
          ${CMAKE_BINARY_DIR}/gen -d /tmp
      VERBATIM
  )
  </code></pre>
  
  <p>src/CMakeLists.txt:</p>
  
  <pre><code>add_library(py-cppast
          ${CMAKE_BINARY_DIR}/generated.cpp
          mylib.cpp)
  </code></pre>
  
  <p>CMakeLists.txt:</p>
  
  <pre><code>cmake_minimum_required(VERSION 3.1.2)
  project(my-project)
  
  add_subdirectory(generator)    
  add_subdirectory(src)
  </code></pre>
  
  <p>However, the command is not executed. Instead, I just get the error:</p>
  
  <pre>
  CMake Error at src/CMakeLists.txt:2 (add_library):
    Cannot find source file:
  
      /home/....(the cmake binary dir)..../generated.cpp
  
    Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
    .hxx .in .txx
  </pre>
  
  <p>How can I tell cmake to execute the program I'm building with it? Is this even possible in a single build?</p>