]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/versioning.h
Update visibility stuff so we can build libcups.2.dylib without an exports list.
[thirdparty/cups.git] / cups / versioning.h
1 /*
2 * API versioning definitions for CUPS.
3 *
4 * Copyright © 2007-2018 by Apple Inc.
5 *
6 * Licensed under Apache License v2.0. See the file "LICENSE" for more
7 * information.
8 */
9
10 #ifndef _CUPS_VERSIONING_H_
11 # define _CUPS_VERSIONING_H_
12
13 /*
14 * This header defines several macros that add compiler-specific attributes for
15 * functions:
16 *
17 * - _CUPS_API_major_minor[_patch]: Specifies when an API became available by
18 * CUPS version.
19 * - _CUPS_DEPRECATED: Function is deprecated with no replacement.
20 * - _CUPS_DEPRECATED_MSG("message"): Function is deprecated and has a
21 * replacement.
22 * - _CUPS_FORMAT(format-index, additional-args-index): Function has a
23 * printf-style format argument followed by zero or more additional
24 * arguments. Indices start at 1.
25 * - _CUPS_INTERNAL: Function is internal with no replacement API.
26 * - _CUPS_INTERNAL_MSG("msg"): Function is internal - use specified API
27 * instead.
28 * - _CUPS_NONNULL((arg list)): Specifies the comma-separated argument indices
29 * are assumed non-NULL. Indices start at 1.
30 * - _CUPS_NORETURN: Specifies the function does not return.
31 * - _CUPS_PRIVATE: Specifies the function is private to CUPS.
32 * - _CUPS_PUBLIC: Specifies the function is public API.
33 */
34
35 /*
36 * Determine which compiler is being used and what annotation features are
37 * available...
38 */
39
40 # ifdef __APPLE__
41 # include <os/availability.h>
42 # endif /* __APPLE__ */
43
44 # ifdef __has_extension /* Clang */
45 # define _CUPS_HAS_DEPRECATED
46 # define _CUPS_HAS_FORMAT
47 # define _CUPS_HAS_NORETURN
48 # define _CUPS_HAS_VISIBILITY
49 # if __has_extension(attribute_deprecated_with_message)
50 # define _CUPS_HAS_DEPRECATED_WITH_MESSAGE
51 # endif
52 # if __has_extension(attribute_unavailable_with_message)
53 # define _CUPS_HAS_UNAVAILABLE_WITH_MESSAGE
54 # endif
55 # elif defined(__GNUC__) /* GCC and compatible */
56 # if __GNUC__ >= 3 /* GCC 3.0 or higher */
57 # define _CUPS_HAS_DEPRECATED
58 # define _CUPS_HAS_FORMAT
59 # define _CUPS_HAS_NORETURN
60 # define _CUPS_HAS_VISIBILITY
61 # endif /* __GNUC__ >= 3 */
62 # if __GNUC__ >= 5 /* GCC 5.x */
63 # define _CUPS_HAS_DEPRECATED_WITH_MESSAGE
64 # elif __GNUC__ == 4 && __GNUC_MINOR__ >= 5
65 /* GCC 4.5 or higher */
66 # define _CUPS_HAS_DEPRECATED_WITH_MESSAGE
67 # endif /* __GNUC__ >= 5 */
68 # endif /* __has_extension */
69
70
71 /*
72 * Define _CUPS_INTERNAL, _CUPS_PRIVATE, and _CUPS_PUBLIC visibilty macros for
73 * internal/private/public functions...
74 */
75
76 # ifdef _CUPS_HAS_VISIBILITY
77 # define _CUPS_INTERNAL __attribute__ ((visibility("hidden")))
78 # define _CUPS_PRIVATE __attribute__ ((visibility("default")))
79 # define _CUPS_PUBLIC __attribute__ ((visibility("default")))
80 # elif defined(_WIN32) && defined(LIBCUPS2_EXPORTS)
81 # define _CUPS_INTERNAL
82 # define _CUPS_PRIVATE __declspec(dllexport)
83 # define _CUPS_PUBLIC __declspec(dllexport)
84 # else
85 # define _CUPS_INTERNAL
86 # define _CUPS_PRIVATE
87 # define _CUPS_PUBLIC
88 # endif /* _CUPS_HAS_VISIBILITY */
89
90
91 /*
92 * Define _CUPS_API_major_minor[_patch] availability macros for CUPS.
93 *
94 * Note: Using any of the _CUPS_API macros automatically adds _CUPS_PUBLIC.
95 */
96
97 # if defined(__APPLE__) && !defined(_CUPS_SOURCE) && !TARGET_OS_IOS
98 /*
99 * On Apple operating systems, the _CUPS_API_* constants are defined using the
100 * API_ macros in <os/availability.h>.
101 *
102 * On iOS, we don't actually have libcups available directly, but the supplied
103 * libcups_static target in the Xcode project supports building on iOS 11.0 and
104 * later.
105 */
106 # define _CUPS_API_1_1_19 API_AVAILABLE(macos(10.3), ios(11.0)) _CUPS_PUBLIC
107 # define _CUPS_API_1_1_20 API_AVAILABLE(macos(10.4), ios(11.0)) _CUPS_PUBLIC
108 # define _CUPS_API_1_1_21 API_AVAILABLE(macos(10.4), ios(11.0)) _CUPS_PUBLIC
109 # define _CUPS_API_1_2 API_AVAILABLE(macos(10.5), ios(11.0)) _CUPS_PUBLIC
110 # define _CUPS_API_1_3 API_AVAILABLE(macos(10.5), ios(11.0)) _CUPS_PUBLIC
111 # define _CUPS_API_1_4 API_AVAILABLE(macos(10.6), ios(11.0)) _CUPS_PUBLIC
112 # define _CUPS_API_1_5 API_AVAILABLE(macos(10.7), ios(11.0)) _CUPS_PUBLIC
113 # define _CUPS_API_1_6 API_AVAILABLE(macos(10.8), ios(11.0)) _CUPS_PUBLIC
114 # define _CUPS_API_1_7 API_AVAILABLE(macos(10.9), ios(11.0)) _CUPS_PUBLIC
115 # define _CUPS_API_2_0 API_AVAILABLE(macos(10.10), ios(11.0)) _CUPS_PUBLIC
116 # define _CUPS_API_2_2 API_AVAILABLE(macos(10.12), ios(11.0)) _CUPS_PUBLIC
117 # define _CUPS_API_2_2_4 API_AVAILABLE(macos(10.13), ios(11.0)) _CUPS_PUBLIC
118 # define _CUPS_API_2_2_7 API_AVAILABLE(macos(10.14), ios(11.0)) _CUPS_PUBLIC
119 # define _CUPS_API_2_3 _CUPS_PUBLIC
120 # else
121 # define _CUPS_API_1_1_19 _CUPS_PUBLIC
122 # define _CUPS_API_1_1_20 _CUPS_PUBLIC
123 # define _CUPS_API_1_1_21 _CUPS_PUBLIC
124 # define _CUPS_API_1_2 _CUPS_PUBLIC
125 # define _CUPS_API_1_3 _CUPS_PUBLIC
126 # define _CUPS_API_1_4 _CUPS_PUBLIC
127 # define _CUPS_API_1_5 _CUPS_PUBLIC
128 # define _CUPS_API_1_6 _CUPS_PUBLIC
129 # define _CUPS_API_1_7 _CUPS_PUBLIC
130 # define _CUPS_API_2_0 _CUPS_PUBLIC
131 # define _CUPS_API_2_2 _CUPS_PUBLIC
132 # define _CUPS_API_2_2_4 _CUPS_PUBLIC
133 # define _CUPS_API_2_2_7 _CUPS_PUBLIC
134 # define _CUPS_API_2_3 _CUPS_PUBLIC
135 # endif /* __APPLE__ && !_CUPS_SOURCE */
136
137
138 /*
139 * Define _CUPS_DEPRECATED and _CUPS_INTERNAL macros to mark old APIs as
140 * "deprecated" or "unavailable" with messages so you get warnings/errors are
141 * compile-time...
142 *
143 * Note: Using any of the _CUPS_DEPRECATED macros automatically adds
144 * _CUPS_PUBLIC.
145 */
146
147 # if !defined(_CUPS_HAS_DEPRECATED) || (defined(_CUPS_SOURCE) && !defined(_CUPS_NO_DEPRECATED))
148 /*
149 * Don't mark functions deprecated if the compiler doesn't support it
150 * or we are building CUPS source that doesn't care.
151 */
152 # define _CUPS_DEPRECATED _CUPS_PUBLIC
153 # define _CUPS_DEPRECATED_MSG(m) _CUPS_PUBLIC
154 # define _CUPS_DEPRECATED_1_2_MSG(m) _CUPS_PUBLIC
155 # define _CUPS_DEPRECATED_1_6_MSG(m) _CUPS_PUBLIC
156 # define _CUPS_DEPRECATED_1_7_MSG(m) _CUPS_PUBLIC
157 # define _CUPS_DEPRECATED_2_2_MSG(m) _CUPS_PUBLIC
158 # elif defined(__APPLE__) && defined(_CUPS_NO_DEPRECATED)
159 /*
160 * Compiler supports the unavailable attribute, so use it when the code
161 * wants to exclude the use of deprecated API.
162 */
163 # define _CUPS_DEPRECATED __attribute__ ((unavailable)) _CUPS_PUBLIC
164 # define _CUPS_DEPRECATED_MSG(m) __attribute__ ((unavailable(m))) _CUPS_PUBLIC
165 # define _CUPS_DEPRECATED_1_2_MSG(m) API_DEPRECATED(m, macos(10.2,10.5)) API_UNAVAILABLE(ios) _CUPS_PUBLIC
166 # define _CUPS_DEPRECATED_1_6_MSG(m) API_DEPRECATED(m, macos(10.2,10.8)) API_UNAVAILABLE(ios) _CUPS_PUBLIC
167 # define _CUPS_DEPRECATED_1_7_MSG(m) API_DEPRECATED(m, macos(10.2,10.9)) API_UNAVAILABLE(ios) _CUPS_PUBLIC
168 # define _CUPS_DEPRECATED_2_2_MSG(m) API_DEPRECATED(m, macos(10.2,10.12)) API_UNAVAILABLE(ios) _CUPS_PUBLIC
169
170 # elif defined(__APPLE__)
171 /*
172 * Just mark things as deprecated...
173 */
174 # define _CUPS_DEPRECATED __attribute__ ((deprecated)) _CUPS_PUBLIC
175 # define _CUPS_DEPRECATED_MSG(m) __attribute__ ((deprecated(m))) _CUPS_PUBLIC
176 # define _CUPS_DEPRECATED_1_2_MSG(m) API_DEPRECATED(m, macos(10.2,10.5)) API_UNAVAILABLE(ios) _CUPS_PUBLIC
177 # define _CUPS_DEPRECATED_1_6_MSG(m) API_DEPRECATED(m, macos(10.2,10.8)) API_UNAVAILABLE(ios) _CUPS_PUBLIC
178 # define _CUPS_DEPRECATED_1_7_MSG(m) API_DEPRECATED(m, macos(10.2,10.9)) API_UNAVAILABLE(ios) _CUPS_PUBLIC
179 # define _CUPS_DEPRECATED_2_2_MSG(m) API_DEPRECATED(m, macos(10.2,10.12)) API_UNAVAILABLE(ios) _CUPS_PUBLIC
180
181 # elif defined(_CUPS_HAS_UNAVAILABLE_WITH_MESSAGE) && defined(_CUPS_NO_DEPRECATED)
182 /*
183 * Compiler supports the unavailable attribute, so use it when the code
184 * wants to exclude the use of deprecated API.
185 */
186 # define _CUPS_DEPRECATED __attribute__ ((unavailable)) _CUPS_PUBLIC
187 # define _CUPS_DEPRECATED_MSG(m) __attribute__ ((unavailable(m))) _CUPS_PUBLIC
188 # define _CUPS_DEPRECATED_1_2_MSG(m) __attribute__ ((unavailable(m))) _CUPS_PUBLIC
189 # define _CUPS_DEPRECATED_1_6_MSG(m) __attribute__ ((unavailable(m))) _CUPS_PUBLIC
190 # define _CUPS_DEPRECATED_1_7_MSG(m) __attribute__ ((unavailable(m))) _CUPS_PUBLIC
191 # define _CUPS_DEPRECATED_2_2_MSG(m) __attribute__ ((unavailable(m))) _CUPS_PUBLIC
192 # else
193 /*
194 * Compiler supports the deprecated attribute, so use it.
195 */
196 # define _CUPS_DEPRECATED __attribute__ ((deprecated)) _CUPS_PUBLIC
197 # ifdef _CUPS_HAS_DEPRECATED_WITH_MESSAGE
198 # define _CUPS_DEPRECATED_MSG(m) __attribute__ ((deprecated(m))) _CUPS_PUBLIC
199 # define _CUPS_DEPRECATED_1_2_MSG(m) __attribute__ ((deprecated(m))) _CUPS_PUBLIC
200 # define _CUPS_DEPRECATED_1_6_MSG(m) __attribute__ ((deprecated(m))) _CUPS_PUBLIC
201 # define _CUPS_DEPRECATED_1_7_MSG(m) __attribute__ ((deprecated(m))) _CUPS_PUBLIC
202 # define _CUPS_DEPRECATED_2_2_MSG(m) __attribute__ ((deprecated(m))) _CUPS_PUBLIC
203 # else
204 # define _CUPS_DEPRECATED_MSG(m) __attribute__ ((deprecated)) _CUPS_PUBLIC
205 # define _CUPS_DEPRECATED_1_2_MSG(m) __attribute__ ((deprecated)) _CUPS_PUBLIC
206 # define _CUPS_DEPRECATED_1_6_MSG(m) __attribute__ ((deprecated)) _CUPS_PUBLIC
207 # define _CUPS_DEPRECATED_1_7_MSG(m) __attribute__ ((deprecated)) _CUPS_PUBLIC
208 # define _CUPS_DEPRECATED_2_2_MSG(m) __attribute__ ((deprecated)) _CUPS_PUBLIC
209 # endif /* _CUPS_HAS_DEPRECATED_WITH_MESSAGE */
210 # endif /* !_CUPS_HAS_DEPRECATED || (_CUPS_SOURCE && !_CUPS_NO_DEPRECATED) */
211
212
213 /*
214 * Define _CUPS_FORMAT macro for printf-style functions...
215 */
216
217 # ifdef _CUPS_HAS_FORMAT
218 # define _CUPS_FORMAT(a,b) __attribute__ ((__format__(__printf__, a,b)))
219 # else
220 # define _CUPS_FORMAT(a,b)
221 # endif /* _CUPS_HAS_FORMAT */
222
223
224 /*
225 * Define _CUPS_INTERNAL_MSG macro for private APIs that have (historical)
226 * public visibility.
227 *
228 * Note: Using the _CUPS_INTERNAL_MSG macro automatically adds _CUPS_PUBLIC.
229 */
230
231 # ifdef _CUPS_SOURCE
232 # define _CUPS_INTERNAL_MSG(m) _CUPS_PUBLIC
233 # elif defined(_CUPS_HAS_UNAVAILABLE_WITH_MESSAGE)
234 # define _CUPS_INTERNAL_MSG(m) __attribute__ ((unavailable(m))) _CUPS_PUBLIC
235 # elif defined(_CUPS_HAS_DEPRECATED_WITH_MESSAGE)
236 # define _CUPS_INTERNAL_MSG(m) __attribute__ ((deprecated(m))) _CUPS_PUBLIC
237 # else
238 # define _CUPS_INTERNAL_MSG(m) __attribute__ ((deprecated)) _CUPS_PUBLIC
239 # endif /* _CUPS_SOURCE */
240
241
242 /*
243 * Define _CUPS_NONNULL macro for functions that don't expect non-null
244 * arguments...
245 */
246
247 # ifdef _CUPS_HAS_NONNULL
248 # define _CUPS_NONNULL(...) __attribute__ ((nonnull(__VA_ARGS__)))
249 # else
250 # define _CUPS_NONNULL(...)
251 # endif /* _CUPS_HAS_FORMAT */
252
253
254 /*
255 * Define _CUPS_NORETURN macro for functions that don't return.
256 */
257
258 # ifdef _CUPS_HAS_NORETURN
259 # define _CUPS_NORETURN __attribute__ ((noreturn))
260 # else
261 # define _CUPS_NORETURN
262 # endif /* _CUPS_HAS_NORETURN */
263
264
265 #endif /* !_CUPS_VERSIONING_H_ */