[Cmake] How do I link a static library into a library

Stuart MacKay smackay at flagstonesoftware.com
Tue, 20 Apr 2004 16:35:10 -0700


--Apple-Mail-4--1029787782
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed

I have a project that generates a C++ library which I am migrating to 
CMake from the GNU autotools. The library uses functions from an 
external C library (zlib) which are only used internally. I have been 
trying to get cmake to link in the external library code so I do not 
have to distribute it with the project library.

The project is structured as follows:

project-root
project-root/library-source
project-root/lib/libz.a

The project-root contains a CMakeLists.txt with:

PROJECT(MyProject)
LINK_LIBRARIES(lib/libz.a)
SUBDIRS(library-source)

then the library-source directory contains CMakeLists.txt which 
contains the lines:

SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__cplusplus")
...
ADD_LIBRARY(mylib STATIC ${SRCS})

I have tried various combinations of specifying the external library 
with either LINK_LIBRARIES command and TARGET_LINK_LIBRARIES. In all 
cases the zlib functions are not linked in with the library.

Do I need to consider the project structure when choosing which 
CMakeLists.txt file to put commands in ? Or am I missing something 
fundamental when using cmake ?

A canonical example would be greatly appreciated.


Stuart
--
Stuart MacKay, Seattle, WA, USA

--Apple-Mail-4--1029787782
Content-Transfer-Encoding: 7bit
Content-Type: text/enriched;
	charset=US-ASCII

I have a project that generates a C++ library which I am migrating to
CMake from the GNU autotools. The library uses functions from an
external C library (zlib) which are only used internally. I have been
trying to get cmake to link in the external library code so I do not
have to distribute it with the project library.


The project is structured as follows:


project-root

project-root/library-source

project-root/lib/libz.a


The project-root contains a CMakeLists.txt with:


PROJECT(MyProject)

LINK_LIBRARIES(lib/libz.a)

SUBDIRS(library-source)


then the library-source directory contains CMakeLists.txt which
contains the lines:


<fixed>SET (CMAKE_CXX_FLAGS
<color><param>8987,1311,1513</param>"${CMAKE_CXX_FLAGS}
-D__cplusplus"</color>)

...

ADD_LIBRARY(mylib STATIC ${SRCS})


</fixed>I have tried various combinations of specifying the external
library with either LINK_LIBRARIES command and TARGET_LINK_LIBRARIES.
In all cases the zlib functions are not linked in with the library.


Do I need to consider the project structure when choosing which
CMakeLists.txt file to put commands in ? Or am I missing something
fundamental when using cmake ?


A canonical example would be greatly appreciated.



Stuart

--

Stuart MacKay, Seattle, WA, USA


--Apple-Mail-4--1029787782--