[cmake-developers] INTERFACE IMPORTED example
Craig Scott
craig.scott at crascit.com
Thu Mar 22 16:26:35 EDT 2018
On Thu, Mar 22, 2018 at 10:37 PM, Brad King <brad.king at kitware.com> wrote:
> On 03/21/2018 06:01 PM, Craig Scott wrote:
> > I swear I asked this a while back and there was an example given
>
> Maybe here:
>
> * https://gitlab.kitware.com/cmake/cmake/merge_requests/1581
Yes, that was it, thanks.
> > Does anyone know of a specific example scenario where an
> > INTERFACE IMPORTED library is the right choice over simply
> > INTERFACE or IMPORTED on its own?
>
> A non-INTERFACE imported target needs an IMPORTED_LOCATION,
> so an IMPORTED target wouldn't replace an INTERFACE IMPORTED
> target.
>
> A plain INTERFACE library and an IMPORTED INTERFACE library are
> nearly identical indeed, but the scope of the name differs.
>
> IMPORTED INTERFACE libraries mostly exist for install(EXPORT)
> to produce from an installed/exported INTERFACE library.
> They can't export as a normal INTERFACE library because
> imported targets have visibility isolated to the directory
> that imports them.
>
Okay. So the use case is inside a package's installed config file? i.e. if
a project wants to define an INTERFACE library to be provided as part of
its package, it should be defining an INTERFACE IMPORTED library? And
that's only needed because by convention, when someone does a
find_package(), any targets created by that are usually expected to be
imported targets with non-global scope, so an ordinary INTERFACE library is
not quite right because it has global scope (which CMake would allow, but
INTERFACE IMPORTED would be better). Following that through, the
combination INTERFACE IMPORTED GLOBAL is probably of little use now, since
either:
- It doesn't need an IMPORTED_LOCATION, in which case a plain INTERFACE
library is appropriate and arguably clearer/simpler.
- It does need an imported location but since IMPORTED GLOBAL now
supports setting interface properties, it could do the job and is also
arguably clearer/simpler.
Only for pre-CMake 3.11 would INTERFACE IMPORTED GLOBAL be useful, since
IMPORTED GLOBAL didn't support setting interface properties before then.
And it would only be useful for the case where IMPORTED_LOCATION was being
set to point at a real library (otherwise just use INTERFACE on its own).
If there are any holes or errors in that, please let me know. Thanks.
--
Craig Scott
Melbourne, Australia
https://crascit.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake-developers/attachments/20180323/61ae9771/attachment.html>
More information about the cmake-developers
mailing list