[CMake] Including object/archive/library in a static lib
Armand Filippi (Temp)
Armand.Filippi at autodesk.com
Wed Sep 10 11:31:51 EDT 2008
Hi again and thanks for your answer.
I'll have a look at your included example but it seems more for debugging Cmake and finding why it doesn't work, and I don't think I have time for that unfortunately.
Otherwise, I'll probably try to make a custom command that uses the MSVC lib.exe (or ld or ar on gnu/linux) to assemble the lib in a final step, if possible. Otherwise I'll have to script it externally, but that defeats the purpose..
Also, I was talking about using ld and the -whole-archive flag, but it's maybe more of a job for the archiver than the linker.. I've looked in the cmake doc but I only found CMAKE_<LANG>_ARCHIVE_APPEND that I don't know how to use yet.
Thanks again
Armand
From: philiplowman at gmail.com [mailto:philiplowman at gmail.com] On Behalf Of Philip Lowman
Sent: September 9, 2008 10:43 PM
To: Armand Filippi (Temp)
Cc: cmake at cmake.org
Subject: Re: [CMake] Including object/archive/library in a static lib
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
More information about the CMake
mailing list