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