[CMake] Confusion over INTERFACE vs STATIC|SHARED IMPORTED vs INTERFACE IMPORTED

Nicholas Braden nicholas11braden at gmail.com
Tue Jul 5 19:09:38 EDT 2016


>From what I understand, interface libraries just don't have sources or
build results. INTERFACE IMPORTED would then mean there is no compiled
binary to be linked against, just as INTERFACE alone means there are
no sources to create said binary from. At least, that is my
understanding.

> My understanding of this is that setting INTERFACE_LINK_LIBRARIES on a target like this would be an error?

Why can't a header-only library link to non-header-only libraries?

On Tue, Jul 5, 2016 at 5:17 PM, Ted Middleton <middleton.ted at gmail.com> wrote:
> I'm looking at the documentation for add_library(), and I'm really confused
> about the distinction between add_library(foo INTERFACE) vs add_library(foo
> INTERFACE IMPORTED) vs add_library(foo <SHARED|STATIC> IMPORTED).
>
> Correct me if I'm wrong (and I probably am), but add_library(foo INTERFACE)
> is for propagating properties like INTERFACE_INCLUDE_DIRECTORIES to other
> targets using target_link_libraries(), so that header-only libraries can be
> consumed by other targets conveniently. My understanding of this is that
> setting INTERFACE_LINK_LIBRARIES on a target like this would be an error?
>
> And add_library(foo SHARED IMPORTED) would be to create a target object for
> a pre-existing library (like a platform lib or something) for which cmake is
> not supposed to try to create an actual "call the compiler and linkeditor or
> archiver" build rule. This still boils down to mostly propagating
> properties, no? Except now some of those properties can be things like
> INTERFACE_LINK_LIBRARIES?
>
> So can anyone tell me what add_library(foo INTERFACE IMPORTED) is? The
> documentation says,
>
> "An INTERFACE Imported Target may also be created with this signature. An
> IMPORTED library target references a library defined outside the project.
> The target name has scope in the directory in which it is created and below,
> but the GLOBAL option extends visibility. It may be referenced like any
> target built within the project. IMPORTED libraries are useful for
> convenient reference from commands like target_link_libraries()."
>
> That description is what I thought add_library(foo <SHARED|STATIC> IMPORTED)
> was for?
>
>
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake


More information about the CMake mailing list