<div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote"><div>Hi David,<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Supporting OBJECT libraries in<br>
target_link_libraries calls was mentioned mentioned right back here<br>
<a href="https://cmake.org/pipermail/cmake-developers/2012-March/015422.html" rel="noreferrer" target="_blank">https://cmake.org/pipermail/<wbr>cmake-developers/2012-March/<wbr>015422.html</a> but<br>
sadly seems still to be on the back burner.<br></blockquote><div><br></div><div>It's not on the back burner!  There has been progress on desiging the rest of the implementation to make OBJECT libraries "first class citizens" and I  can't give you actual dates I do believe you can probably expect it some time this year.<br><br> <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> Not being<br>
able to use target_link_libraries with thier transitive nature made this<br>
very painful, many days of work. </blockquote><br></div><div>I actually just recently went through the exercise of creating a workaround for this in one of my projects so I can certainly understand the gaping hole that is currently present.  The workaround I ended up with was to create three seperate libraries: one for the objects, one for the usage requirements, and then a third that combines them.<br><br></div></div><div style="margin-left:40px"><span style="font-family:monospace,monospace">add_library(foo_objects OBJECT foo_src1.cxx foo_src2.cxx ...)<br></span></div></div><div class="gmail_extra" style="margin-left:40px"><span style="font-family:monospace,monospace"><br>add_library(foo_interface INTERFACE)<br></span></div><div class="gmail_extra" style="margin-left:40px"><span style="font-family:monospace,monospace">target_link_libraries(foo_interface INTERFACE FooDepend1 FooDepend2 ...)<br></span></div><div class="gmail_extra" style="margin-left:40px"><span style="font-family:monospace,monospace">target_include_directories(foo_interface INTERFACE<br>  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR})><br></span></div><div class="gmail_extra" style="margin-left:40px"><span style="font-family:monospace,monospace">  $<INSTALL_INTERFACE:include>)<br></span></div><div class="gmail_extra" style="margin-left:40px"><span style="font-family:monospace,monospace"><br>add_library(foo INTERFACE)<br></span></div><div style="margin-left:40px"><span style="font-family:monospace,monospace">target_sources(foo INTERFACE $<TARGET_OBJECTS:foo_objects>)<br>target_link_libraries(foo INTERFACE foo_interface)</span><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">The interface sources property on "foo" will populate the object files into whatever uses "foo" in its target_link_libraries and then the usage requirements in foo_interface will populate transitively.  The only problem with this approach, and the reason for creating three separate libraries instead of just adding the objects to the sources on foo_interface, is that INTERFACE_SOURCES will continue to get propagated transitively potentially causing duplicate symbols upstream, so it's really only appropriate for private linking so you want to link publically then add the objects manually and pass the interface publically.  This essentially means you need to use it like this:<br><div style="margin-left:40px"><br></div><div style="margin-left:40px"><span style="font-family:monospace,monospace">// Use foo privately, so just put "foo" in TLL and it just works</span> <br></div></div><div class="gmail_extra" style="margin-left:40px"><span style="font-family:monospace,monospace">add_library(bar1 bar1_src1.cxx bar1_src2.cxx)<br></span></div><div class="gmail_extra"><div style="margin-left:40px"><span style="font-family:monospace,monospace">target_link_libraries(bar1 PRIVATE foo)<br><br></span></div><div style="margin-left:40px"><span style="font-family:monospace,monospace">// Use foo publicly so we need to separately grab the objects and<br>// their usage requirements.<br></span></div><div class="gmail_extra" style="margin-left:40px"><span style="font-family:monospace,monospace">add_library(bar2<br>  bar2_src1.cxx bar2_src2.cxx<br></span></div><div class="gmail_extra" style="margin-left:40px"><span style="font-family:monospace,monospace">  $<TARGET_OBJECTS:foo_objects>)<br></span></div><div style="margin-left:40px"><span style="font-family:monospace,monospace">target_link_libraries(bar2 PUBLIC foo_interface)</span><br></div><br></div><div class="gmail_extra">This is effectively what the current plan is for the upstream implementation, just all rolled into one; i.e. the objects get added to whatever is explicitly linking with target_link_libraries, but all transitive linkage only uses the interface usage requirements.  Plans, of course, may change but that's what it's looking like right now, we just need to find the time and funding to implement it.<br><br></div><div class="gmail_extra">- Chuck<br></div><div class="gmail_extra"><br></div></div>