[CMake] static & shared library

William A. Hoffman billlist at nycap.rr.com
Wed Aug 3 08:41:10 EDT 2005


At 08:30 AM 8/3/2005, Doug Henry wrote:
>thanks.  its not a real problem, but if I didn't have to compile twice that would obviously be better :-)  Right now I just tack on -static to the target name and have two targets.  I'm basically trying to loosely simulate the autotools functionality where you can independently switch on/off shared and static (--disable-shared --enable-static).

I think you want the BUILD_SHARED_LIBS flag.  If you add the libraries without specifying static or
shared, then the global BUILD_SHARED_LIBS is used instead.  This works just like autoconfs --enable-shared
and --enable-static.


ADD_LIBRARY: Add an library to the project using the specified source files.

  ADD_LIBRARY(libname [SHARED | STATIC | MODULE]
              source1 source2 ... sourceN)

Adds a library target. SHARED, STATIC or MODULE keywords are used to set the library type. If the keyword MODULE appears, the library type is set to MH_BUNDLE on systems which use dyld. On systems without dyld, MODULE is treated like SHARED. If no keywords appear as the second argument, the type defaults to the current value of BUILD_SHARED_LIBS. If this variable is not set, the type defaults to STATIC. 


-Bill



More information about the CMake mailing list