TARGET_NAME¶
This generator expression belongs to the Target Meta-Data family. See that section for related generator expressions.
Syntax¶
$<TARGET_NAME:tgt>
The target name tgt as written. This marks tgt as being the name of a
target wherever it appears inside a larger expression. When the property
holding that expression is exported with a namespace by
install(EXPORT) or export(), a marked target name is
rewritten to its namespaced imported target name (e.g. mylib::mylib), the
same way a bare target name in a link-library list would be. Marking is needed
when a target name is nested inside another generator expression that the export
machinery does not otherwise descend into, such as LINK_LIBRARY or
LINK_GROUP, and also when exporting targets to multiple dependent
export sets.
For example, a target name used inside LINK_LIBRARY is exported
verbatim unless it is marked:
# Exported as bare "mylib"; a consumer would see an unresolved -lmylib.
target_link_libraries(myotherlib PUBLIC
$<LINK_LIBRARY:WHOLE_ARCHIVE,mylib>)
# Marked, so export rewrites it to the namespaced "mylib::mylib".
target_link_libraries(myotherlib PUBLIC
$<LINK_LIBRARY:WHOLE_ARCHIVE,$<TARGET_NAME:mylib>>)
The tgt text must be a literal name of a target; it may not contain
generator expressions. During ordinary evaluation the target does not have to
exist, but when the expression is exported the marked name must resolve to a
target reachable from the export.