Feature Request: Enhanced target_link_libraries validation
target_link_libraries
supports an array of different types of 'items' which makes it easy to construct the input to the linker. However, this means it is impossible to validate what is linked to a target until the linker actually uses this input.
So far I've only been able to do this using add_dependencies
, but that introduces redundancies in the code and unnecessary duplications.
I'd like to propose a variant of this command that only accepts valid targets, similarly to add_dependencies
, for the purposes of linking. Possibly, target_link_target
although better ideas are welcome.
For example:
add_library(a)
add_library(b)
target_link_target(a PUBLIC b)
target_link_target(a PUBLIC c) # fails with 'The dependency target "c" of target "a" does not exist'
This will ensure at configuration time that all the target dependencies are accounted for. Additionally, it will provide some visual separation between target relationships and plaintext linker options that are currently combined with target_link_libraries
.