[CMake] Function for visibility definitions

Andreas Pakulat apaku at gmx.de
Thu Feb 11 10:26:23 EST 2010


On 11.02.10 16:09:34, Hendrik Sattler wrote:
> Zitat von Michael Wild <themiwi at gmail.com>:
>
>>
>> On 11. Feb, 2010, at 15:40 , Hendrik Sattler wrote:
>>
>>> Zitat von Bill Hoffman <bill.hoffman at kitware.com>:
>>>> That said, you could have CMake configure a .h file that had this stuff
>>>> in it.  It might be nice if the function did that automatically, as it
>>>> is almost the same code for every project.  Then once your project was
>>>> built with CMake, you would install the configured .h files and other
>>>> build systems could still use the software.
>>>
>>> OTOH, cmake is a build system, not a code generator.
>>> This export stuff is so simple[1], why all the hassle to generate it?
>>>
>>> HS
>>>
>>> [1]: you only have too cases: Windows and gcc>=4. All compilers on   
>>> Windows use the same syntax.
>>>
>>
>> Also refer to http://gcc.gnu.org/wiki/Visibility
>
> ...which can be even simplified to:
> #if defined _WIN32 || defined __CYGWIN__
>   #ifdef PROJECT_EXPORT
>     #define DLL_PUBLIC __declspec(dllexport)
>   #endif
> #else
>   #if __GNUC__ >= 4
>     #define DLL_PUBLIC __attribute__ ((visibility("default")))
>     #define DLL_LOCAL  __attribute__ ((visibility("hidden")))
>   #endif
> #endif
> #ifndef DLL_PUBLIC
>   #define DLL_PUBLIC
> #endif
> #ifndef DLL_LOCAL
>   #define DLL_LOCAL
> #endif
>
> Note: __declspec(dllimport) is not used here as it is only to be used  
> when including a header file for a DLL. This needs a different solution 
> (some custom define) in the header, only.

At least Qt and KDE manage just fine with __declspec(dllimport) in their
xxx_export headers defining these macros. That is they define DLL_PUBLIC to
be __declspec(dllimport) when PROJECT_EXPORT is not defined and use the
fact, that cmake sets a define already when building a shared library.
(MAKE_XX_LIBRARY or something similar).

Andreas

-- 
Don't you feel more like you do now than you did when you came in?


More information about the CMake mailing list