[cmake-developers] INTERFACE_LIBRARY target type

Stephen Kelly steveire at gmail.com
Fri May 3 06:59:52 EDT 2013


Brad King wrote:

> On 05/02/2013 11:26 AM, Stephen Kelly wrote:
>> Perhaps we could do aliasing with a target property instead?
>> 
>>  add_library(foo SHARED foo.cpp)
>>  set_property(TARGET foo APPEND PROPERTY ALIAS_NAME KF5::foo)
> 
> No, I like to be able to say that all logical target names are
> created by an add_* call.  Actually your point about scopes of
> target names means that ALIAS targets should be scoped like
> IMPORTED targets since their purpose is to "self-import".  That
> is an argument for ALIAS targets to be built on IMPORTED targets.

I wouldn't say the primary purpose is to self-import, and therefore they 
should behave as IMPORTED targets. Their primary purpose is to be an alias 
for another target.

>> This might need some deeper consideration. I like that IMPORTED targets
>> can not be re-exported, and I would expect the same for the
>> INTERFACE_LIBRARY type.
> 
> How should a project define an interface library and get CMake
> to put it in a targets file through install(EXPORT) or export()?

I don't think I understand the question. 

It should be the same as for any other target.

 add_library(iface INTERFACE)
 export(TARGETS iface)

results in 

 add_library(iface INTERFACE IMPORTED)
 # ...

I think that's the conclusion you reach below too.

> Shouldn't header-only libraries be able to work like that?

Yes.

>> IMPORTED targets also have a different scope to non-imported targets. I'd
>> expect that if I find_package somewhere and a KF5::iface
>> INTERFACE_LIBRARY results, that follows the same scope rules as
>> KF5::KArchive.
> 
> Perhaps IMPORTED and INTERFACE are orthogonal.

Yes, that's the way I've been thinking of them.

> One could import
> an interface library defined by another project.  I'll retract my
> previous assertion that IMPORTED targets should always refer to
> files. 

Yes.

Thanks,

Steve.





More information about the cmake-developers mailing list