config.h 26 KB

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