Details
-
Task
-
Resolution: Done
-
P3: Somewhat important
-
None
-
None
-
None
Description
So far Qt has been using the target_link_libraries overload that doesn't specify any linkage, e.g.
target_link_libraries(mytarget Qt6::Core)
Anyhow, the Professional CMake book suggests always using explicit linkage with
target_link_libraries. In particular, it reinforces the habit and forces you to think about the relationships between targets. The type of linkage you get if you don't specify it actually depends on a policy setting.
The actual type of linkage (PUBLIC, PRIVATE, INTERFACE) to be used depends very much on the use case. Whether to use PUBLIC or PRIVATE for Qt libraries depends on whether something that consumes mytarget needs to link to Qt6::Test as well. In practice, this usually means use PUBLIC if anything from Qt6::Test is mentioned in a header of mytarget, use PRIVATE otherwise.
You should always prefer PRIVATE where you can to minimise the internal dependencies you expose out to consumers.