[CMake] Generating shared libraries on Visual 8.0

Stefan Buschmann s_buschmann at gmx.de
Mon Sep 29 13:00:11 EDT 2008


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


Julien Michel schrieb:
> Dear Cmake user,
>
> I am still having trouble when trying to generate shared libraries on 
> visual (7.1  and 8.0).
>
> I am correctly taggin the __declspec(dllexport)/__declspec(dllimport) 
> when choosing SHARED_LIBRARIES in the cmake configuration process.
>
> But When I open the properties of a given libraries in visual IDE, it 
> says static libraries (.lib). So the whole project think he is 
> generating shared libraries, and put __declspec(dllimport) everywhere 
> when using a lib, though actually visual builds static libraries. This 
> is of course not compiling.
>
> Of course I can manually open each library properties and toggle the 
> configuration type to dynamic libraries (.dll), but this is quite 
> heavy since I have quite a lot of libraries ...
>
> Any idea why visual persist in building static libraries, even if i 
> export the symbols and configure the cmake SHARED_LIBRARIES option 
> (working fine under linux, by the way) ?
>
> Julien



More information about the CMake mailing list