MantisBT - CMake
View Issue Details
0014778CMakeCMakepublic2014-02-28 02:402016-06-10 14:31
A. Klitzing 
Ben Boeckel 
normalfeaturealways
closedmoved 
CMake 2.8.12.2 
 
0014778: Allow linking OBJECT libraries for usage requirements.
I'm using cmake 2.8.12 and qt 5.2.1 and I have some artifacts that should be build as an OBJECT LIBRARY. But cmake and the new IMPORTED TARGETs way does not allow me to do it.

There should be a way to add all needed compile stuff to OBJECT LIBRARIES like the new IMPORTED TARGET feature. Intuitional I would use an IMPORTED target in target_include_directories.
FILE(GLOB_RECURSE FILES "*.cpp")
ADD_LIBRARY(Example OBJECT ${FILES})
TARGET_LINK_LIBRARIES(Example Qt5::Core)

Error: Object library target "Example" may not link to anything.



Of course I don't need to link libraries to that OBJECT LIBRARY. But I need INCLUDES, DEFINITIONS and so on for the compilation because the artifacts uses qt.
https://bugreports.qt-project.org/browse/QTBUG-37105 [^]
No tags attached.
related to 0014751closed Brad King Generalize LINK_ONLY 
Issue History
2014-02-28 02:40A. KlitzingNew Issue
2014-03-05 16:16Stephen KellyNote Added: 0035319
2014-03-05 16:16Stephen KellySummaryAllow IMPORTED target in target_include_directories => Allow linking OBJECT libraries for usage requirements.
2014-03-06 10:39Brad KingRelationship addedrelated to 0014751
2014-03-06 10:42Brad KingNote Added: 0035325
2015-02-20 15:59Ben BoeckelAssigned To => Ben Boeckel
2015-02-20 15:59Ben BoeckelStatusnew => assigned
2015-02-20 15:59Ben BoeckelNote Added: 0038011
2015-02-20 15:59Ben BoeckelTarget Version => CMake 3.3
2015-02-20 17:34Ben BoeckelNote Added: 0038012
2015-02-21 04:13Stephen KellyNote Added: 0038014
2015-04-22 09:55Brad KingTarget VersionCMake 3.3 =>
2015-07-31 05:24Vladimír VondrušNote Added: 0039208
2016-01-05 09:30Damien BuhlNote Added: 0040142
2016-06-10 14:29Kitware RobotNote Added: 0042495
2016-06-10 14:29Kitware RobotStatusassigned => resolved
2016-06-10 14:29Kitware RobotResolutionopen => moved
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0035319)
Stephen Kelly   
2014-03-05 16:16   
Allowing IMPORTED targets as the lhs of target_include_directories was considered, implemented and reverted before, but I don't recall why.

I think the only option that works for you in the future will be linking OBJECT libraries to things.
(0035325)
Brad King   
2014-03-06 10:42   
This is somewhat the opposite of 0014751. Here we want to get all usage requirements except linking. More specifically, the implementation of the OBJECT library needs compilation usage requirements but consumers of the object library need linking usage requirements.
(0038011)
Ben Boeckel   
2015-02-20 15:59   
I'm nominating this for 3.3. I need this sooner rather than later. I'll try to take a whack at it.
(0038012)
Ben Boeckel   
2015-02-20 17:34   
@Steven: so I have LHS implemented; working on RHS now. I see no test errors for it (after updating the LHS test to check for the right thing). Are the original commits around somewhere?
(0038014)
Stephen Kelly   
2015-02-21 04:13   
Ben, see

 http://www.cmake.org/gitweb?p=cmake.git;a=commitdiff;h=9cfe4f1b76 [^]
 Allow target_link_libraries with IMPORTED targets.

 http://www.cmake.org/gitweb?p=cmake.git;a=commitdiff;h=48a4cf21 [^]
 Revert "Allow target_link_libraries with IMPORTED targets."

 http://www.cmake.org/gitweb?p=cmake.git;a=commitdiff;h=b98d14d4 [^]
 Disallow porcelain to populate includes and defines of IMPORTED targets.

However, I don't think those are actually relevant to this feature request. It was a response to the IMPORTED libraries mention in the summary. If you're implementing things as Brad wrote in 0014778:0035325, I don't think they're relevant.
(0039208)
Vladimír Vondruš   
2015-07-31 05:24   
Hello, any progress on this? I wanted to switch to IMPORTED targets from the old ${variable} way, but I have a lot of OBJECT libs for which I need to specify include directories etc. and target_link_libraries() seems to me like the most intuitive way to do it.

The current workaround is unnecessarily verbose.

 target_include_directories(Example PRIVATE $<TARGET_PROPERTY:Qt5::Core,INTERFACE_INCLUDE_DIRECTORIES>)
 target_compile_definitions(Example PRIVATE $<TARGET_PROPERTY:Qt5::Core,INTERFACE_COMPILE_DEFINITIONS>)
(0040142)
Damien Buhl   
2016-01-05 09:30   
Thanks for the workaround, yes it's sad that we cannot do this.

I also needed to take the INTERFACE_COMPILE_OPTIONS which are sometimes used (like C++11 flags).
target_compile_options(SAUTER_CONTROL_CORE_OBJECT_FILES_WITHOUT_MAIN PRIVATE $<TARGET_PROPERTY:lib-cpp-slc::cpp-slc,INTERFACE_COMPILE_OPTIONS>)
(0042495)
Kitware Robot   
2016-06-10 14:29   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.