[CMake] target DEPENDS are ignored if the target is also used for the COMMAND

Alan W. Irwin irwin at beluga.phys.uvic.ca
Sat Oct 24 13:21:52 EDT 2009


The following CMake logic fragment illustrates the issue:

add_executable(plhershey-unicode-gen ${plhershey-unicode-gen_SRCS})

add_custom_command(
   OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/plhershey-unicode.h
   COMMAND plhershey-unicode-gen
   ${CMAKE_SOURCE_DIR}/fonts/plhershey-unicode.csv
   ${CMAKE_CURRENT_BINARY_DIR}/plhershey-unicode.h
   DEPENDS
   plhershey-unicode-gen
   ${CMAKE_SOURCE_DIR}/fonts/plhershey-unicode.csv
   )

add_custom_target(
   plhershey-unicode.h_built
   DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/plhershey-unicode.h
   )

If I touch the source for plhershey-unicode-gen and run "make
plhershey-unicode.h_built", then plhershey-unicode-gen gets rebuilt but the
custom command is not re-run.  Apparently, a target is ignored as a DEPENDS
if it is also used as a COMMAND.  That doesn't seem correct to me.

The workaround is to replace the COMMAND by the location of the 
plhershey-unicode-gen executable.  In that case, if I touch the source for
plhershey-unicode-gen and run "make plhershey-unicode.h_built", then
plhershey-unicode-gen gets rebuilt, and so does plhershey-unicode.h.

According to the documentation you should be able to use targets for
COMMANDs, and targets for DEPENDS.  Furthermore according to the
documention, in the former case the file depends are not taken care of, but
in the latter case they should be (for add_executable or add_library
targets).  I believe it is a bug in the implemention that the latter case is
ignored when the target is also used for the COMMAND.

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 libLASi project (unifont.org/lasi); 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