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 # define SYS_VISIBILITY_ENABLE 1
34 #elif !defined(WIN32) // && defined(MAKING_STATIC)
35 # define SYS_VISIBILITY_ENABLE 1
36 #else
37 # define SYS_VISIBILITY_ENABLE 0
38 #endif
39 
40 #if SYS_VISIBILITY_ENABLE
41 # if defined(WIN32)
42 # define SYS_VISIBILITY_EXPORT __declspec(dllexport)
43 # define SYS_VISIBILITY_IMPORT __declspec(dllimport)
44 # define SYS_VISIBILITY_EXPORT_TINST SYS_VISIBILITY_EXPORT
45 # define SYS_VISIBILITY_IMPORT_TINST SYS_VISIBILITY_IMPORT
46  // On Windows, doing "extern template class SYS_VISIBILITY_EXPORT" causes
47  // warning C4910:
48  // '__declspec(dllexport)' and 'extern' are incompatible on an explicit
49  // instantiation
50  // To avoid this, we just expand it out to nothing. The means that when we
51  // compile the code within the library that's doing the explicit
52  // instantiation, other .C files in the library will end up generically
53  // instantiating anyways.
54 # define SYS_VISIBILITY_EXPORT_EXTERN_TEMPLATE(...) \
55  /* nothing */
56 # define SYS_VISIBILITY_IMPORT_EXTERN_TEMPLATE(...) \
57  extern template class SYS_VISIBILITY_IMPORT __VA_ARGS__
58 # elif (SYS_IS_CLANG_GE(3, 3) || SYS_IS_GCC_GE(4, 7))
59  // As of clang 3.3 and gcc 4.7, template instantiations do *not* inherit
60  // the visibility attribute.
61  // (See: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51930)
62 # define SYS_VISIBILITY_EXPORT __attribute__((visibility("default")))
63 # define SYS_VISIBILITY_IMPORT __attribute__((visibility("default")))
64 # define SYS_VISIBILITY_EXPORT_TMPL SYS_VISIBILITY_EXPORT
65 # define SYS_VISIBILITY_IMPORT_TMPL SYS_VISIBILITY_IMPORT
66 # define SYS_VISIBILITY_EXPORT_TINST SYS_VISIBILITY_EXPORT
67 # define SYS_VISIBILITY_IMPORT_TINST SYS_VISIBILITY_IMPORT
68 # define SYS_VISIBILITY_EXPORT_EXTERN_TEMPLATE(...) \
69  extern template class SYS_VISIBILITY_EXPORT __VA_ARGS__
70 # define SYS_VISIBILITY_IMPORT_EXTERN_TEMPLATE(...) \
71  extern template class SYS_VISIBILITY_IMPORT __VA_ARGS__
72 # elif SYS_IS_GCC_GE(4, 2)
73 # define SYS_VISIBILITY_EXPORT __attribute__((visibility("default")))
74 # define SYS_VISIBILITY_IMPORT __attribute__((visibility("default")))
75 # endif
76 #endif
77 
78 #undef SYS_VISIBILITY_ENABLE
79 
80 #ifndef SYS_VISIBILITY_EXPORT
81 # define SYS_VISIBILITY_EXPORT
82 #endif
83 
84 #ifndef SYS_VISIBILITY_IMPORT
85 # define SYS_VISIBILITY_IMPORT
86 #endif
87 
88 #ifndef SYS_VISIBILITY_EXPORT_TMPL
89 # define SYS_VISIBILITY_EXPORT_TMPL
90 #endif
91 
92 #ifndef SYS_VISIBILITY_IMPORT_TMPL
93 # define SYS_VISIBILITY_IMPORT_TMPL
94 #endif
95 
96 #ifndef SYS_VISIBILITY_EXPORT_TINST
97 # define SYS_VISIBILITY_EXPORT_TINST
98 #endif
99 
100 #ifndef SYS_VISIBILITY_IMPORT_TINST
101 # define SYS_VISIBILITY_IMPORT_TINST
102 #endif
103 
104 #ifndef SYS_VISIBILITY_EXPORT_EXTERN_TEMPLATE
105 # define SYS_VISIBILITY_EXPORT_EXTERN_TEMPLATE(...)
106 #endif
107 #ifndef SYS_VISIBILITY_IMPORT_EXTERN_TEMPLATE
108 # define SYS_VISIBILITY_IMPORT_EXTERN_TEMPLATE(...)
109 #endif
110 
111 #endif