[CMake] Get all targets a target depends on

Matthew Woehlke matthew.woehlke at kitware.com
Mon Dec 2 15:16:42 EST 2013


On 2013-11-29 11:34, Dominik Bernhardt wrote:
> On 2013-11-29 17:26, Matthew Woehlke wrote:
>> On 2013-11-29 03:07, Dominik Bernhardt wrote:
>>> is it possible to get a list of all targets on which a particular
>>> target depends on. The only idea I have so far is to query the
>>> LINK_LIBRARIES target property. However that would only allow to get
>>> the libraries I'm linking with and for example no custom targets.
>>> Any ideas how to accomplish this task?
>>
>> I guess you want to make use of this information in CMake, and are not
>> just curious?
>
> you are absolutely right. It's not just for information. I have a lot of
> targets that I import and I would like query all dependent targets of my
> applications to figure out which DLLs are needed to run the application.
> I would use this information to either set the PATH environment or copy
> the DLLs to my binary directory

I'm not sure this can be made to work correctly in all cases. If you 
have e.g. imported libB which has a private depencency on libA, and are 
trying to build exeC linked to libB, libA won't be reported as a 
dependency of libB (and may not even be exported), but is still required 
to run exeC.

That said, given your use case, I'm not sure why you need to know about 
other than link libraries? How would a custom dependency create a 
runtime link dependency?

-- 
Matthew



More information about the CMake mailing list