[CMake] shared and static library
Xavier Delannoy
xavier.delannoy at netasq.com
Thu Feb 2 09:59:20 EST 2006
On Thu, 02 Feb 2006 11:31:42 -0300
Darko Miletic <darko at uvcms.com> wrote:
> Xavier Delannoy wrote:
> > hi all,
> >
> > Is there any proper way to build a shared AND static lib with cmake ?
>
> 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:
>
> <root_source_dir>
> |
> |--<srcdir>
> |
> |--<static_lib_dir> (script goes here)
> |
> |--<shared_lib_dir> (script goes here)
>
> So in static_lib_dir CMakeLists.txt will be like this:
>
> SET (SRCS a.cpp b.cpp ... x.cpp)
>
> ADD_LIBRARY(<libname> STATIC ${SRCS})
>
> And in shared_lib_dir CMakeLists.txt will be like this:
>
> SET (SRCS a.cpp b.cpp ... x.cpp)
>
> ADD_LIBRARY(<libname> 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(<libname> STATIC ${SRCS})
>
> And in shared_lib_dir CMakeLists.txt will be like this:
>
> INCLUDE(${CGILib_SOURCE_DIR}/src/sources.txt)
>
> ADD_LIBRARY(<libname> SHARED ${SRCS})
>
> But you get the idea.
this doesn't work, or maybe I do something wrong.
When I do this:
cd static_lib_dir && cmake . && make
cd shared_lib_dir && cmake . && make
In my LIBRARY_OUTPUT_PATH I have only have the last type of lib which was build (in this case the shared type).
Any suggestion ?
More information about the CMake
mailing list