[CMake] Transitive linking and static libraries

Andreas Pakulat apaku at gmx.de
Thu Oct 17 14:51:03 EDT 2013


Hi James,

On Thu, Oct 17, 2013 at 6:58 PM, James Bigler <jamesbigler at gmail.com> wrote:

> It doesn't seem to work.
>
> I can't use target_link_libraries on an imported target.
>
> add_library(imported_lib STATIC IMPORTED GLOBAL)
> set_target_properties(imported_lib PROPERTIES IMPOARTED_LOCATION
> "${imported_lib_location}")
>

Is this typo in the property name only in the mail or also in your cmake
code? It should be IMPORTED_LOCATION of course.


> target_link_libraries(imported_lib other_lib)
>
> Produces an error:
>
> Attempt to add link library [imported_lib_location] to target imported_lib
> which is not built in this directory.
>

Now, without having read all the history, this makes no sense to me. How
should cmake link another library into your imported library? This would
require re-linking that library, but cmake has no idea whats needed for
that since it didn't build that imported library. If you're dealing with
static libraries on ELF based systems this might be doable, because you can
simply unback the .a archive and re-pack it including new object files or
even simply add files to it. However other systems may use different types
of static libraries that are not just a simple archive of object files, so
this is really specific to a subset of the supported platforms. If you
absolutely need that, then I'd write a post-link cmake script for
'other_lib' (assuming that one is built by cmake) that does the necessary
steps.

Andreas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20131017/4388da0f/attachment.htm>


More information about the CMake mailing list