1

I have a project in which the output of one custom command is used as the input to another, but in a different directory. So for example:

Directory lib/CMakeLists.txt contains:

add_custom_command(
    OUTPUT libfoo.xx
    COMMAND <command to build libfoo.xx>
)
add_custom_target(libfoo DEPENDS libfoo.xx)

Directory test/CMakeLists.txt contains:

add_custom_command(OUTPUT test.yy
   COMMAND <command to build test.yy>
   DEPENDS "${PROJECT_BINARY_DIR}/lib/libfoo.xx"
)

So I need to make sure that libfoo is build before test.yy. The docs say that the DEPENDS clause of add_custom_command() can only have file-level dependencies. Let's try that and see what happens:

No rule to make target 'lib/libfoo.xx', needed by 'test/test.yy'.  Stop.

If on the other hand, I attempt to create a target-level dependency by saying DEPENDS libfoo, then the error changes to:

No rule to make target 'libfoo', needed by 'test/test.yy'.  Stop.

So it seems neither file-level or target-level dependencies will work here. Is there any way to have the output from one custom command be the input to another custom command, in a different directory?

einpoklum
  • 118,144
  • 57
  • 340
  • 684
Talin
  • 1,397
  • 2
  • 15
  • 30
  • 2
    Is there an outermost CMakeLists.txt file which adds both the lib and the test directory with add_subdirectory? – sakra May 01 '11 at 09:03

1 Answers1

0

You could try in test/CMakLists.txt to add

add_custom_target(test DEPENDS test.yy)

and then to add

add_dependencies(test libfoo)

in your top-level CMakeLists.txt.

Disclaimer: I didn't test it and I'm a CMake beginner. Tell us if it works!

Simon
  • 31,675
  • 9
  • 80
  • 92