View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0014970CMakeCMakepublic2014-06-12 12:422016-06-10 14:31
ReporterBen Boeckel 
Assigned ToKitware Robot 
PrioritynormalSeverityminorReproducibilityhave not tried
StatusclosedResolutionmoved 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0014970: [RFE] Add support for "linking" object libraries
DescriptionShould act like an INTERFACE library with INTERFACE_SOURCES set.
TagsNo tags attached.
Attached Files

 Relationships

  Notes
(0036169)
Ben Boeckel (developer)
2014-06-12 12:46

Should also only be allowed under LINK_PRIVATE (since OBJECT libraries are not allowed to be exported).
(0036172)
Brad King (manager)
2014-06-12 14:17

With a minor fix to the implementation in CMake, this can be made to work:

 add_library(objlib OBJECT obj.cpp)
 add_library(iface_objlib INTERFACE)
 target_sources(iface_objlib INTERFACE $<TARGET_OBJECTS:objlib>)

 add_executable(myexe myexe.cpp)
 target_link_libraries(myexe iface_objlib)

Then other usage requirements could be added to the INTERFACE library. Of course it will be up to the author not to install this interface library and expect it to work.
(0036173)
Robert Maynard (manager)
2014-06-12 14:28

@Brad,

 add_library(objlib OBJECT obj.cpp)
 add_library(iface_objlib INTERFACE)
 target_sources(iface_objlib INTERFACE $<TARGET_OBJECTS:objlib>)

 add_library(mylib mylib.cpp)
 target_link_libraries(mylib PUBLIC iface_objlib)

In the above example would the TARGET_OBJECTS become embedded in any other target that links to mylib?
(0036174)
Brad King (manager)
2014-06-12 15:21

Re 0014970:0036173: Yes, though I would call that a bug in the project code for not doing

 target_link_libraries(mylib PRIVATE iface_objlib)

What Ben proposes in this issue is to allow

 target_link_libraries(mylib PRIVATE objlib)

without an explicit intermediate interface target. In this case we would be able to diagnose a non-PRIVATE reference to an object library and report an error.
(0036176)
Robert Maynard (manager)
2014-06-12 15:34

So I don't think the private only linking is sufficient for object targets, mainly because that is unable to properly express the requirements of for using the object target. Why can't I have public INTERFACE include dirs or compilation flags on iface_objlib and have those propagate with mylib?

I would think something like this is clearer:

add_library(objlib OBJECT obj.cpp)
target_include_directories(objlib INTERFACE ${foo} )

add_library(mylib mylib.cpp $<TARGET_OBJECTS:objlib>)
target_link_libraries(mylib PUBLIC objlib)
(0036178)
Brad King (manager)
2014-06-12 15:56

Re 0014970:0036176: I'd prefer not to have to reference the object library twice from mylib to get things working. We should either include the object files and their requirements, or neither.

Object libraries cannot be installed so they can never be involved in public interfaces (unless we make such involvement also prevent the installation of the consuming targets that do not switch to PRIVATE).

One of the purposes of object libraries is to allow multiple groups of object files to each be built with their own requirements and then combined into a single library. Referencing $<TARGET_OBJECTS:objlib> is currently our way to bring the objects into the sources of that single library. What we're discussing here is that bringing object libraries into a single library like this should also integrate its usage requirements as if all the sources had been compiled as part of the single target. Perhaps that means that

 target_link_libraries(mylib PUBLIC objlib)

should cause objlib's object files to be included when archiving/linking mylib and also all the INTERFACE_ property values on objlib to be *appended* (and de-duped) to those of mylib for purposes of the current build system and when exported as part of installing mylib.
(0036367)
Brad King (manager)
2014-07-14 09:39

Re 0014970:0036172: Independent of the rest of the discussion here, I think using $<TARGET_OBJECTS:objlib> in INTERFACE_SOURCES should be expected to work:

 Allow INTERFACE_SOURCES to specify $<TARGET_OBJECTS>
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=affe9d56 [^]
(0042565)
Kitware Robot (administrator)
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.

 Issue History
Date Modified Username Field Change
2014-06-12 12:42 Ben Boeckel New Issue
2014-06-12 12:46 Ben Boeckel Note Added: 0036169
2014-06-12 14:17 Brad King Note Added: 0036172
2014-06-12 14:28 Robert Maynard Note Added: 0036173
2014-06-12 15:21 Brad King Note Added: 0036174
2014-06-12 15:34 Robert Maynard Note Added: 0036176
2014-06-12 15:56 Brad King Note Added: 0036178
2014-07-14 09:39 Brad King Note Added: 0036367
2016-06-10 14:29 Kitware Robot Note Added: 0042565
2016-06-10 14:29 Kitware Robot Status new => resolved
2016-06-10 14:29 Kitware Robot Resolution open => moved
2016-06-10 14:29 Kitware Robot Assigned To => Kitware Robot
2016-06-10 14:31 Kitware Robot Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team