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