HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SYS_Visibility.h
Go to the documentation of this file.
1 //
2 // This file is intended to be included in each library-specific API file.
3 // For example, in a hypthetical LIB_API.h:
4 //
5 /*
6 #include <SYS/SYS_Visibility.h>
7 #ifdef LIB_EXPORTS
8 #define LIB_API SYS_VISIBILITY_EXPORT
9 #define LIB_API_TMPL SYS_VISIBILITY_EXPORT_TMPL
10 #define LIB_API_TINST SYS_VISIBILITY_EXPORT_TINST
11 #else
12 #define LIB_API SYS_VISIBILITY_IMPORT
13 #define LIB_API_TMPL SYS_VISIBILITY_IMPORT_TMPL
14 #define LIB_API_TINST SYS_VISIBILITY_IMPORT_TINST
15 #endif
16 */
17 // LIB_API should be used for classes, functions or global variables that need
18 // to be visible by external users of that library. LIB_API_TINST is a special
19 // case for template instantiations, which require an export flag on Windows,
20 // clang and gcc 4.7 or later. They're not required when building with gcc 4.6
21 // and older, since they inherit the visibility from the template class/function
22 // they're instantiated from.
23 // LIB_API_TMPL is required for types which are used as template arguments in
24 // gcc 4.7 and later. Otherwise derived types will not be exported, since all
25 // dependent types need to be visible for the final type to be exported.
26 
27 #ifndef __SYS_Visibility_h__
28 #define __SYS_Visibility_h__
29 
30 #include "SYS_Compiler.h"
31 
32 #if !defined(MAKING_STATIC)
33 # if defined(WIN32)
34 # define SYS_VISIBILITY_EXPORT __declspec(dllexport)
35 # define SYS_VISIBILITY_IMPORT __declspec(dllimport)
36 # define SYS_VISIBILITY_EXPORT_TINST SYS_VISIBILITY_EXPORT
37 # define SYS_VISIBILITY_IMPORT_TINST SYS_VISIBILITY_IMPORT
38 # define SYS_VISIBILITY_EXPORT_EXTERN_TEMPLATE(CLASS_) \
39  /* nothing */
40 # define SYS_VISIBILITY_IMPORT_EXTERN_TEMPLATE(CLASS_) \
41  extern template class SYS_VISIBILITY_IMPORT CLASS_
42 # elif (SYS_IS_CLANG_GE(3, 3) || SYS_IS_GCC_GE(4, 7))
43  // As of clang 3.3 and gcc 4.7, template instantiations do *not* inherit
44  // the visibility attribute.
45  // (See: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51930)
46 # define SYS_VISIBILITY_EXPORT __attribute__((visibility("default")))
47 # define SYS_VISIBILITY_IMPORT __attribute__((visibility("default")))
48 # define SYS_VISIBILITY_EXPORT_TMPL SYS_VISIBILITY_EXPORT
49 # define SYS_VISIBILITY_IMPORT_TMPL SYS_VISIBILITY_IMPORT
50 # define SYS_VISIBILITY_EXPORT_TINST SYS_VISIBILITY_EXPORT
51 # define SYS_VISIBILITY_IMPORT_TINST SYS_VISIBILITY_IMPORT
52 # define SYS_VISIBILITY_EXPORT_EXTERN_TEMPLATE(CLASS_) \
53  extern template class SYS_VISIBILITY_EXPORT CLASS_
54 # define SYS_VISIBILITY_IMPORT_EXTERN_TEMPLATE(CLASS_) \
55  extern template class SYS_VISIBILITY_IMPORT CLASS_
56 # elif SYS_IS_GCC_GE(4, 2)
57 # define SYS_VISIBILITY_EXPORT __attribute__((visibility("default")))
58 # define SYS_VISIBILITY_IMPORT __attribute__((visibility("default")))
59 # endif
60 #endif
61 
62 #ifndef SYS_VISIBILITY_EXPORT
63 # define SYS_VISIBILITY_EXPORT
64 #endif
65 
66 #ifndef SYS_VISIBILITY_IMPORT
67 # define SYS_VISIBILITY_IMPORT
68 #endif
69 
70 #ifndef SYS_VISIBILITY_EXPORT_TMPL
71 # define SYS_VISIBILITY_EXPORT_TMPL
72 #endif
73 
74 #ifndef SYS_VISIBILITY_IMPORT_TMPL
75 # define SYS_VISIBILITY_IMPORT_TMPL
76 #endif
77 
78 #ifndef SYS_VISIBILITY_EXPORT_TINST
79 # define SYS_VISIBILITY_EXPORT_TINST
80 #endif
81 
82 #ifndef SYS_VISIBILITY_IMPORT_TINST
83 # define SYS_VISIBILITY_IMPORT_TINST
84 #endif
85 
86 #ifndef SYS_VISIBILITY_EXPORT_EXTERN_TEMPLATE
87 # define SYS_VISIBILITY_EXPORT_EXTERN_TEMPLATE(CLASS_)
88 #endif
89 #ifndef SYS_VISIBILITY_IMPORT_EXTERN_TEMPLATE
90 # define SYS_VISIBILITY_IMPORT_EXTERN_TEMPLATE(CLASS_)
91 #endif
92 
93 #endif