[cmake-developers] Object library linking (and a bit about INTERFACE_SOURCES)

Stephen Kelly steveire at gmail.com
Wed Feb 25 16:57:13 EST 2015


Brad King wrote:

> On 02/24/2015 05:25 PM, Stephen Kelly wrote:
>>> Until that problem is solved we cannot make object libraries
>>> implicitly offer their objects just through tll().
>> 
>> Honestly, the problem is still not clear to me.
> 
> Consider an object library with some usage requirements:
> 
>  add_library(objlib OBJECT ...)
>  target_compile_definitions(objlib PUBLIC MYDEF)
> 
> Now try using that library and assume that tll() takes the objects
> without explicit $<TARGET_OBJECTS:objlib> in the sources:
> 
>  add_library(mylib SHARED ...)
>  target_link_libraries(mylib PUBLIC objlib)
> 
> We link publicly to forward the usage requirements of objlib through
> mylib.  Now consumers of mylib will get objlib's objects too.  That
> is not desired.  It is the same problem as transitive interface
> sources.

Ok, I see. Now I also understand Bens commit message referenced at the 
beginning of the thread:

    The real fix is to make INTERFACE_SOURCES only applicable when
    directly linked and not transitive, but that is a bigger change.


> What I envision for the future is:
> 
>  add_library(objlib OBJECT ...)
>  target_compile_definitions(objlib PUBLIC MYDEF)
>  target_sources(objlib INTERFACE $<TARGET_OBJECTS:objlib>)

Do you envision that as the idiomatic way to declare object libraries? Would 
CMakeLists authors have to write the target_sources line explicitly, if this 
future becomes possible?

Thanks,

Steve.





More information about the cmake-developers mailing list