<div dir="ltr"><div><div><div><div><div><div>Hi David.<br><br></div>In your particular case, you don't have build everything twice. Just make the SHARED libraries thin wrappers around the OBJECT libraries. Like this:<br><br></div>add_library(obj1 OBJECT a.cpp b.cpp ...)<br></div>add_library(lib1 SHARED $<TARGET_OBJECTS:obj1>)<br><br>add_library(obj2 OBJECT c.cpp d.cpp ...)<br></div>add_library(lib2 SHARED $<TARGET_OBJECTS:obj2>)<br><br></div>add_library(combined SHARED $<TARGET_OBJECTS:obj1> $<TARGET_OBJECTS:obj2>)<br><br></div>Petr<br><div class="gmail_extra"><br><div class="gmail_quote">On 10 July 2017 at 19:41, David Hunter <span dir="ltr"><<a href="mailto:davidhunter22@gmail.com" target="_blank">davidhunter22@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Currently you can create an OBJECT library using "add_library(<name><br>
OBJECT <src>...)" this populates $<TARGET_OBJECTS:name>  which can then<br>
later be used using something like<br>
"target_sources(name PUBLIC $<TARGET_OBJECTS:name>)". I am wondering if<br>
there  is some reason that $<TARGET_OBJECTS:name> can't be populated when<br>
you create a shared or static library, for instance using<br>
"add_library(<name> SHARED <src>...)". Looking at the output the VS 2017<br>
generators for "add_library(<name> OBJECT <src>...)" it seems to actually<br>
build a static library anyway. I suspect that all the <src> files are<br>
compiled to object files somewhere for both STATIC and SHARED libraries,<br>
if so would it not be possible to point $<TARGET_OBJECTS:name> as these<br>
object files?<br>
<br>
The reason I ask is that we have a a bunch of source code that builds<br>
in about 100 projects. These projects have a normal hierarchical<br>
dependency tree. However when distributing we want to create larger<br>
libraries that are the combination of various subsets of the smaller ones.<br>
In automake these are called convenience libraries and I suspect they may<br>
have been the reason for CMake OBJECT in the first place. Given the current<br>
behaviour we have to build all the projects twice once in SHARED library<br>
form on once in OBJECT library form. If TARGET_OBJECTS was populated for<br>
SHARED libraries we would not need to build everything twice as we could<br>
build everything SHARED but still use TARGET_OBJECTS to build combination<br>
convenience libraries.<br>
<br>
Of course maybe there's already a way to do this without having to<br>
build twice which I don't know about.<br></blockquote></div><br></div></div>