[CMake] Building both SHARED and STATIC libs

Eric Noulard eric.noulard at gmail.com
Thu Jan 25 13:40:11 EST 2007


2007/1/25, Andreas Schneider <mail at cynapses.org>:
> Eric Noulard wrote:
> > Is there a way to build both shared AND static
>
> Hi Eric,
>
> yes there is. From the cmake documentation:
>
> SET_TARGET_PROPERTIES
>
>         When a library is built  CMake  by  default  generates  code  to
>         remove  any  existing library using all possible names.  This is
>         needed to support  libraries  that  switch  between  STATIC  and
>         SHARED  by  a  user  option.   However when using OUTPUT_NAME to
>         build a static and shared library of the same name using differ‐
>         ent  logical  target  names  the  two  targets  will remove each
>         other's  files.   This  can  be   prevented   by   setting   the
>         CLEAN_DIRECT_OUTPUT property to 1.
>
> RTFM.

Ok your are right I should have RTFFFFM.
Nevertheless I post here how to write such rule since I was puzzled by
the FM, before I understand how I should wriet it down.

So I managed to get both static and shared lib by writing:

ADD_LIBRARY(services-static STATIC ${SERVICE_SRC})
SET_TARGET_PROPERTIES(services-static
  PROPERTIES OUTPUT_NAME services
  CLEAN_DIRECT_OUTPUT 1)

then again

ADD_LIBRARY(services-dynamic DYNAMIC ${SERVICE_SRC})
SET_TARGET_PROPERTIES(services-dynamic
  PROPERTIES OUTPUT_NAME services
  CLEAN_DIRECT_OUTPUT 1)

-- 
Erk


More information about the CMake mailing list