[Cmake] Linking libraries to make a library...

Brad King brad . king at kitware . com
Thu, 24 Jul 2003 11:44:11 -0400 (EDT)


Nick,

> What command should I use to make a static library from several other
> individual libraries.

This is a windows thing, and cannot be done by most unix linkers.
However, there is probably another way to achieve your goal. You can
organize your CMakeLists.txt files like this:

> -->/lib_1
ADD_LIBRARY(lib1 lib1.cxx)

> -->/lib_2
ADD_LIBRARY(lib2 lib2.cxx)
TARGET_LINK_LIBRARIES(lib2 lib1)

> -->/lib_3
ADD_LIBRARY(lib3 lib3.cxx)
TARGET_LINK_LIBRARIES(lib3 lib2)

> -->/app_src
ADD_EXECUTABLE(app app.cxx)
TARGET_LINK_LIBRARIES(app lib3)

Any program that links to lib3 will automatically link to lib2 and lib1.
These dependencies are managed by cmake and invisible to the user.  If you
want to install one big library for use by outside projects, then you can
configure a cmake package for your library that will forward the
dependencies into any outside cmake project.

-Brad