<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Darko Miletic wrote:
<blockquote cite="mid43E217CE.3000803@uvcms.com" type="cite">
  <pre wrap="">Xavier Delannoy wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">hi all, 

Is there any proper way to build a shared AND static lib with cmake ?
    </pre>
  </blockquote>
  <pre wrap=""><!---->
Not directly from the same script. You will have to write two separate
scripts for that. One that will produce static lib and another that will
produce shared lib. It can be represented like this:

&lt;root_source_dir&gt;
|
|--&lt;srcdir&gt;
|
|--&lt;static_lib_dir&gt; (script goes here)
|
|--&lt;shared_lib_dir&gt; (script goes here)

So in static_lib_dir CMakeLists.txt will be like this:

SET (SRCS a.cpp b.cpp ... x.cpp)

ADD_LIBRARY(&lt;libname&gt; STATIC ${SRCS})

And in shared_lib_dir CMakeLists.txt will be like this:

SET (SRCS a.cpp b.cpp ... x.cpp)

ADD_LIBRARY(&lt;libname&gt; SHARED ${SRCS})

Or even better you can have one file that lists source files in src
folder and include that one in both scripts like this:

sources.txt:

SET(SRC a.cpp b.cpp ... x.cpp)


So in static_lib_dir CMakeLists.txt will be like this:

INCLUDE(${CGILib_SOURCE_DIR}/src/sources.txt)

ADD_LIBRARY(&lt;libname&gt; STATIC ${SRCS})

And in shared_lib_dir CMakeLists.txt will be like this:

INCLUDE(${CGILib_SOURCE_DIR}/src/sources.txt)

ADD_LIBRARY(&lt;libname&gt; SHARED ${SRCS})

But you get the idea.

  </pre>
</blockquote>
I believe that if you don't specify STATIC or SHARED in the ADD_LIBRARY
command, then you can control whether libraries are built as shared or
static via the BUILD_SHARED_LIBS variable.&nbsp; If you set this to true in
your cache, then all libraries in your project that aren't explicitly
STATIC will be built as shared and vice-versa.<br>
<br>
something like this should do it:<br>
<br>
cd static_lib_dir<br>
cmake -D BUILD_SHARED_LIBS:BOOL=FALSE ../srcdir<br>
<br>
cd shared_lib_dir<br>
cmake -D BUILD_SHARED_LIBS:BOOL=TRUE ../srcdir<br>
<br>
<pre class="moz-signature" cols="72">-- 
Mike Talbot
Senior Software Developer
Schlumberger
Lambourn Court, Wyndyke Furlong,
Abingdon Business Park, Abingdon,
Oxfordshire, OX14 1UJ, UK
Tel: +44 (0)1235 543 488
</pre>
</body>
</html>