[CMake] How to merge dependencies of a static lib with itself?

Matthew Woehlke mw_triad at users.sourceforge.net
Fri Feb 28 12:12:17 EST 2014


On 2014-02-28 05:47, Shobhit Shrivastava wrote:
> I am working on creating an SDK from an existing product's code base and
> use it as an independent static library. The issue I am facing is that the
> older product, let's say MM, used to link with all the dependencies in the
> executable but I have to provide one monolith SDK lib that contains all its
> dependencies within itself. I have struggled but couldn't find the way to
> achieve that in CMAKE.

I'm not sure if it is possible in CMake to produce a static library that 
contains the objects from other static libraries. (I'm not even 100% 
sure it's possible in general, on Windows... I believe with AR-type 
libraries you could unpack the dependencies and repack their contents 
into your own library. Ugly, but doable.)

However, if your downstream is also using CMake, you shouldn't need to; 
just provide exported targets for "MM" and make sure that the interface 
link libraries for "MMlib" include all of its dependencies. CMake will 
then take care that anything linking to "MMlib" will also pick up the 
interface dependencies.

> set_target_properties( MMLib PROPERTIES LINK_FLAGS
> "/LIBPATH:Path_To_MM3PLib1" )

Don't do this; it's not portable. Set the interface link libraries instead.

> set_target_properties( MMLib PROPERTIES IMPORTED_LOCATION
> (Path_To_MM3PLib1) )

This won't do what you want; you're telling CMake that the library to 
link for the "MMLib" target is a third-party target, and not the "MMlib" 
library.

-- 
Matthew



More information about the CMake mailing list