[CMake] add_custom_command depending on add_custom_target

Giampiero Salvi giampi at kth.se
Thu Nov 13 18:42:19 EST 2008


Hi,
I have a custom command that has target-level dependencies. My problem 
is that this works fine if the target dependency was created by 
add_library, but not if it was created by add_custom_target. Example:

In the main CMakeLists.txt:

add_custom_command(
   OUTPUT mainoutputfile
   COMMAND mycommand...
   DEPENDS target-dep1 target-dep2
)
add_custom_target(maintarget ALL DEPENDS mainoutputfile)

In a subdirectory:

add_library(target-dep1 SHARED src1 src2...)

In another subdirectory:

add_custom_target(target-dep2 DEPENDS outputfile)

where outputfile is generated by another custom command.

This is what happens:
I can run "make target-dep1" and "make target-dept2" and the targets are 
correctly built, but if I run "make" or "make maintarget" I get the error:

...No rule to make target `target-dep2', needed by `mainoutputfile'...

 From the documentation of add_custom_command I read:
   [...]
   If DEPENDS specifies any target (created by an ADD_* command)  a
   target-level  dependency  is  created to make sure the target is
   built before any target using this  custom  command.   Addition‐
   ally,  if  the  target  is an executable or library a file-level
   dependency is created to cause  the  custom  command  to  re-run
   whenever the target is recompiled.
   [...]
where I interpret ADD_* as add_executable, add_library *and* 
add_custom_target.

Can you please tell me what I'm doing wrong?
Thank you,
Giampiero

I am running cmake version 2.6-patch 2 on Ubuntu Hardy


More information about the CMake mailing list