[CMake] What is the preferred method of establishing the dependence of a custom command on an executable target?

Alan W. Irwin irwin at beluga.phys.uvic.ca
Mon Apr 9 13:17:44 EDT 2007


On 2007-04-09 09:27-0400 Bill Hoffman wrote:

> Actually from the wiki:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Your custom commands should look like this:
>
> ADD_CUSTOM_COMMAND(
> OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/foo0.qaz
> COMMAND ${DOIT_EXE} ${CMAKE_CURRENT_SOURCE_DIR}/someinput0.txt 
> ${CMAKE_CURRENT_BINARY_DIR}/foo0.qaz
> DEPENDS ${DOIT_EXE})
>
> [...]ADD_DEPENDENCIES(foo-files doit)
>
> is no longer required, and is implied by the custom commands.

Our windows user now reports success with this style of dependencies. Its
the "linear" chain of dependencies I had originally, but implemented
properly with the "${DOIT_EXE}" variable determined by the GET_TARGET_PROPERTY
LOCATION property determined with GET_TARGET_PROPERTY.

My thanks to Brandon and Bill for helping me to improve my implementation
of making a custom command file depend on an executable.

As part of my investigation, I found the alternative "forked" chain of
dependencies (using ADD_DEPENDENCIES(foo-files doit) to make the custom
target depend on the executable rather than the custom command) does not
give the desired result.  Touching the source of the executable just
rebuilds the executable and reruns the (empty) custom target, but does not
rerun the custom command.  That's just what you should expect if you think
about it.  It's amazing how computers do exactly what they are told. :-)

Also, as part of the investigation I found that preparing the header in one
subdirectory with the custom command and putting that header in the source
list of a library built in a different subdirectory does not work.  The
library build in the separate subdirectory has no idea that the header is
generated, and therefore errors out with a missing file message.  I
therefore stuck with my original method which was to use ADD_DEPENDENCIES to
make the library depend on the custom target, and that seems to work fine.

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the Yorick front-end to PLplot (yplot.sf.net); the
Loads of Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


More information about the CMake mailing list