[CMake] simple project in Visual Studio 2008

Hendrik Sattler post at hendrik-sattler.de
Wed Aug 20 09:36:37 EDT 2008


Zitat von Mike Jackson <mike.jackson at imts.us>:
> BUILD_SHARED_LIBS: Global flag to cause add_library to create shared
> libraries if on.
>
> If present and true, this will cause all libraries to be built shared
> unless the library was explicitly added as a static library. This
> variable is often added to projects as an OPTION so that each user of a
> project can decide if they want to build the project using shared or
> static libraries.
>
> Most projects do in-fact add this as an option so that the libraries
> can be built as Static or Dynamic so I added it here. I will make a
> note in the Wiki.

They add this so that it is directly visible in e.g. ccmake. Saves  
some manual typing. Nothing else implied.

>> 2.
>> "#if defined(_MSC_VER)" is working for MSVC but gcc can also do   
>> __declspec(dllexport) on Win32 and other Windows compilers probably  
>>  too.
>> You can use "#if defined(_WIN32)" for gcc and msvc.
>>
>> The result (and that's _all_ that is needed, works with cmake and libtool):
>> #if defined(_WIN32)
>> #  if defined(MyLibrary_EXPORTS) or defined(DLL_EXPORT)

s/or/||/

> I am going to leave out the GCC until I can get a
> concise example based on the GCC web page working. I do not use that
> GCC Feature in my projects (yet) so I probably would mess up any
> example that I tried to write at the moment.

I used it in various projects except the default visibility classes  
with hidden members. Just one hint: member functions available via  
virtual function tables do not need to be exported as they are always  
accessed via the VFT.
Additionally, you should always allocate and destroy a class in the  
same library or executable, just in case you link to different runtime  
implementations (e.g. from different MSVC versions). And that is  
common on Windows.

HS




More information about the CMake mailing list