[CMake] Including object/archive/library in a static lib

Philip Lowman philip at yhbt.com
Tue Sep 9 22:43:18 EDT 2008


On Tue, Sep 9, 2008 at 12:42 PM, Armand Filippi (Temp) <
Armand.Filippi at autodesk.com> wrote:

>  Hi all,
>
>
>
> I am trying to _*include*_ an externally built library B in a static lib A
> that I'm building with Cmake.
>
>
>
> For MSVC, I would like it to end up in the Librarian>Additional
> Dependencies (and have its path in the Additional Library Directories).
> Also, this would add some /LIBPATH: and the library names at the end of the
> linker command.
>
>
>
> For Linux ld, the equivalent result would be to have the B library appended
> to the linker command, with the –whole-archive parameter.
>
>
>
> Apparently, using the Cmake command: target_link_libraries(<my lib A> <my
> lib B>) with Cmake 2.6.0 patch0 does not produce this result (nothing in the
> additional dependencies field in MSVC)
>
>
>
> Is that supported by Cmake ?
>
I don't think they've added built-in support to do what you want to do in
CMake because it's not portable everywhere.

With GNU ld on Linux you can simply pass any flags you might need to
TARGET_LINK_LIBRARIES to grab the libraries you need:
http://www.mail-archive.com/cmake@cmake.org/msg01890.html


I couldn't figure out a way to do what you want to do with CMake's MSVC
generator.  It looks like this may be a coding oversight in CMake.  A
suggested fix would be for CMake to allow SET_TARGET_PROPERTIES(...
LINK_FLAGS) to work on Visual Studio static libraries.  Right now this
doesn't appear to work, at least with specifying additional ".lib" files to
link against.

Here's a test example for this if someone wants to have a look.  I wasn't
sure that MSVC even supported this use case until I modified the Visual
Studio project manually and verified that it does work.

-- 
Philip Lowman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20080909/251fca8e/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: static_in_static_msvc.zip
Type: application/zip
Size: 1233 bytes
Desc: not available
URL: <http://www.cmake.org/pipermail/cmake/attachments/20080909/251fca8e/attachment.zip>


More information about the CMake mailing list