Darko Miletic wrote:
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. 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.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. something like this should do it: cd static_lib_dir cmake -D BUILD_SHARED_LIBS:BOOL=FALSE ../srcdir cd shared_lib_dir cmake -D BUILD_SHARED_LIBS:BOOL=TRUE ../srcdir -- Mike Talbot Senior Software Developer Schlumberger Lambourn Court, Wyndyke Furlong, Abingdon Business Park, Abingdon, Oxfordshire, OX14 1UJ, UK Tel: +44 (0)1235 543 488 |
_______________________________________________ CMake mailing list CMake@cmake.org http://www.cmake.org/mailman/listinfo/cmake