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

Shobhit Shrivastava shobhit.shri at gmail.com
Fri Feb 28 05:47:18 EST 2014


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.

The structure of the code is such that the MMexe- old product's executable-
depends on MMLib but MMLib in turn depends on 3rd party libs, let's say
MM3PLib1 and MM3PLib2. In older CMAKE files, MMExe would depend on MM3PLib1
and MM3PLib2 so all dependencies were resolved at link time.

But now, we need to create MMLib in such a way that its clients will not
have to depend on, or link to, any other 3rd parties. In visual Studio, we
can do it by using Librarian -> General-> Additional Dependencies.   This
way the generated MMLib contains all its dependencies by archiving them. I
have tried multiple approaches but couldn't achieve the same result through
CMAKE. Even after setting these values, the corresponding fields in VS are
blank.

I have tried following approaches in different ways in MMLib's CMAKE files
and none of them seem to be working for me.

----------------------------------------------------------------------------------------------------------------------------------------------
link_directories (Path_To_MM3PLib1)

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

add_library (MMLib STATIC Path_To_MM3PLib1/MM3PLib1.lib)
add_library(MMLib Path_To_MM3PLib2/MM3PLib2.lib)

target_link_libraries (MMLib MM3PLib1)
target_link_libraries (MMLib MM3PLib2)
target_link_libraries (MMLib MM3PLib1.lib)
target_link_libraries (MMLib MM3PLib2.lib)
-----------------------------------------------------------------------------------------------------------------------------------------------

Thanks,
-Shobhit
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20140228/bf841367/attachment.html>


More information about the CMake mailing list