[CMake] Adding non-file dependencies to a custom target

Giampiero Salvi giampi at kth.se
Mon Oct 20 07:54:22 EDT 2008


Hi,
I have a large project that includes a number of sub targets (subtgt1 
subtgt2...) each generating both linked libraries and tcl files (each 
sub target generates several files). The project also includes a main 
custom target maintgt that wraps the libs+tcl files into one executable 
using a custom command. The problem is I did not find a good way to make 
the maintgt dependent on the the sub targets (listing all generated 
files into the custom command's DEPENDS field would be really tedious).

Here is how the main target looks like:

ADD_CUSTOM_COMMAND(
  OUTPUT ${EXECUTABLE_OUTPUT_PATH}/maintgt${CMAKE_EXECUTABLE_SUFFIX}
  COMMAND ${TCL_TCLSH} ${PROJECT_SOURCE_DIR}/wrap.tcl ${SDX_EXECUTABLE} 
${TCLKIT_RUNTIME} ${TCLKITSH_RUNTIME} 
${EXECUTABLE_OUTPUT_PATH}/maintgt${CMAKE_EXECUTABLE_SUFFIX}
  WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
ADD_CUSTOM_TARGET(maintgt ALL
  DEPENDS ${EXECUTABLE_OUTPUT_PATH}/synface${CMAKE_EXECUTABLE_SUFFIX}
)
ADD_DEPENDENCIES(maintgt subtgt1 subtgt2 subtgt3...)

This doesn't work: rebuilding the sub targets does not trigger 
rebuilding the main target.

I also tried to use DEPENDS in the custom command, but I read on the 
list that that is only for file dependencies.

The question is: is there a way to specify high level dependencies in a 
custom target? What am I doing wrong?

It might help to know that the sub targets are built in subdirectories 
(I read on the list somewhere that this might make a difference).

Thank you very much!
Giampiero

I'm using CMake 2.6-patch 0 on Ubuntu and Mingw


More information about the CMake mailing list