[CMake] When is the TARGET_NAME generator expression necessary?
Razvan Maris
razvan.maris10 at yahoo.com
Mon Jul 9 14:21:14 EDT 2018
Hello,
I was reading the CMake documentation regarding generator expressions, and I found the following:
"$<TARGET_NAME:...>
Marks ... as being the name of a target. This is required if exporting targets to multiple dependent export sets. The ... must be a literal name of a target- it may not contain generator expressions."
>From that I understand that if some targets from an export set depend on other targets from other export set, the dependencies should be specified using $<TARGET_NAME:...> instead of the targets' names.
I found the thread (this message specifically: https://www.mail-archive.com/cmake-developers@cmake.org/msg05498.html) that is responsible for the introduction of the TARGET_NAME generator expression, however I cannot find an example for its use.
I believe it has something to do with adding the correct namespace to the "required library".
I tried an example of dependent export sets in which I do not use $<TARGET_NAME:...>, I even use the target's name inside another generator expression, but no error is generated and the output files contain the correct "imported" targets (with the correct namespaces):
"project(target_name)
add_library(a a.cpp)
add_library(b b.cpp)
target_link_libraries(b $<$<EQUAL:1,1>:a>)
export(TARGETS
a
NAMESPACE foo_
FILE a_config.cmake
)
export(TARGETS
b
NAMESPACE bar_
FILE b_config.cmake
)"
When are we required to use the TARGET_NAME generator expression?
Thank you,
Razvan
More information about the CMake
mailing list