[CMake] Generating shared libraries on Visual 8.0

Julien Michel julien.michel at c-s.cnes.fr
Tue Sep 30 04:18:04 EDT 2008


Stefan Buschmann a écrit :
> How do you create those libraries in your CMakeLists.txt? To build a 
> shared library, you usually only need to specify "SHARED" when calling 
> ADD_LIBRARY, e.g.
>  ADD_LIBRARY(MyProject SHARED ${PROJECT_SOURCES})
> 
> If you want to decide whether to build static or dynamic libraries based 
> on a variable, I would use something like this (this could of course be 
> simplified):
>  IF (SHARED_LIBRARIES)
>    ADD_LIBRARY(MyProject SHARED ${PROJECT_SOURCES})
>  ELSE (SHARED_LIBRARIES)
>    ADD_LIBRARY(MyProject ${PROJECT_SOURCES})
>  ENDIF (SHARED_LIBRARIES)
> 
> Stefan

Stefan,

We are not specifying anything when doing ADD_LIBRARY. We are using the 
BUILD_SHARED_LIBS variable instead. This variable is set to SHARED or 
STATIC in our root CMakeLists.txt depending on what the user choosed in 
the cmake gui.

In our "Mastering CMake" book, it is said that if you do not specify 
anything in ADD_LIBRARY, then it uses the BUILD_SHARED_LIBS variable to 
determine if it should build static or shared libraries. Should we set 
this variable to SHARED/STATIC or to 1/0 as it is recommended in cmake 
2.6 online documentation ? Maybe we did misread the book as we are 
setting BUILD_SHARED_LIBS to SHARED or STATIC. The strange thing is that 
it is working fine on linux-like OS ...

Julien
-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Julien MICHEL - Ingénieur d'études - Traitement d'images
CS Systèmes d'Information - Division ESPACE
Département Information Géographique & Image
Téléphone : +33 561 17 64 27
Email : julien.michel at c-s.fr

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



More information about the CMake mailing list