title: cmake: struggling with add_custom_command dependencies
body: <p>I'm trying to get a file produced by an add_custom_command in one directory to be a dependency of an add_custom_command in another directory.</p>
  
  <p>In the first directory (lib/core) I have a build command that looks like this:</p>
  
  <pre><code>add_custom_command(
      OUTPUT libcore.bc
      COMMAND tartln -filetype=bc -link-as-library -o libcore.bc ${STDLIB_BC_FILES}
      DEPENDS ${STDLIB_BC_FILES} tartln
      COMMENT "Linking libcore.bc")
  </code></pre>
  
  <p>In the second directory, I have a command that uses the output of that command:</p>
  
  <pre><code>add_custom_command(OUTPUT ${OBJ_FILE}
      COMMAND tartln -disable-fp-elim -filetype=obj -o ${OBJ_FILE} ${BC_FILE}
          "${PROJECT_BINARY_DIR}/lib/core/libcore.bc"
      MAIN_DEPENDENCY "${BC_FILE}" 
      DEPENDS "${PROJECT_BINARY_DIR}/lib/core/libcore.bc"
      COMMENT "Linking Tart bitcode file ${BC_FILE}")
  </code></pre>
  
  <p>However, when I try to build, I get the following error:</p>
  
  <pre><code>make[3]: *** No rule to make target `lib/core/libcore.bc', needed by `test/stdlib/ReflectionTest.o'.  Stop.
  </code></pre>
  
  <p>One weird thing that I see is that the path in the error message is a relative, not an absolute path, despite the fact that I know that ${PROJECT_BINARY_DIR} is a full, correct path. I don't know if this is a problem or just a strangeness of make.</p>
  
  <p>I've also tried making a top-level target for the libcore library, in the lib/core directory:</p>
  
  <pre><code>add_custom_target(libcore DEPENDS libcore.bc libcore.deps)
  </code></pre>
  
  <p>And then using that in the DEPENDS clause. The strange thing about that is it works the first time you do a clean build, but gives an error on any subsequent build. In any case, my understanding is DEPENDS is only supposed to work for file dependencies, so this doesn't seem like the correct solution. (How do you have a custom command that depends on a top-level target then?)</p>
  
  <p>I've also tried putting absolute paths everywhere, no effect.</p>