CMake Property + Generator expression to get all dependent libraries?

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 says it includes transitive dependencies, but in my testing, that didn’t seem to be the case.

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.

1 Like

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

I saw the new cmake_langauge(DEFER ...) 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?

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.

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

1 Like