[CMake] add_custom_command and DEPENDS

Michael Hertling mhertling at online.de
Tue Sep 20 13:34:53 EDT 2011


On 09/20/2011 07:00 PM, Talin wrote:
> After several years of working with CMake, I have to say that I still do not
> understand the behavior of the DEPENDS clause in add_custom_command.
> 
> The main problem is a fairly simple one: I have an add_custom_command in one
> subdirectory, the output of which is needed by an add_custom_command in
> another subdirectory. Since add_custom_command can't refer to targets in
> other directories, I have followed the advice of various experts (on this
> list and on stackoverflow) and made additional targets via
> add_custom_target, in both subdirectories.
> 
> So in directory A, I have an add_custom_command which generates a file, and
> then I have an add_custom_target which depends on that file. In directory B,
> I have another custom target which uses add_dependencies to add a dependency
> to the custom target defined in A. Finally, I have an add_custom_command
> which has a DEPENDS clause adding a dependency to the target defined in that
> directory.
> 
> It's the last step that doesn't work - it says "No rule to make target
> <targetname>, needed by <filename>.  Stop." Even though <targetname> is
> defined earlier in the same CMakeLists.txt file.
> 
> According to my reading of the CMake documentation, this should work
> (although the docs are quite confusing on this point). Here's what the doc
> says about the DEPENDS clause of add_custom_command: "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." I'm assuming that the words "specifies any target" means that you
> can pass the name of a target as an argument to DEPENDS. If that's not what
> it means, please tell me.
> 
> Caveat: I'm still working with 2.8.3 - I see that generator expressions in
> 2.8.4 would solve my problems, but at the moment I'm stuck with the version
> that Ubuntu distributes.
> 
> In any case, I've been struggling with this specific problem off and on for
> over 3 years, asking for help on various forums, and I've never found an
> answer that actually works for me.

See [1] and upgrade; the generator expressions per se are worth the effort.

Regards,

Michael

[1] http://public.kitware.com/Bug/view.php?id=12057


More information about the CMake mailing list