config.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  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 (`OTABSL_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 OTABSL_HAVE_MMAP
  39. // #include "sys/mman.h"
  40. // #endif //OTABSL_HAVE_MMAP
  41. //
  42. // ...
  43. // #ifdef OTABSL_HAVE_MMAP
  44. // void *ptr = mmap(...);
  45. // ...
  46. // #endif // OTABSL_HAVE_MMAP
  47. #ifndef OTABSL_BASE_CONFIG_H_
  48. #define OTABSL_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 "options.h"
  62. #include "policy_checks.h"
  63. // Helper macro to convert a CPP variable to a string literal.
  64. #define OTABSL_INTERNAL_DO_TOKEN_STR(x) #x
  65. #define OTABSL_INTERNAL_TOKEN_STR(x) OTABSL_INTERNAL_DO_TOKEN_STR(x)
  66. // -----------------------------------------------------------------------------
  67. // Abseil namespace annotations
  68. // -----------------------------------------------------------------------------
  69. // OTABSL_NAMESPACE_BEGIN/OTABSL_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. // OTABSL_NAMESPACE_BEGIN
  78. //
  79. // void Foo(); // absl::OTABSL_OPTION_NAMESPACE_NAME::Foo().
  80. //
  81. // OTABSL_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(OTABSL_OPTION_NAMESPACE_NAME)
  90. #error options.h is misconfigured.
  91. #endif
  92. // Check that OTABSL_OPTION_NAMESPACE_NAME is neither "head" nor ""
  93. #if defined(__cplusplus)
  94. #define OTABSL_INTERNAL_INLINE_NAMESPACE_STR \
  95. OTABSL_INTERNAL_TOKEN_STR(OTABSL_OPTION_NAMESPACE_NAME)
  96. static_assert(OTABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != '\0',
  97. "options.h misconfigured: OTABSL_OPTION_NAMESPACE_NAME must "
  98. "not be empty.");
  99. static_assert(OTABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
  100. OTABSL_INTERNAL_INLINE_NAMESPACE_STR[1] != 'e' ||
  101. OTABSL_INTERNAL_INLINE_NAMESPACE_STR[2] != 'a' ||
  102. OTABSL_INTERNAL_INLINE_NAMESPACE_STR[3] != 'd' ||
  103. OTABSL_INTERNAL_INLINE_NAMESPACE_STR[4] != '\0',
  104. "options.h misconfigured: OTABSL_OPTION_NAMESPACE_NAME must "
  105. "be changed to a new, unique identifier name.");
  106. #endif
  107. #define OTABSL_NAMESPACE_BEGIN namespace OTABSL_OPTION_NAMESPACE_NAME {
  108. #define OTABSL_NAMESPACE_END }
  109. // -----------------------------------------------------------------------------
  110. // Compiler Feature Checks
  111. // -----------------------------------------------------------------------------
  112. // OTABSL_HAVE_BUILTIN()
  113. //
  114. // Checks whether the compiler supports a Clang Feature Checking Macro, and if
  115. // so, checks whether it supports the provided builtin function "x" where x
  116. // is one of the functions noted in
  117. // https://clang.llvm.org/docs/LanguageExtensions.html
  118. //
  119. // Note: Use this macro to avoid an extra level of #ifdef __has_builtin check.
  120. // http://releases.llvm.org/3.3/tools/clang/docs/LanguageExtensions.html
  121. #ifdef __has_builtin
  122. #define OTABSL_HAVE_BUILTIN(x) __has_builtin(x)
  123. #else
  124. #define OTABSL_HAVE_BUILTIN(x) 0
  125. #endif
  126. #if defined(__is_identifier)
  127. #define OTABSL_INTERNAL_HAS_KEYWORD(x) !(__is_identifier(x))
  128. #else
  129. #define OTABSL_INTERNAL_HAS_KEYWORD(x) 0
  130. #endif
  131. // OTABSL_HAVE_TLS is defined to 1 when __thread should be supported.
  132. // We assume __thread is supported on Linux when compiled with Clang or compiled
  133. // against libstdc++ with _GLIBCXX_HAVE_TLS defined.
  134. #ifdef OTABSL_HAVE_TLS
  135. #error OTABSL_HAVE_TLS cannot be directly set
  136. #elif defined(__linux__) && (defined(__clang__) || defined(_GLIBCXX_HAVE_TLS))
  137. #define OTABSL_HAVE_TLS 1
  138. #endif
  139. // OTABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE
  140. //
  141. // Checks whether `std::is_trivially_destructible<T>` is supported.
  142. //
  143. // Notes: All supported compilers using libc++ support this feature, as does
  144. // gcc >= 4.8.1 using libstdc++, and Visual Studio.
  145. #ifdef OTABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE
  146. #error OTABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE cannot be directly set
  147. #elif defined(_LIBCPP_VERSION) || \
  148. (defined(__clang__) && __clang_major__ >= 15) || \
  149. (!defined(__clang__) && defined(__GNUC__) && defined(__GLIBCXX__) && \
  150. (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))) || \
  151. defined(_MSC_VER)
  152. #define OTABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE 1
  153. #endif
  154. // OTABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE
  155. //
  156. // Checks whether `std::is_trivially_default_constructible<T>` and
  157. // `std::is_trivially_copy_constructible<T>` are supported.
  158. // OTABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE
  159. //
  160. // Checks whether `std::is_trivially_copy_assignable<T>` is supported.
  161. // Notes: Clang with libc++ supports these features, as does gcc >= 5.1 with
  162. // either libc++ or libstdc++, and Visual Studio (but not NVCC).
  163. #if defined(OTABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE)
  164. #error OTABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE cannot be directly set
  165. #elif defined(OTABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE)
  166. #error OTABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE cannot directly set
  167. #elif (defined(__clang__) && defined(_LIBCPP_VERSION)) || \
  168. (defined(__clang__) && __clang_major__ >= 15) || \
  169. (!defined(__clang__) && defined(__GNUC__) && \
  170. (__GNUC__ > 7 || (__GNUC__ == 7 && __GNUC_MINOR__ >= 4)) && \
  171. (defined(_LIBCPP_VERSION) || defined(__GLIBCXX__))) || \
  172. (defined(_MSC_VER) && !defined(__NVCC__))
  173. #define OTABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE 1
  174. #define OTABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE 1
  175. #endif
  176. // OTABSL_HAVE_STD_IS_TRIVIALLY_COPYABLE
  177. //
  178. // Checks whether `std::is_trivially_copyable<T>` is supported.
  179. //
  180. // Notes: Clang 15+ with libc++ supports these features, GCC hasn't been tested.
  181. #if defined(OTABSL_HAVE_STD_IS_TRIVIALLY_COPYABLE)
  182. #error OTABSL_HAVE_STD_IS_TRIVIALLY_COPYABLE cannot be directly set
  183. #elif defined(__clang__) && (__clang_major__ >= 15)
  184. #define OTABSL_HAVE_STD_IS_TRIVIALLY_COPYABLE 1
  185. #endif
  186. // OTABSL_HAVE_SOURCE_LOCATION_CURRENT
  187. //
  188. // Indicates whether `absl::OTABSL_OPTION_NAMESPACE_NAME::SourceLocation::current()` will return useful
  189. // information in some contexts.
  190. #ifndef OTABSL_HAVE_SOURCE_LOCATION_CURRENT
  191. #if OTABSL_INTERNAL_HAS_KEYWORD(__builtin_LINE) && \
  192. OTABSL_INTERNAL_HAS_KEYWORD(__builtin_FILE)
  193. #define OTABSL_HAVE_SOURCE_LOCATION_CURRENT 1
  194. #endif
  195. #endif
  196. // OTABSL_HAVE_THREAD_LOCAL
  197. //
  198. // Checks whether C++11's `thread_local` storage duration specifier is
  199. // supported.
  200. #ifdef OTABSL_HAVE_THREAD_LOCAL
  201. #error OTABSL_HAVE_THREAD_LOCAL cannot be directly set
  202. #elif defined(__APPLE__)
  203. // Notes:
  204. // * Xcode's clang did not support `thread_local` until version 8, and
  205. // even then not for all iOS < 9.0.
  206. // * Xcode 9.3 started disallowing `thread_local` for 32-bit iOS simulator
  207. // targeting iOS 9.x.
  208. // * Xcode 10 moves the deployment target check for iOS < 9.0 to link time
  209. // making __has_feature unreliable there.
  210. //
  211. // Otherwise, `__has_feature` is only supported by Clang so it has be inside
  212. // `defined(__APPLE__)` check.
  213. #if __has_feature(cxx_thread_local) && \
  214. !(TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_9_0)
  215. #define OTABSL_HAVE_THREAD_LOCAL 1
  216. #endif
  217. #else // !defined(__APPLE__)
  218. #define OTABSL_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 OTABSL_HAVE_TLS
  240. #undef OTABSL_HAVE_THREAD_LOCAL
  241. #endif
  242. #endif // defined(__ANDROID__) && defined(__clang__)
  243. // Emscripten doesn't yet support `thread_local` or `__thread`.
  244. // https://github.com/emscripten-core/emscripten/issues/3502
  245. #if defined(__EMSCRIPTEN__)
  246. #undef OTABSL_HAVE_TLS
  247. #undef OTABSL_HAVE_THREAD_LOCAL
  248. #endif // defined(__EMSCRIPTEN__)
  249. // OTABSL_HAVE_INTRINSIC_INT128
  250. //
  251. // Checks whether the __int128 compiler extension for a 128-bit integral type is
  252. // supported.
  253. //
  254. // Note: __SIZEOF_INT128__ is defined by Clang and GCC when __int128 is
  255. // supported, but we avoid using it in certain cases:
  256. // * On Clang:
  257. // * Building using Clang for Windows, where the Clang runtime library has
  258. // 128-bit support only on LP64 architectures, but Windows is LLP64.
  259. // * On Nvidia's nvcc:
  260. // * nvcc also defines __GNUC__ and __SIZEOF_INT128__, but not all versions
  261. // actually support __int128.
  262. #ifdef OTABSL_HAVE_INTRINSIC_INT128
  263. #error OTABSL_HAVE_INTRINSIC_INT128 cannot be directly set
  264. #elif defined(__SIZEOF_INT128__)
  265. #if (defined(__clang__) && !defined(_WIN32)) || \
  266. (defined(__CUDACC__) && __CUDACC_VER_MAJOR__ >= 9) || \
  267. (defined(__GNUC__) && !defined(__clang__) && !defined(__CUDACC__))
  268. #define OTABSL_HAVE_INTRINSIC_INT128 1
  269. #elif defined(__CUDACC__)
  270. // __CUDACC_VER__ is a full version number before CUDA 9, and is defined to a
  271. // string explaining that it has been removed starting with CUDA 9. We use
  272. // nested #ifs because there is no short-circuiting in the preprocessor.
  273. // NOTE: `__CUDACC__` could be undefined while `__CUDACC_VER__` is defined.
  274. #if __CUDACC_VER__ >= 70000
  275. #define OTABSL_HAVE_INTRINSIC_INT128 1
  276. #endif // __CUDACC_VER__ >= 70000
  277. #endif // defined(__CUDACC__)
  278. #endif // OTABSL_HAVE_INTRINSIC_INT128
  279. // OTABSL_HAVE_EXCEPTIONS
  280. //
  281. // Checks whether the compiler both supports and enables exceptions. Many
  282. // compilers support a "no exceptions" mode that disables exceptions.
  283. //
  284. // Generally, when OTABSL_HAVE_EXCEPTIONS is not defined:
  285. //
  286. // * Code using `throw` and `try` may not compile.
  287. // * The `noexcept` specifier will still compile and behave as normal.
  288. // * The `noexcept` operator may still return `false`.
  289. //
  290. // For further details, consult the compiler's documentation.
  291. #ifdef OTABSL_HAVE_EXCEPTIONS
  292. #error OTABSL_HAVE_EXCEPTIONS cannot be directly set.
  293. #elif defined(__clang__)
  294. #if __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 6)
  295. // Clang >= 3.6
  296. #if __has_feature(cxx_exceptions)
  297. #define OTABSL_HAVE_EXCEPTIONS 1
  298. #endif // __has_feature(cxx_exceptions)
  299. #else
  300. // Clang < 3.6
  301. // http://releases.llvm.org/3.6.0/tools/clang/docs/ReleaseNotes.html#the-exceptions-macro
  302. #if defined(__EXCEPTIONS) && __has_feature(cxx_exceptions)
  303. #define OTABSL_HAVE_EXCEPTIONS 1
  304. #endif // defined(__EXCEPTIONS) && __has_feature(cxx_exceptions)
  305. #endif // __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 6)
  306. // Handle remaining special cases and default to exceptions being supported.
  307. #elif !(defined(__GNUC__) && (__GNUC__ < 5) && !defined(__EXCEPTIONS)) && \
  308. !(defined(__GNUC__) && (__GNUC__ >= 5) && !defined(__cpp_exceptions)) && \
  309. !(defined(_MSC_VER) && !defined(_CPPUNWIND))
  310. #define OTABSL_HAVE_EXCEPTIONS 1
  311. #endif
  312. // -----------------------------------------------------------------------------
  313. // Platform Feature Checks
  314. // -----------------------------------------------------------------------------
  315. // Currently supported operating systems and associated preprocessor
  316. // symbols:
  317. //
  318. // Linux and Linux-derived __linux__
  319. // Android __ANDROID__ (implies __linux__)
  320. // Linux (non-Android) __linux__ && !__ANDROID__
  321. // Darwin (macOS and iOS) __APPLE__
  322. // Akaros (http://akaros.org) __ros__
  323. // Windows _WIN32
  324. // NaCL __native_client__
  325. // AsmJS __asmjs__
  326. // WebAssembly __wasm__
  327. // Fuchsia __Fuchsia__
  328. //
  329. // Note that since Android defines both __ANDROID__ and __linux__, one
  330. // may probe for either Linux or Android by simply testing for __linux__.
  331. // OTABSL_HAVE_MMAP
  332. //
  333. // Checks whether the platform has an mmap(2) implementation as defined in
  334. // POSIX.1-2001.
  335. #ifdef OTABSL_HAVE_MMAP
  336. #error OTABSL_HAVE_MMAP cannot be directly set
  337. #elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
  338. defined(__ros__) || defined(__native_client__) || defined(__asmjs__) || \
  339. defined(__wasm__) || defined(__Fuchsia__) || defined(__sun) || \
  340. defined(__ASYLO__)
  341. #define OTABSL_HAVE_MMAP 1
  342. #endif
  343. // OTABSL_HAVE_PTHREAD_GETSCHEDPARAM
  344. //
  345. // Checks whether the platform implements the pthread_(get|set)schedparam(3)
  346. // functions as defined in POSIX.1-2001.
  347. #ifdef OTABSL_HAVE_PTHREAD_GETSCHEDPARAM
  348. #error OTABSL_HAVE_PTHREAD_GETSCHEDPARAM cannot be directly set
  349. #elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
  350. defined(__ros__)
  351. #define OTABSL_HAVE_PTHREAD_GETSCHEDPARAM 1
  352. #endif
  353. // OTABSL_HAVE_SCHED_YIELD
  354. //
  355. // Checks whether the platform implements sched_yield(2) as defined in
  356. // POSIX.1-2001.
  357. #ifdef OTABSL_HAVE_SCHED_YIELD
  358. #error OTABSL_HAVE_SCHED_YIELD cannot be directly set
  359. #elif defined(__linux__) || defined(__ros__) || defined(__native_client__)
  360. #define OTABSL_HAVE_SCHED_YIELD 1
  361. #endif
  362. // OTABSL_HAVE_SEMAPHORE_H
  363. //
  364. // Checks whether the platform supports the <semaphore.h> header and sem_init(3)
  365. // family of functions as standardized in POSIX.1-2001.
  366. //
  367. // Note: While Apple provides <semaphore.h> for both iOS and macOS, it is
  368. // explicitly deprecated and will cause build failures if enabled for those
  369. // platforms. We side-step the issue by not defining it here for Apple
  370. // platforms.
  371. #ifdef OTABSL_HAVE_SEMAPHORE_H
  372. #error OTABSL_HAVE_SEMAPHORE_H cannot be directly set
  373. #elif defined(__linux__) || defined(__ros__)
  374. #define OTABSL_HAVE_SEMAPHORE_H 1
  375. #endif
  376. // OTABSL_HAVE_ALARM
  377. //
  378. // Checks whether the platform supports the <signal.h> header and alarm(2)
  379. // function as standardized in POSIX.1-2001.
  380. #ifdef OTABSL_HAVE_ALARM
  381. #error OTABSL_HAVE_ALARM cannot be directly set
  382. #elif defined(__GOOGLE_GRTE_VERSION__)
  383. // feature tests for Google's GRTE
  384. #define OTABSL_HAVE_ALARM 1
  385. #elif defined(__GLIBC__)
  386. // feature test for glibc
  387. #define OTABSL_HAVE_ALARM 1
  388. #elif defined(_MSC_VER)
  389. // feature tests for Microsoft's library
  390. #elif defined(__MINGW32__)
  391. // mingw32 doesn't provide alarm(2):
  392. // https://osdn.net/projects/mingw/scm/git/mingw-org-wsl/blobs/5.2-trunk/mingwrt/include/unistd.h
  393. // mingw-w64 provides a no-op implementation:
  394. // https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/mingw-w64-crt/misc/alarm.c
  395. #elif defined(__EMSCRIPTEN__)
  396. // emscripten doesn't support signals
  397. #elif defined(__Fuchsia__)
  398. // Signals don't exist on fuchsia.
  399. #elif defined(__native_client__)
  400. #else
  401. // other standard libraries
  402. #define OTABSL_HAVE_ALARM 1
  403. #endif
  404. // OTABSL_IS_LITTLE_ENDIAN
  405. // OTABSL_IS_BIG_ENDIAN
  406. //
  407. // Checks the endianness of the platform.
  408. //
  409. // Notes: uses the built in endian macros provided by GCC (since 4.6) and
  410. // Clang (since 3.2); see
  411. // https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html.
  412. // Otherwise, if _WIN32, assume little endian. Otherwise, bail with an error.
  413. #if defined(OTABSL_IS_BIG_ENDIAN)
  414. #error "OTABSL_IS_BIG_ENDIAN cannot be directly set."
  415. #endif
  416. #if defined(OTABSL_IS_LITTLE_ENDIAN)
  417. #error "OTABSL_IS_LITTLE_ENDIAN cannot be directly set."
  418. #endif
  419. #if (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
  420. __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
  421. #define OTABSL_IS_LITTLE_ENDIAN 1
  422. #elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \
  423. __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
  424. #define OTABSL_IS_BIG_ENDIAN 1
  425. #elif defined(_WIN32)
  426. #define OTABSL_IS_LITTLE_ENDIAN 1
  427. #else
  428. #error "absl endian detection needs to be set up for your compiler"
  429. #endif
  430. // macOS 10.13 and iOS 10.11 don't let you use <any>, <optional>, or <variant>
  431. // even though the headers exist and are publicly noted to work. See
  432. // https://github.com/abseil/abseil-cpp/issues/207 and
  433. // https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes
  434. // libc++ spells out the availability requirements in the file
  435. // llvm-project/libcxx/include/__config via the #define
  436. // _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS.
  437. #if defined(__APPLE__) && defined(_LIBCPP_VERSION) && \
  438. ((defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \
  439. __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101400) || \
  440. (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && \
  441. __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 120000) || \
  442. (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && \
  443. __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 120000) || \
  444. (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && \
  445. __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 50000))
  446. #define OTABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE 1
  447. #else
  448. #define OTABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE 0
  449. #endif
  450. // OTABSL_HAVE_STD_ANY
  451. //
  452. // Checks whether C++17 std::any is available by checking whether <any> exists.
  453. #ifdef OTABSL_HAVE_STD_ANY
  454. #error "OTABSL_HAVE_STD_ANY cannot be directly set."
  455. #endif
  456. #ifdef __has_include
  457. #if __has_include(<any>) && __cplusplus >= 201703L && \
  458. !OTABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE
  459. #define OTABSL_HAVE_STD_ANY 1
  460. #endif
  461. #endif
  462. // OTABSL_HAVE_STD_OPTIONAL
  463. //
  464. // Checks whether C++17 std::optional is available.
  465. #ifdef OTABSL_HAVE_STD_OPTIONAL
  466. #error "OTABSL_HAVE_STD_OPTIONAL cannot be directly set."
  467. #endif
  468. #ifdef __has_include
  469. #if __has_include(<optional>) && __cplusplus >= 201703L && \
  470. !OTABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE
  471. #define OTABSL_HAVE_STD_OPTIONAL 1
  472. #endif
  473. #endif
  474. // OTABSL_HAVE_STD_VARIANT
  475. //
  476. // Checks whether C++17 std::variant is available.
  477. #ifdef OTABSL_HAVE_STD_VARIANT
  478. #error "OTABSL_HAVE_STD_VARIANT cannot be directly set."
  479. #endif
  480. #ifdef __has_include
  481. #if __has_include(<variant>) && __cplusplus >= 201703L && \
  482. !OTABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE
  483. #define OTABSL_HAVE_STD_VARIANT 1
  484. #endif
  485. #endif
  486. // OTABSL_HAVE_STD_STRING_VIEW
  487. //
  488. // Checks whether C++17 std::string_view is available.
  489. #ifdef OTABSL_HAVE_STD_STRING_VIEW
  490. #error "OTABSL_HAVE_STD_STRING_VIEW cannot be directly set."
  491. #endif
  492. #ifdef __has_include
  493. #if __has_include(<string_view>) && __cplusplus >= 201703L
  494. #define OTABSL_HAVE_STD_STRING_VIEW 1
  495. #endif
  496. #endif
  497. // For MSVC, `__has_include` is supported in VS 2017 15.3, which is later than
  498. // the support for <optional>, <any>, <string_view>, <variant>. So we use
  499. // _MSC_VER to check whether we have VS 2017 RTM (when <optional>, <any>,
  500. // <string_view>, <variant> is implemented) or higher. Also, `__cplusplus` is
  501. // not correctly set by MSVC, so we use `_MSVC_LANG` to check the language
  502. // version.
  503. // TODO(zhangxy): fix tests before enabling aliasing for `std::any`.
  504. #if defined(_MSC_VER) && _MSC_VER >= 1910 && \
  505. ((defined(_MSVC_LANG) && _MSVC_LANG > 201402) || __cplusplus > 201402)
  506. // #define OTABSL_HAVE_STD_ANY 1
  507. #define OTABSL_HAVE_STD_OPTIONAL 1
  508. #define OTABSL_HAVE_STD_VARIANT 1
  509. #define OTABSL_HAVE_STD_STRING_VIEW 1
  510. #endif
  511. // OTABSL_USES_STD_ANY
  512. //
  513. // Indicates whether absl::OTABSL_OPTION_NAMESPACE_NAME::any is an alias for std::any.
  514. #if !defined(OTABSL_OPTION_USE_STD_ANY)
  515. #error options.h is misconfigured.
  516. #elif OTABSL_OPTION_USE_STD_ANY == 0 || \
  517. (OTABSL_OPTION_USE_STD_ANY == 2 && !defined(OTABSL_HAVE_STD_ANY))
  518. #undef OTABSL_USES_STD_ANY
  519. #elif OTABSL_OPTION_USE_STD_ANY == 1 || \
  520. (OTABSL_OPTION_USE_STD_ANY == 2 && defined(OTABSL_HAVE_STD_ANY))
  521. #define OTABSL_USES_STD_ANY 1
  522. #else
  523. #error options.h is misconfigured.
  524. #endif
  525. // OTABSL_USES_STD_OPTIONAL
  526. //
  527. // Indicates whether absl::OTABSL_OPTION_NAMESPACE_NAME::optional is an alias for std::optional.
  528. #if !defined(OTABSL_OPTION_USE_STD_OPTIONAL)
  529. #error options.h is misconfigured.
  530. #elif OTABSL_OPTION_USE_STD_OPTIONAL == 0 || \
  531. (OTABSL_OPTION_USE_STD_OPTIONAL == 2 && !defined(OTABSL_HAVE_STD_OPTIONAL))
  532. #undef OTABSL_USES_STD_OPTIONAL
  533. #elif OTABSL_OPTION_USE_STD_OPTIONAL == 1 || \
  534. (OTABSL_OPTION_USE_STD_OPTIONAL == 2 && defined(OTABSL_HAVE_STD_OPTIONAL))
  535. #define OTABSL_USES_STD_OPTIONAL 1
  536. #else
  537. #error options.h is misconfigured.
  538. #endif
  539. // OTABSL_USES_STD_VARIANT
  540. //
  541. // Indicates whether absl::OTABSL_OPTION_NAMESPACE_NAME::variant is an alias for std::variant.
  542. #if !defined(OTABSL_OPTION_USE_STD_VARIANT)
  543. #error options.h is misconfigured.
  544. #elif OTABSL_OPTION_USE_STD_VARIANT == 0 || \
  545. (OTABSL_OPTION_USE_STD_VARIANT == 2 && !defined(OTABSL_HAVE_STD_VARIANT))
  546. #undef OTABSL_USES_STD_VARIANT
  547. #elif OTABSL_OPTION_USE_STD_VARIANT == 1 || \
  548. (OTABSL_OPTION_USE_STD_VARIANT == 2 && defined(OTABSL_HAVE_STD_VARIANT))
  549. #define OTABSL_USES_STD_VARIANT 1
  550. #else
  551. #error options.h is misconfigured.
  552. #endif
  553. // OTABSL_USES_STD_STRING_VIEW
  554. //
  555. // Indicates whether absl::OTABSL_OPTION_NAMESPACE_NAME::string_view is an alias for std::string_view.
  556. #if !defined(OTABSL_OPTION_USE_STD_STRING_VIEW)
  557. #error options.h is misconfigured.
  558. #elif OTABSL_OPTION_USE_STD_STRING_VIEW == 0 || \
  559. (OTABSL_OPTION_USE_STD_STRING_VIEW == 2 && \
  560. !defined(OTABSL_HAVE_STD_STRING_VIEW))
  561. #undef OTABSL_USES_STD_STRING_VIEW
  562. #elif OTABSL_OPTION_USE_STD_STRING_VIEW == 1 || \
  563. (OTABSL_OPTION_USE_STD_STRING_VIEW == 2 && \
  564. defined(OTABSL_HAVE_STD_STRING_VIEW))
  565. #define OTABSL_USES_STD_STRING_VIEW 1
  566. #else
  567. #error options.h is misconfigured.
  568. #endif
  569. // In debug mode, MSVC 2017's std::variant throws a EXCEPTION_ACCESS_VIOLATION
  570. // SEH exception from emplace for variant<SomeStruct> when constructing the
  571. // struct can throw. This defeats some of variant_test and
  572. // variant_exception_safety_test.
  573. #if defined(_MSC_VER) && _MSC_VER >= 1700 && defined(_DEBUG)
  574. #define OTABSL_INTERNAL_MSVC_2017_DBG_MODE
  575. #endif
  576. // OTABSL_INTERNAL_MANGLED_NS
  577. // OTABSL_INTERNAL_MANGLED_BACKREFERENCE
  578. //
  579. // Internal macros for building up mangled names in our internal fork of CCTZ.
  580. // This implementation detail is only needed and provided for the MSVC build.
  581. //
  582. // These macros both expand to string literals. OTABSL_INTERNAL_MANGLED_NS is
  583. // the mangled spelling of the `absl` namespace, and
  584. // OTABSL_INTERNAL_MANGLED_BACKREFERENCE is a back-reference integer representing
  585. // the proper count to skip past the CCTZ fork namespace names. (This number
  586. // is one larger when there is an inline namespace name to skip.)
  587. #if defined(_MSC_VER)
  588. #define OTABSL_INTERNAL_MANGLED_NS \
  589. OTABSL_INTERNAL_TOKEN_STR(OTABSL_OPTION_NAMESPACE_NAME) "@absl"
  590. #define OTABSL_INTERNAL_MANGLED_BACKREFERENCE "6"
  591. #endif
  592. #undef OTABSL_INTERNAL_HAS_KEYWORD
  593. // OTABSL_DLL
  594. //
  595. // When building Abseil as a DLL, this macro expands to `__declspec(dllexport)`
  596. // so we can annotate symbols appropriately as being exported. When used in
  597. // headers consuming a DLL, this macro expands to `__declspec(dllimport)` so
  598. // that consumers know the symbol is defined inside the DLL. In all other cases,
  599. // the macro expands to nothing.
  600. #if defined(_MSC_VER)
  601. #if defined(OTABSL_BUILD_DLL)
  602. #define OTABSL_DLL __declspec(dllexport)
  603. #elif 1
  604. #define OTABSL_DLL __declspec(dllimport)
  605. #else
  606. #define OTABSL_DLL
  607. #endif
  608. #else
  609. #define OTABSL_DLL
  610. #endif // defined(_MSC_VER)
  611. #endif // OTABSL_BASE_CONFIG_H_