[CMake] simple project in Visual Studio 2008

Mike Jackson mike.jackson at imts.us
Wed Aug 20 09:11:24 EDT 2008



On Aug 20, 2008, at 6:02 AM, Hendrik Sattler wrote:

> Zitat von Jos.van.den.Oever at panalytical.com:
>>> http://www.cmake.org/Wiki/BuildingWinDLL
>>>
>>> Take a look, send feedback or just correct any errors..
>>
>> Very nice Mike. This will really help people coming from the Linux  
>> side in
>> making their programs compile with MSVC.
>
> But much too complicated.
>
> 1.
> LIB_TYPE is automatically set by cmake, no need to do that in the  
> script. It is also not necessary do add a definition. Actually, you  
> don't have to do anything special in the cmake script to do it right.

 From the documentation for BUILD_SHARED_LIBS:


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.


>
> 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)
> #    define LIB_SYMBOL __declspec(dllexport)
> #  else
> #    define LIB_SYMBOL __declspec(dllimport)
> #  endif
> #else if HAVE_VISIBILITY
> #  define LIB_SYMBOL __attribute((visibility("default")))
> #endif
>

I agree. I was taking the example from one of my own projects and  
didn't walk the project thoroughly to see that for the basic example  
the extra definition was NOT needed. It has been corrected in the Wiki.


> Optionally with gcc on linux, compile with -fvisibility=hidden - 
> DHAVE_VISIBILITY and all is fine.
> You might want to check this flag in cmake script or specify it  
> statically as gcc >= 4.0.2 support this.
>
> You still have to decide about the calling convention on windows.
>
> HS
>

Great Feedback. 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 did write a note in the Wiki with a link to the GCC site for  
those interested in this.


Mike Jackson


  



More information about the CMake mailing list