[CMake] simple project in Visual Studio 2008

Hendrik Sattler post at hendrik-sattler.de
Wed Aug 20 06:02:54 EDT 2008


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.

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

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




More information about the CMake mailing list