# CMake Property + Generator expression to get all dependent libraries?

**URL:** <https://discourse.cmake.org/t/cmake-property-generator-expression-to-get-all-dependent-libraries/1898>\
**Category:** Code\
**Created:** [September 23, 2020, 3:17am UTC](https://discourse.cmake.org/t/cmake-property-generator-expression-to-get-all-dependent-libraries/1898 "2020-09-23T03:17:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndrewGaspar](https://discourse.cmake.org/user_avatar/discourse.cmake.org/andrewgaspar/32/137_2.png) [@AndrewGaspar](https://discourse.cmake.org/u/AndrewGaspar)\
**Post date:** [September 23, 2020, 3:17am UTC](https://discourse.cmake.org/t/cmake-property-generator-expression-to-get-all-dependent-libraries/1898/1 "2020-09-23T03:17:55Z")

</div>

Is there any way to get the list of _all_ dependent libraries for a target, including transitive dependencies, via a generator expression? The Target property [`INTERFACE_LINK_LIBRARIES`](https://cmake.org/cmake/help/latest/prop_tgt/INTERFACE_LINK_LIBRARIES.html) says it includes transitive dependencies, but in my testing, that didn’t seem to be the case.

---

<div class="post-metadata">

**Author:** ![robert.maynard](https://discourse.cmake.org/user_avatar/discourse.cmake.org/robert.maynard/32/4_2.png) [@robert.maynard](https://discourse.cmake.org/u/robert.maynard)\
**Post date:** [September 23, 2020, 3:28pm UTC](https://discourse.cmake.org/t/cmake-property-generator-expression-to-get-all-dependent-libraries/1898/2 "2020-09-23T15:28:03Z")

</div>

CMake doesn’t have generator expression that will give you the complete list of dependent targets.

A generator expression that provided this would require a significant change in how generator expressions are evaluated and introduce new context sensitive rules. Consider a generator expression that does

- Adds target `B` if not target `A` is in the dependent list
- Adds target `A` if any other target is in the dependent list

The result of `dependent list` now changes depending where we are in the evaluation of a generator expression, and now is context sensitive.

---

<div class="post-metadata">

**Author:** ![AndrewGaspar](https://discourse.cmake.org/user_avatar/discourse.cmake.org/andrewgaspar/32/137_2.png) [@AndrewGaspar](https://discourse.cmake.org/u/AndrewGaspar)\
**Post date:** [September 23, 2020, 6:09pm UTC](https://discourse.cmake.org/t/cmake-property-generator-expression-to-get-all-dependent-libraries/1898/3 "2020-09-23T18:09:58Z")

</div>

Ah, that’s a good point. That’s too bad. Thanks!

---

<div class="post-metadata">

**Author:** ![AndrewGaspar](https://discourse.cmake.org/user_avatar/discourse.cmake.org/andrewgaspar/32/137_2.png) [@AndrewGaspar](https://discourse.cmake.org/u/AndrewGaspar)\
**Post date:** [October 14, 2020, 6:46pm UTC](https://discourse.cmake.org/t/cmake-property-generator-expression-to-get-all-dependent-libraries/1898/4 "2020-10-14T18:46:21Z")

</div>

I saw the new [`cmake_langauge(DEFER ...)`](https://cmake.org/cmake/help/latest/command/cmake_language.html#deferring-calls) command in CMake 3.19, and I thought maybe I could use that to get a good approximation. Sure, I can’t follow generator expressions, but could at least get those explicitly defined dependencies.

However, it looks like I probably can’t run a cmake script using that, at least in the context of the generator process. Is that right?

---

<div class="post-metadata">

**Author:** ![AndrewGaspar](https://discourse.cmake.org/user_avatar/discourse.cmake.org/andrewgaspar/32/137_2.png) [@AndrewGaspar](https://discourse.cmake.org/u/AndrewGaspar)\
**Post date:** [October 14, 2020, 6:48pm UTC](https://discourse.cmake.org/t/cmake-property-generator-expression-to-get-all-dependent-libraries/1898/5 "2020-10-14T18:48:08Z")

</div>

Oh, looks like maybe I’m misunderstanding `<command>`. I had interpreted that to mean an executable of some sorts, but it looks like it’s actually a cmake function or macro? That is kind of confusing, imo - ~~I think “command” is typically used in CMake to refer to things like running executables, such as in `add_custom_target` and `and_custom_command`.~~

EDIT: I’m mistaken, command is used all the time. Regardless, I wish there was some clarity in this documentation about that.

---

<div class="post-metadata">

**Author:** ![robert.maynard](https://discourse.cmake.org/user_avatar/discourse.cmake.org/robert.maynard/32/4_2.png) [@robert.maynard](https://discourse.cmake.org/u/robert.maynard)\
**Post date:** [October 15, 2020, 12:50pm UTC](https://discourse.cmake.org/t/cmake-property-generator-expression-to-get-all-dependent-libraries/1898/6 "2020-10-15T12:50:55Z")

</div>

You are correct. It might make sense for the command documentation to be `<cmake_command>`
