• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2017 The Abseil Authors.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      https://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 // -----------------------------------------------------------------------------
17 // File: config.h
18 // -----------------------------------------------------------------------------
19 //
20 // This header file defines a set of macros for checking the presence of
21 // important compiler and platform features. Such macros can be used to
22 // produce portable code by parameterizing compilation based on the presence or
23 // lack of a given feature.
24 //
25 // We define a "feature" as some interface we wish to program to: for example,
26 // a library function or system call. A value of `1` indicates support for
27 // that feature; any other value indicates the feature support is undefined.
28 //
29 // Example:
30 //
31 // Suppose a programmer wants to write a program that uses the 'mmap()' system
32 // call. The Abseil macro for that feature (`ABSL_HAVE_MMAP`) allows you to
33 // selectively include the `mmap.h` header and bracket code using that feature
34 // in the macro:
35 //
36 //   #include "absl/base/config.h"
37 //
38 //   #ifdef ABSL_HAVE_MMAP
39 //   #include "sys/mman.h"
40 //   #endif  //ABSL_HAVE_MMAP
41 //
42 //   ...
43 //   #ifdef ABSL_HAVE_MMAP
44 //   void *ptr = mmap(...);
45 //   ...
46 //   #endif  // ABSL_HAVE_MMAP
47 
48 #ifndef ABSL_BASE_CONFIG_H_
49 #define ABSL_BASE_CONFIG_H_
50 
51 // Included for the __GLIBC__ macro (or similar macros on other systems).
52 #include <limits.h>
53 
54 #ifdef __cplusplus
55 // Included for __GLIBCXX__, _LIBCPP_VERSION
56 #include <cstddef>
57 #endif  // __cplusplus
58 
59 #if defined(__APPLE__)
60 // Included for TARGET_OS_IPHONE, __IPHONE_OS_VERSION_MIN_REQUIRED,
61 // __IPHONE_8_0.
62 #include <Availability.h>
63 #include <TargetConditionals.h>
64 #endif
65 
66 #include "absl/base/options.h"
67 #include "absl/base/policy_checks.h"
68 
69 // Abseil long-term support (LTS) releases will define
70 // `ABSL_LTS_RELEASE_VERSION` to the integer representing the date string of the
71 // LTS release version, and will define `ABSL_LTS_RELEASE_PATCH_LEVEL` to the
72 // integer representing the patch-level for that release.
73 //
74 // For example, for LTS release version "20300401.2", this would give us
75 // ABSL_LTS_RELEASE_VERSION == 20300401 && ABSL_LTS_RELEASE_PATCH_LEVEL == 2
76 //
77 // These symbols will not be defined in non-LTS code.
78 //
79 // Abseil recommends that clients live-at-head. Therefore, if you are using
80 // these symbols to assert a minimum version requirement, we recommend you do it
81 // as
82 //
83 // #if defined(ABSL_LTS_RELEASE_VERSION) && ABSL_LTS_RELEASE_VERSION < 20300401
84 // #error Project foo requires Abseil LTS version >= 20300401
85 // #endif
86 //
87 // The `defined(ABSL_LTS_RELEASE_VERSION)` part of the check excludes
88 // live-at-head clients from the minimum version assertion.
89 //
90 // See https://abseil.io/about/releases for more information on Abseil release
91 // management.
92 //
93 // LTS releases can be obtained from
94 // https://github.com/abseil/abseil-cpp/releases.
95 #define ABSL_LTS_RELEASE_VERSION 20211102
96 #define ABSL_LTS_RELEASE_PATCH_LEVEL 0
97 
98 // Helper macro to convert a CPP variable to a string literal.
99 #define ABSL_INTERNAL_DO_TOKEN_STR(x) #x
100 #define ABSL_INTERNAL_TOKEN_STR(x) ABSL_INTERNAL_DO_TOKEN_STR(x)
101 
102 // -----------------------------------------------------------------------------
103 // Abseil namespace annotations
104 // -----------------------------------------------------------------------------
105 
106 // ABSL_NAMESPACE_BEGIN/ABSL_NAMESPACE_END
107 //
108 // An annotation placed at the beginning/end of each `namespace absl` scope.
109 // This is used to inject an inline namespace.
110 //
111 // The proper way to write Abseil code in the `absl` namespace is:
112 //
113 // namespace absl {
114 // ABSL_NAMESPACE_BEGIN
115 //
116 // void Foo();  // absl::Foo().
117 //
118 // ABSL_NAMESPACE_END
119 // }  // namespace absl
120 //
121 // Users of Abseil should not use these macros, because users of Abseil should
122 // not write `namespace absl {` in their own code for any reason.  (Abseil does
123 // not support forward declarations of its own types, nor does it support
124 // user-provided specialization of Abseil templates.  Code that violates these
125 // rules may be broken without warning.)
126 #if !defined(ABSL_OPTION_USE_INLINE_NAMESPACE) || \
127     !defined(ABSL_OPTION_INLINE_NAMESPACE_NAME)
128 #error options.h is misconfigured.
129 #endif
130 
131 // Check that ABSL_OPTION_INLINE_NAMESPACE_NAME is neither "head" nor ""
132 #if defined(__cplusplus) && ABSL_OPTION_USE_INLINE_NAMESPACE == 1
133 
134 #define ABSL_INTERNAL_INLINE_NAMESPACE_STR \
135   ABSL_INTERNAL_TOKEN_STR(ABSL_OPTION_INLINE_NAMESPACE_NAME)
136 
137 static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != '\0',
138               "options.h misconfigured: ABSL_OPTION_INLINE_NAMESPACE_NAME must "
139               "not be empty.");
140 static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
141                   ABSL_INTERNAL_INLINE_NAMESPACE_STR[1] != 'e' ||
142                   ABSL_INTERNAL_INLINE_NAMESPACE_STR[2] != 'a' ||
143                   ABSL_INTERNAL_INLINE_NAMESPACE_STR[3] != 'd' ||
144                   ABSL_INTERNAL_INLINE_NAMESPACE_STR[4] != '\0',
145               "options.h misconfigured: ABSL_OPTION_INLINE_NAMESPACE_NAME must "
146               "be changed to a new, unique identifier name.");
147 
148 #endif
149 
150 #if ABSL_OPTION_USE_INLINE_NAMESPACE == 0
151 #define ABSL_NAMESPACE_BEGIN
152 #define ABSL_NAMESPACE_END
153 #define ABSL_INTERNAL_C_SYMBOL(x) x
154 #elif ABSL_OPTION_USE_INLINE_NAMESPACE == 1
155 #define ABSL_NAMESPACE_BEGIN \
156   inline namespace ABSL_OPTION_INLINE_NAMESPACE_NAME {
157 #define ABSL_NAMESPACE_END }
158 #define ABSL_INTERNAL_C_SYMBOL_HELPER_2(x, v) x##_##v
159 #define ABSL_INTERNAL_C_SYMBOL_HELPER_1(x, v) \
160   ABSL_INTERNAL_C_SYMBOL_HELPER_2(x, v)
161 #define ABSL_INTERNAL_C_SYMBOL(x) \
162   ABSL_INTERNAL_C_SYMBOL_HELPER_1(x, ABSL_OPTION_INLINE_NAMESPACE_NAME)
163 #else
164 #error options.h is misconfigured.
165 #endif
166 
167 // -----------------------------------------------------------------------------
168 // Compiler Feature Checks
169 // -----------------------------------------------------------------------------
170 
171 // ABSL_HAVE_BUILTIN()
172 //
173 // Checks whether the compiler supports a Clang Feature Checking Macro, and if
174 // so, checks whether it supports the provided builtin function "x" where x
175 // is one of the functions noted in
176 // https://clang.llvm.org/docs/LanguageExtensions.html
177 //
178 // Note: Use this macro to avoid an extra level of #ifdef __has_builtin check.
179 // http://releases.llvm.org/3.3/tools/clang/docs/LanguageExtensions.html
180 #ifdef __has_builtin
181 #define ABSL_HAVE_BUILTIN(x) __has_builtin(x)
182 #else
183 #define ABSL_HAVE_BUILTIN(x) 0
184 #endif
185 
186 #if defined(__is_identifier)
187 #define ABSL_INTERNAL_HAS_KEYWORD(x) !(__is_identifier(x))
188 #else
189 #define ABSL_INTERNAL_HAS_KEYWORD(x) 0
190 #endif
191 
192 #ifdef __has_feature
193 #define ABSL_HAVE_FEATURE(f) __has_feature(f)
194 #else
195 #define ABSL_HAVE_FEATURE(f) 0
196 #endif
197 
198 // Portable check for GCC minimum version:
199 // https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
200 #if defined(__GNUC__) && defined(__GNUC_MINOR__)
201 #define ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(x, y) \
202   (__GNUC__ > (x) || __GNUC__ == (x) && __GNUC_MINOR__ >= (y))
203 #else
204 #define ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(x, y) 0
205 #endif
206 
207 #if defined(__clang__) && defined(__clang_major__) && defined(__clang_minor__)
208 #define ABSL_INTERNAL_HAVE_MIN_CLANG_VERSION(x, y) \
209   (__clang_major__ > (x) || __clang_major__ == (x) && __clang_minor__ >= (y))
210 #else
211 #define ABSL_INTERNAL_HAVE_MIN_CLANG_VERSION(x, y) 0
212 #endif
213 
214 // ABSL_HAVE_TLS is defined to 1 when __thread should be supported.
215 // We assume __thread is supported on Linux when compiled with Clang or compiled
216 // against libstdc++ with _GLIBCXX_HAVE_TLS defined.
217 #ifdef ABSL_HAVE_TLS
218 #error ABSL_HAVE_TLS cannot be directly set
219 #elif defined(__linux__) && (defined(__clang__) || defined(_GLIBCXX_HAVE_TLS))
220 #define ABSL_HAVE_TLS 1
221 #endif
222 
223 // ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE
224 //
225 // Checks whether `std::is_trivially_destructible<T>` is supported.
226 //
227 // Notes: All supported compilers using libc++ support this feature, as does
228 // gcc >= 4.8.1 using libstdc++, and Visual Studio.
229 #ifdef ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE
230 #error ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE cannot be directly set
231 #elif defined(_LIBCPP_VERSION) || defined(_MSC_VER) || \
232     (!defined(__clang__) && defined(__GLIBCXX__) &&    \
233      ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(4, 8))
234 #define ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE 1
235 #endif
236 
237 // ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE
238 //
239 // Checks whether `std::is_trivially_default_constructible<T>` and
240 // `std::is_trivially_copy_constructible<T>` are supported.
241 
242 // ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE
243 //
244 // Checks whether `std::is_trivially_copy_assignable<T>` is supported.
245 
246 // Notes: Clang with libc++ supports these features, as does gcc >= 7.4 with
247 // libstdc++, or gcc >= 8.2 with libc++, and Visual Studio (but not NVCC).
248 #if defined(ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE)
249 #error ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE cannot be directly set
250 #elif defined(ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE)
251 #error ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE cannot directly set
252 #elif (defined(__clang__) && defined(_LIBCPP_VERSION)) ||                    \
253     (!defined(__clang__) &&                                                  \
254      ((ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(7, 4) && defined(__GLIBCXX__)) || \
255       (ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(8, 2) &&                          \
256        defined(_LIBCPP_VERSION)))) ||                                        \
257     (defined(_MSC_VER) && !defined(__NVCC__))
258 #define ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE 1
259 #define ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE 1
260 #endif
261 
262 // ABSL_HAVE_SOURCE_LOCATION_CURRENT
263 //
264 // Indicates whether `absl::SourceLocation::current()` will return useful
265 // information in some contexts.
266 #ifndef ABSL_HAVE_SOURCE_LOCATION_CURRENT
267 #if ABSL_INTERNAL_HAS_KEYWORD(__builtin_LINE) && \
268     ABSL_INTERNAL_HAS_KEYWORD(__builtin_FILE)
269 #define ABSL_HAVE_SOURCE_LOCATION_CURRENT 1
270 #elif ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(5, 0)
271 #define ABSL_HAVE_SOURCE_LOCATION_CURRENT 1
272 #endif
273 #endif
274 
275 // ABSL_HAVE_THREAD_LOCAL
276 //
277 // Checks whether C++11's `thread_local` storage duration specifier is
278 // supported.
279 #ifdef ABSL_HAVE_THREAD_LOCAL
280 #error ABSL_HAVE_THREAD_LOCAL cannot be directly set
281 #elif defined(__APPLE__)
282 // Notes:
283 // * Xcode's clang did not support `thread_local` until version 8, and
284 //   even then not for all iOS < 9.0.
285 // * Xcode 9.3 started disallowing `thread_local` for 32-bit iOS simulator
286 //   targeting iOS 9.x.
287 // * Xcode 10 moves the deployment target check for iOS < 9.0 to link time
288 //   making ABSL_HAVE_FEATURE unreliable there.
289 //
290 #if ABSL_HAVE_FEATURE(cxx_thread_local) && \
291     !(TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_9_0)
292 #define ABSL_HAVE_THREAD_LOCAL 1
293 #endif
294 #else  // !defined(__APPLE__)
295 #define ABSL_HAVE_THREAD_LOCAL 1
296 #endif
297 
298 // There are platforms for which TLS should not be used even though the compiler
299 // makes it seem like it's supported (Android NDK < r12b for example).
300 // This is primarily because of linker problems and toolchain misconfiguration:
301 // Abseil does not intend to support this indefinitely. Currently, the newest
302 // toolchain that we intend to support that requires this behavior is the
303 // r11 NDK - allowing for a 5 year support window on that means this option
304 // is likely to be removed around June of 2021.
305 // TLS isn't supported until NDK r12b per
306 // https://developer.android.com/ndk/downloads/revision_history.html
307 // Since NDK r16, `__NDK_MAJOR__` and `__NDK_MINOR__` are defined in
308 // <android/ndk-version.h>. For NDK < r16, users should define these macros,
309 // e.g. `-D__NDK_MAJOR__=11 -D__NKD_MINOR__=0` for NDK r11.
310 #if defined(__ANDROID__) && defined(__clang__)
311 #if __has_include(<android/ndk-version.h>)
312 #include <android/ndk-version.h>
313 #endif  // __has_include(<android/ndk-version.h>)
314 #if defined(__ANDROID__) && defined(__clang__) && defined(__NDK_MAJOR__) && \
315     defined(__NDK_MINOR__) &&                                               \
316     ((__NDK_MAJOR__ < 12) || ((__NDK_MAJOR__ == 12) && (__NDK_MINOR__ < 1)))
317 #undef ABSL_HAVE_TLS
318 #undef ABSL_HAVE_THREAD_LOCAL
319 #endif
320 #endif  // defined(__ANDROID__) && defined(__clang__)
321 
322 // ABSL_HAVE_INTRINSIC_INT128
323 //
324 // Checks whether the __int128 compiler extension for a 128-bit integral type is
325 // supported.
326 //
327 // Note: __SIZEOF_INT128__ is defined by Clang and GCC when __int128 is
328 // supported, but we avoid using it in certain cases:
329 // * On Clang:
330 //   * Building using Clang for Windows, where the Clang runtime library has
331 //     128-bit support only on LP64 architectures, but Windows is LLP64.
332 // * On Nvidia's nvcc:
333 //   * nvcc also defines __GNUC__ and __SIZEOF_INT128__, but not all versions
334 //     actually support __int128.
335 #ifdef ABSL_HAVE_INTRINSIC_INT128
336 #error ABSL_HAVE_INTRINSIC_INT128 cannot be directly set
337 #elif defined(__SIZEOF_INT128__)
338 #if (defined(__clang__) && !defined(_WIN32)) || \
339     (defined(__CUDACC__) && __CUDACC_VER_MAJOR__ >= 9) ||                \
340     (defined(__GNUC__) && !defined(__clang__) && !defined(__CUDACC__))
341 #define ABSL_HAVE_INTRINSIC_INT128 1
342 #elif defined(__CUDACC__)
343 // __CUDACC_VER__ is a full version number before CUDA 9, and is defined to a
344 // string explaining that it has been removed starting with CUDA 9. We use
345 // nested #ifs because there is no short-circuiting in the preprocessor.
346 // NOTE: `__CUDACC__` could be undefined while `__CUDACC_VER__` is defined.
347 #if __CUDACC_VER__ >= 70000
348 #define ABSL_HAVE_INTRINSIC_INT128 1
349 #endif  // __CUDACC_VER__ >= 70000
350 #endif  // defined(__CUDACC__)
351 #endif  // ABSL_HAVE_INTRINSIC_INT128
352 
353 // ABSL_HAVE_EXCEPTIONS
354 //
355 // Checks whether the compiler both supports and enables exceptions. Many
356 // compilers support a "no exceptions" mode that disables exceptions.
357 //
358 // Generally, when ABSL_HAVE_EXCEPTIONS is not defined:
359 //
360 // * Code using `throw` and `try` may not compile.
361 // * The `noexcept` specifier will still compile and behave as normal.
362 // * The `noexcept` operator may still return `false`.
363 //
364 // For further details, consult the compiler's documentation.
365 #ifdef ABSL_HAVE_EXCEPTIONS
366 #error ABSL_HAVE_EXCEPTIONS cannot be directly set.
367 #elif ABSL_INTERNAL_HAVE_MIN_CLANG_VERSION(3, 6)
368 // Clang >= 3.6
369 #if ABSL_HAVE_FEATURE(cxx_exceptions)
370 #define ABSL_HAVE_EXCEPTIONS 1
371 #endif  // ABSL_HAVE_FEATURE(cxx_exceptions)
372 #elif defined(__clang__)
373 // Clang < 3.6
374 // http://releases.llvm.org/3.6.0/tools/clang/docs/ReleaseNotes.html#the-exceptions-macro
375 #if defined(__EXCEPTIONS) && ABSL_HAVE_FEATURE(cxx_exceptions)
376 #define ABSL_HAVE_EXCEPTIONS 1
377 #endif  // defined(__EXCEPTIONS) && ABSL_HAVE_FEATURE(cxx_exceptions)
378 // Handle remaining special cases and default to exceptions being supported.
379 #elif !(defined(__GNUC__) && (__GNUC__ < 5) && !defined(__EXCEPTIONS)) && \
380     !(ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(5, 0) &&                        \
381       !defined(__cpp_exceptions)) &&                                      \
382     !(defined(_MSC_VER) && !defined(_CPPUNWIND))
383 #define ABSL_HAVE_EXCEPTIONS 1
384 #endif
385 
386 // -----------------------------------------------------------------------------
387 // Platform Feature Checks
388 // -----------------------------------------------------------------------------
389 
390 // Currently supported operating systems and associated preprocessor
391 // symbols:
392 //
393 //   Linux and Linux-derived           __linux__
394 //   Android                           __ANDROID__ (implies __linux__)
395 //   Linux (non-Android)               __linux__ && !__ANDROID__
396 //   Darwin (macOS and iOS)            __APPLE__
397 //   Akaros (http://akaros.org)        __ros__
398 //   Windows                           _WIN32
399 //   NaCL                              __native_client__
400 //   AsmJS                             __asmjs__
401 //   WebAssembly                       __wasm__
402 //   Fuchsia                           __Fuchsia__
403 //
404 // Note that since Android defines both __ANDROID__ and __linux__, one
405 // may probe for either Linux or Android by simply testing for __linux__.
406 
407 // ABSL_HAVE_MMAP
408 //
409 // Checks whether the platform has an mmap(2) implementation as defined in
410 // POSIX.1-2001.
411 #ifdef ABSL_HAVE_MMAP
412 #error ABSL_HAVE_MMAP cannot be directly set
413 #elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
414     defined(_AIX) || defined(__ros__) || defined(__native_client__) ||    \
415     defined(__asmjs__) || defined(__wasm__) || defined(__Fuchsia__) ||    \
416     defined(__sun) || defined(__ASYLO__) || defined(__myriad2__) ||       \
417     defined(__HAIKU__)
418 #define ABSL_HAVE_MMAP 1
419 #endif
420 
421 // ABSL_HAVE_PTHREAD_GETSCHEDPARAM
422 //
423 // Checks whether the platform implements the pthread_(get|set)schedparam(3)
424 // functions as defined in POSIX.1-2001.
425 #ifdef ABSL_HAVE_PTHREAD_GETSCHEDPARAM
426 #error ABSL_HAVE_PTHREAD_GETSCHEDPARAM cannot be directly set
427 #elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
428     defined(_AIX) || defined(__ros__)
429 #define ABSL_HAVE_PTHREAD_GETSCHEDPARAM 1
430 #endif
431 
432 // ABSL_HAVE_SCHED_GETCPU
433 //
434 // Checks whether sched_getcpu is available.
435 #ifdef ABSL_HAVE_SCHED_GETCPU
436 #error ABSL_HAVE_SCHED_GETCPU cannot be directly set
437 #elif defined(__linux__)
438 #define ABSL_HAVE_SCHED_GETCPU 1
439 #endif
440 
441 // ABSL_HAVE_SCHED_YIELD
442 //
443 // Checks whether the platform implements sched_yield(2) as defined in
444 // POSIX.1-2001.
445 #ifdef ABSL_HAVE_SCHED_YIELD
446 #error ABSL_HAVE_SCHED_YIELD cannot be directly set
447 #elif defined(__linux__) || defined(__ros__) || defined(__native_client__)
448 #define ABSL_HAVE_SCHED_YIELD 1
449 #endif
450 
451 // ABSL_HAVE_SEMAPHORE_H
452 //
453 // Checks whether the platform supports the <semaphore.h> header and sem_init(3)
454 // family of functions as standardized in POSIX.1-2001.
455 //
456 // Note: While Apple provides <semaphore.h> for both iOS and macOS, it is
457 // explicitly deprecated and will cause build failures if enabled for those
458 // platforms.  We side-step the issue by not defining it here for Apple
459 // platforms.
460 #ifdef ABSL_HAVE_SEMAPHORE_H
461 #error ABSL_HAVE_SEMAPHORE_H cannot be directly set
462 #elif defined(__linux__) || defined(__ros__)
463 #define ABSL_HAVE_SEMAPHORE_H 1
464 #endif
465 
466 // ABSL_HAVE_ALARM
467 //
468 // Checks whether the platform supports the <signal.h> header and alarm(2)
469 // function as standardized in POSIX.1-2001.
470 #ifdef ABSL_HAVE_ALARM
471 #error ABSL_HAVE_ALARM cannot be directly set
472 #elif defined(__GOOGLE_GRTE_VERSION__)
473 // feature tests for Google's GRTE
474 #define ABSL_HAVE_ALARM 1
475 #elif defined(__GLIBC__)
476 // feature test for glibc
477 #define ABSL_HAVE_ALARM 1
478 #elif defined(_MSC_VER)
479 // feature tests for Microsoft's library
480 #elif defined(__MINGW32__)
481 // mingw32 doesn't provide alarm(2):
482 // https://osdn.net/projects/mingw/scm/git/mingw-org-wsl/blobs/5.2-trunk/mingwrt/include/unistd.h
483 // mingw-w64 provides a no-op implementation:
484 // https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/mingw-w64-crt/misc/alarm.c
485 #elif defined(__EMSCRIPTEN__)
486 // emscripten doesn't support signals
487 #elif defined(__Fuchsia__)
488 // Signals don't exist on fuchsia.
489 #elif defined(__native_client__)
490 #else
491 // other standard libraries
492 #define ABSL_HAVE_ALARM 1
493 #endif
494 
495 // ABSL_IS_LITTLE_ENDIAN
496 // ABSL_IS_BIG_ENDIAN
497 //
498 // Checks the endianness of the platform.
499 //
500 // Notes: uses the built in endian macros provided by GCC (since 4.6) and
501 // Clang (since 3.2); see
502 // https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html.
503 // Otherwise, if _WIN32, assume little endian. Otherwise, bail with an error.
504 #if defined(ABSL_IS_BIG_ENDIAN)
505 #error "ABSL_IS_BIG_ENDIAN cannot be directly set."
506 #endif
507 #if defined(ABSL_IS_LITTLE_ENDIAN)
508 #error "ABSL_IS_LITTLE_ENDIAN cannot be directly set."
509 #endif
510 
511 #if (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
512      __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
513 #define ABSL_IS_LITTLE_ENDIAN 1
514 #elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \
515     __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
516 #define ABSL_IS_BIG_ENDIAN 1
517 #elif defined(_WIN32)
518 #define ABSL_IS_LITTLE_ENDIAN 1
519 #else
520 #error "absl endian detection needs to be set up for your compiler"
521 #endif
522 
523 // macOS 10.13 and iOS 10.11 don't let you use <any>, <optional>, or <variant>
524 // even though the headers exist and are publicly noted to work.  See
525 // https://github.com/abseil/abseil-cpp/issues/207 and
526 // https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes
527 // libc++ spells out the availability requirements in the file
528 // llvm-project/libcxx/include/__config via the #define
529 // _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS.
530 #if defined(__APPLE__) && defined(_LIBCPP_VERSION) && \
531   ((defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \
532    __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101400) || \
533   (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && \
534    __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 120000) || \
535   (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && \
536    __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 50000) || \
537   (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && \
538    __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 120000))
539 #define ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE 1
540 #else
541 #define ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE 0
542 #endif
543 
544 // ABSL_HAVE_STD_ANY
545 //
546 // Checks whether C++17 std::any is available by checking whether <any> exists.
547 #ifdef ABSL_HAVE_STD_ANY
548 #error "ABSL_HAVE_STD_ANY cannot be directly set."
549 #endif
550 
551 #ifdef __has_include
552 #if __has_include(<any>) && defined(__cplusplus) && __cplusplus >= 201703L && \
553     !ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE
554 #define ABSL_HAVE_STD_ANY 1
555 #endif
556 #endif
557 
558 // ABSL_HAVE_STD_OPTIONAL
559 //
560 // Checks whether C++17 std::optional is available.
561 #ifdef ABSL_HAVE_STD_OPTIONAL
562 #error "ABSL_HAVE_STD_OPTIONAL cannot be directly set."
563 #endif
564 
565 #ifdef __has_include
566 #if __has_include(<optional>) && defined(__cplusplus) && \
567     __cplusplus >= 201703L && !ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE
568 #define ABSL_HAVE_STD_OPTIONAL 1
569 #endif
570 #endif
571 
572 // ABSL_HAVE_STD_VARIANT
573 //
574 // Checks whether C++17 std::variant is available.
575 #ifdef ABSL_HAVE_STD_VARIANT
576 #error "ABSL_HAVE_STD_VARIANT cannot be directly set."
577 #endif
578 
579 #ifdef __has_include
580 #if __has_include(<variant>) && defined(__cplusplus) && \
581     __cplusplus >= 201703L && !ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE
582 #define ABSL_HAVE_STD_VARIANT 1
583 #endif
584 #endif
585 
586 // ABSL_HAVE_STD_STRING_VIEW
587 //
588 // Checks whether C++17 std::string_view is available.
589 #ifdef ABSL_HAVE_STD_STRING_VIEW
590 #error "ABSL_HAVE_STD_STRING_VIEW cannot be directly set."
591 #endif
592 
593 #ifdef __has_include
594 #if __has_include(<string_view>) && defined(__cplusplus) && \
595     __cplusplus >= 201703L
596 #define ABSL_HAVE_STD_STRING_VIEW 1
597 #endif
598 #endif
599 
600 // For MSVC, `__has_include` is supported in VS 2017 15.3, which is later than
601 // the support for <optional>, <any>, <string_view>, <variant>. So we use
602 // _MSC_VER to check whether we have VS 2017 RTM (when <optional>, <any>,
603 // <string_view>, <variant> is implemented) or higher. Also, `__cplusplus` is
604 // not correctly set by MSVC, so we use `_MSVC_LANG` to check the language
605 // version.
606 // TODO(zhangxy): fix tests before enabling aliasing for `std::any`.
607 #if defined(_MSC_VER) && _MSC_VER >= 1910 &&         \
608     ((defined(_MSVC_LANG) && _MSVC_LANG > 201402) || \
609      (defined(__cplusplus) && __cplusplus > 201402))
610 // #define ABSL_HAVE_STD_ANY 1
611 #define ABSL_HAVE_STD_OPTIONAL 1
612 #define ABSL_HAVE_STD_VARIANT 1
613 #define ABSL_HAVE_STD_STRING_VIEW 1
614 #endif
615 
616 // ABSL_USES_STD_ANY
617 //
618 // Indicates whether absl::any is an alias for std::any.
619 #if !defined(ABSL_OPTION_USE_STD_ANY)
620 #error options.h is misconfigured.
621 #elif ABSL_OPTION_USE_STD_ANY == 0 || \
622     (ABSL_OPTION_USE_STD_ANY == 2 && !defined(ABSL_HAVE_STD_ANY))
623 #undef ABSL_USES_STD_ANY
624 #elif ABSL_OPTION_USE_STD_ANY == 1 || \
625     (ABSL_OPTION_USE_STD_ANY == 2 && defined(ABSL_HAVE_STD_ANY))
626 #define ABSL_USES_STD_ANY 1
627 #else
628 #error options.h is misconfigured.
629 #endif
630 
631 // ABSL_USES_STD_OPTIONAL
632 //
633 // Indicates whether absl::optional is an alias for std::optional.
634 #if !defined(ABSL_OPTION_USE_STD_OPTIONAL)
635 #error options.h is misconfigured.
636 #elif ABSL_OPTION_USE_STD_OPTIONAL == 0 || \
637     (ABSL_OPTION_USE_STD_OPTIONAL == 2 && !defined(ABSL_HAVE_STD_OPTIONAL))
638 #undef ABSL_USES_STD_OPTIONAL
639 #elif ABSL_OPTION_USE_STD_OPTIONAL == 1 || \
640     (ABSL_OPTION_USE_STD_OPTIONAL == 2 && defined(ABSL_HAVE_STD_OPTIONAL))
641 #define ABSL_USES_STD_OPTIONAL 1
642 #else
643 #error options.h is misconfigured.
644 #endif
645 
646 // ABSL_USES_STD_VARIANT
647 //
648 // Indicates whether absl::variant is an alias for std::variant.
649 #if !defined(ABSL_OPTION_USE_STD_VARIANT)
650 #error options.h is misconfigured.
651 #elif ABSL_OPTION_USE_STD_VARIANT == 0 || \
652     (ABSL_OPTION_USE_STD_VARIANT == 2 && !defined(ABSL_HAVE_STD_VARIANT))
653 #undef ABSL_USES_STD_VARIANT
654 #elif ABSL_OPTION_USE_STD_VARIANT == 1 || \
655     (ABSL_OPTION_USE_STD_VARIANT == 2 && defined(ABSL_HAVE_STD_VARIANT))
656 #define ABSL_USES_STD_VARIANT 1
657 #else
658 #error options.h is misconfigured.
659 #endif
660 
661 // ABSL_USES_STD_STRING_VIEW
662 //
663 // Indicates whether absl::string_view is an alias for std::string_view.
664 #if !defined(ABSL_OPTION_USE_STD_STRING_VIEW)
665 #error options.h is misconfigured.
666 #elif ABSL_OPTION_USE_STD_STRING_VIEW == 0 || \
667     (ABSL_OPTION_USE_STD_STRING_VIEW == 2 &&  \
668      !defined(ABSL_HAVE_STD_STRING_VIEW))
669 #undef ABSL_USES_STD_STRING_VIEW
670 #elif ABSL_OPTION_USE_STD_STRING_VIEW == 1 || \
671     (ABSL_OPTION_USE_STD_STRING_VIEW == 2 &&  \
672      defined(ABSL_HAVE_STD_STRING_VIEW))
673 #define ABSL_USES_STD_STRING_VIEW 1
674 #else
675 #error options.h is misconfigured.
676 #endif
677 
678 // In debug mode, MSVC 2017's std::variant throws a EXCEPTION_ACCESS_VIOLATION
679 // SEH exception from emplace for variant<SomeStruct> when constructing the
680 // struct can throw. This defeats some of variant_test and
681 // variant_exception_safety_test.
682 #if defined(_MSC_VER) && _MSC_VER >= 1700 && defined(_DEBUG)
683 #define ABSL_INTERNAL_MSVC_2017_DBG_MODE
684 #endif
685 
686 // ABSL_INTERNAL_MANGLED_NS
687 // ABSL_INTERNAL_MANGLED_BACKREFERENCE
688 //
689 // Internal macros for building up mangled names in our internal fork of CCTZ.
690 // This implementation detail is only needed and provided for the MSVC build.
691 //
692 // These macros both expand to string literals.  ABSL_INTERNAL_MANGLED_NS is
693 // the mangled spelling of the `absl` namespace, and
694 // ABSL_INTERNAL_MANGLED_BACKREFERENCE is a back-reference integer representing
695 // the proper count to skip past the CCTZ fork namespace names.  (This number
696 // is one larger when there is an inline namespace name to skip.)
697 #if defined(_MSC_VER)
698 #if ABSL_OPTION_USE_INLINE_NAMESPACE == 0
699 #define ABSL_INTERNAL_MANGLED_NS "absl"
700 #define ABSL_INTERNAL_MANGLED_BACKREFERENCE "5"
701 #else
702 #define ABSL_INTERNAL_MANGLED_NS \
703   ABSL_INTERNAL_TOKEN_STR(ABSL_OPTION_INLINE_NAMESPACE_NAME) "@absl"
704 #define ABSL_INTERNAL_MANGLED_BACKREFERENCE "6"
705 #endif
706 #endif
707 
708 #undef ABSL_INTERNAL_HAS_KEYWORD
709 
710 // ABSL_DLL
711 //
712 // When building Abseil as a DLL, this macro expands to `__declspec(dllexport)`
713 // so we can annotate symbols appropriately as being exported. When used in
714 // headers consuming a DLL, this macro expands to `__declspec(dllimport)` so
715 // that consumers know the symbol is defined inside the DLL. In all other cases,
716 // the macro expands to nothing.
717 #if defined(_MSC_VER)
718 #if defined(ABSL_BUILD_DLL)
719 #define ABSL_DLL __declspec(dllexport)
720 #elif defined(ABSL_CONSUME_DLL)
721 #define ABSL_DLL __declspec(dllimport)
722 #else
723 #define ABSL_DLL
724 #endif
725 #else
726 #define ABSL_DLL
727 #endif  // defined(_MSC_VER)
728 
729 // ABSL_HAVE_MEMORY_SANITIZER
730 //
731 // MemorySanitizer (MSan) is a detector of uninitialized reads. It consists of
732 // a compiler instrumentation module and a run-time library.
733 #ifdef ABSL_HAVE_MEMORY_SANITIZER
734 #error "ABSL_HAVE_MEMORY_SANITIZER cannot be directly set."
735 #elif defined(__SANITIZE_MEMORY__)
736 #define ABSL_HAVE_MEMORY_SANITIZER 1
737 #elif !defined(__native_client__) && ABSL_HAVE_FEATURE(memory_sanitizer)
738 #define ABSL_HAVE_MEMORY_SANITIZER 1
739 #endif
740 
741 // ABSL_HAVE_THREAD_SANITIZER
742 //
743 // ThreadSanitizer (TSan) is a fast data race detector.
744 #ifdef ABSL_HAVE_THREAD_SANITIZER
745 #error "ABSL_HAVE_THREAD_SANITIZER cannot be directly set."
746 #elif defined(__SANITIZE_THREAD__)
747 #define ABSL_HAVE_THREAD_SANITIZER 1
748 #elif ABSL_HAVE_FEATURE(thread_sanitizer)
749 #define ABSL_HAVE_THREAD_SANITIZER 1
750 #endif
751 
752 // ABSL_HAVE_ADDRESS_SANITIZER
753 //
754 // AddressSanitizer (ASan) is a fast memory error detector.
755 #ifdef ABSL_HAVE_ADDRESS_SANITIZER
756 #error "ABSL_HAVE_ADDRESS_SANITIZER cannot be directly set."
757 #elif defined(__SANITIZE_ADDRESS__)
758 #define ABSL_HAVE_ADDRESS_SANITIZER 1
759 #elif ABSL_HAVE_FEATURE(address_sanitizer)
760 #define ABSL_HAVE_ADDRESS_SANITIZER 1
761 #endif
762 
763 // ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION
764 //
765 // Class template argument deduction is a language feature added in C++17.
766 #ifdef ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION
767 #error "ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION cannot be directly set."
768 #elif defined(__cpp_deduction_guides)
769 #define ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION 1
770 #endif
771 
772 #endif  // ABSL_BASE_CONFIG_H_
773