0

Is there any way to get a list of all the alias targets of a given target?

It is quite straightforward to get the target given an alias-target of it by using get_target_property(x x_alias ALIASED_TARGET), but I can't find a way to do the other way around.

starball
  • 20,030
  • 7
  • 43
  • 238
  • 1
    CMake doesn't store list of aliases for a target. At least, it doesn't export that information to the script. You could iterate over all targets (see e.g. [that question] (https://stackoverflow.com/questions/37434946/how-do-i-iterate-over-all-cmake-targets-programmatically)) and select ones which are aliases for the specific target. Note, that not every kind of target has ALIASED_TARGET property, so before read the property of iterated target you need to check whether the target has given property. – Tsyvarev Jul 27 '22 at 06:48
  • 1
    Except for debugging someone else's code, I can't imagine why this would be useful... why do you want to do this? – Alex Reinking Jul 27 '22 at 13:51
  • @Tsyvarev I thought about that solution. but alias is not generated as a target, but just a read-only reference. In that case, even when I extract all the targets `get_all_targets()`, there is no alias that can be detected. – Toothless Jul 28 '22 at 03:27
  • @AlexReinking It's true. I wanna make sure everyone use alias all over the project. – Toothless Jul 28 '22 at 03:28
  • "alias is not generated as a target" - ALIAS is a **target**. E.g. the command `get_target_property` is applicable to it. It is property [BUILDSYSTEM_TARGETS](https://cmake.org/cmake/help/latest/prop_dir/BUILDSYSTEM_TARGETS.html) which doesn't list ALIAS targets. Unfortunately, I cannot find in documentation the property, which list ALIAS targets. – Tsyvarev Jul 28 '22 at 07:44
  • "_I wanna make sure everyone use alias all over the project._" this still doesn't explain why (to me). What benefit does it provide? Does it in your context somehow have implications for maintainability? robustness? readability? etc. – starball Oct 27 '22 at 05:42

0 Answers0