MantisBT - CMake
View Issue Details
0013876CMakeCMakepublic2013-01-24 14:502013-06-03 09:05
Chris Harris 
Brad King 
normalminoralways
closedfixed 
x86_64Ubuntu12.10
CMake 2.8.10.2 
CMake 2.8.11CMake 2.8.11 
0013876: target_link_libraries does not clearly document that LINK_* signatures privatize old signatures
Given the following CMake code:

target_link_libraries(AvogadroIO AvogadroCore)

target_link_libraries(AvogadroIO LINK_PRIVATE hdf5)

The LINK_PRIVATE is also applied to AvogadroCore. The workaround is to add LINK_PUBLIC:

target_link_libraries(AvogadroIO LINK_PUBLIC AvogadroCore)

target_link_libraries(AvogadroIO LINK_PRIVATE hdf5)
The following dashboard entry demonstrates this failure:

http://cdash.openchemistry.org/viewBuildError.php?buildid=5638 [^]
No tags attached.
Issue History
2013-01-24 14:50Chris HarrisNew Issue
2013-01-24 15:26Brad KingNote Added: 0032154
2013-01-24 15:27Brad KingNote Added: 0032155
2013-01-24 15:30Marcus D. HanwellNote Added: 0032156
2013-01-24 15:48Brad KingNote Added: 0032160
2013-01-24 15:48Brad KingNote Edited: 0032160bug_revision_view_page.php?bugnote_id=32160#r1015
2013-01-24 16:22Marcus D. HanwellNote Added: 0032161
2013-01-24 16:48Brad KingNote Added: 0032162
2013-01-24 16:48Brad KingAssigned To => Brad King
2013-01-24 16:48Brad KingStatusnew => resolved
2013-01-24 16:48Brad KingResolutionopen => fixed
2013-01-24 16:48Brad KingFixed in Version => CMake 2.8.11
2013-01-24 16:48Brad KingTarget Version => CMake 2.8.11
2013-01-24 16:48Brad KingSummaryUse of LINK_PRIVATE in target_link_libraries(...) cause all libaries to be linked private => target_link_libraries does not clearly document that LINK_* signatures privatize old signatures
2013-06-03 09:05Robert MaynardNote Added: 0033192
2013-06-03 09:05Robert MaynardStatusresolved => closed

Notes
(0032154)
Brad King   
2013-01-24 15:26   
This is expected. Any use of LINK_PRIVATE or LINK_PUBLIC means that LINK_INTERFACE_LIBRARIES will be populated. Once this happens then any libraries not in the link interface will not be public anymore. It is only for historical reasons that having no explicit link interface means that everything is public by default.
(0032155)
Brad King   
2013-01-24 15:27   
The LINK_* options are meant to allow everything in one command:

 target_link_libraries(AvogadroIO LINK_PUBLIC AvogadroCore LINK_PRIVATE hdf5)
(0032156)
Marcus D. Hanwell   
2013-01-24 15:30   
It would be helpful to make this clearer in the documentation (it wasn't clear to me when we read it). I didn't expect a second call to make previous libraries private, and assumed any calls made without such arguments would have maintained the previous behavior, i.e. being equivalent to calling with LINK_PUBLIC.
(0032160)
Brad King   
2013-01-24 15:48   
Multiple signatures set the link interface so it makes more sense IMO to document in the old signature that the others may make its libraries private. How about this patch?

diff --git a/Source/cmTargetLinkLibrariesCommand.h b/Source/cmTargetLinkLibrariesCommand.h
index 34fe54c..3da3950 100644
--- a/Source/cmTargetLinkLibrariesCommand.h
+++ b/Source/cmTargetLinkLibrariesCommand.h
@@ -93,7 +93,9 @@ public:
       "linked to this target will appear on the link line for the other "
       "target too.  "
       "See the LINK_INTERFACE_LIBRARIES target property to override the "
-      "set of transitive link dependencies for a target."
+      "set of transitive link dependencies for a target.  "
+      "Calls to other signatures of this command may set the property "
+      "making any libraries linked exclusively by this signature private."
       "\n"
       "  target_link_libraries(<target> LINK_INTERFACE_LIBRARIES\n"
       "                        [[debug|optimized|general] <lib>] ...)\n"


(0032161)
Marcus D. Hanwell   
2013-01-24 16:22   
I think that is better, I still feel like this is a very surprising result (a subsequent call, possibly in a function/macro, changes the behavior of existing unchanged calls). I will remember to be careful with it, I am surprised that the standard call with no arguments is not equivalent to calling with LINK_PUBLIC (which was the previous default to the best of my understanding). I guess you are saying it is equivalent to silently inserting LINK_PRIVATE once any of the new forms of target_link_libraries are called.
(0032162)
Brad King   
2013-01-24 16:48   
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=f032fb90 [^]
(0033192)
Robert Maynard   
2013-06-03 09:05   
Closing resolved issues that have not been updated in more than 4 months.