00001 // 00002 // Copyright 2017 The Abseil Authors. 00003 // 00004 // Licensed under the Apache License, Version 2.0 (the "License"); 00005 // you may not use this file except in compliance with the License. 00006 // You may obtain a copy of the License at 00007 // 00008 // https://www.apache.org/licenses/LICENSE-2.0 00009 // 00010 // Unless required by applicable law or agreed to in writing, software 00011 // distributed under the License is distributed on an "AS IS" BASIS, 00012 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 // See the License for the specific language governing permissions and 00014 // limitations under the License. 00015 // 00016 // ----------------------------------------------------------------------------- 00017 // File: config.h 00018 // ----------------------------------------------------------------------------- 00019 // 00020 // This header file defines a set of macros for checking the presence of 00021 // important compiler and platform features. Such macros can be used to 00022 // produce portable code by parameterizing compilation based on the presence or 00023 // lack of a given feature. 00024 // 00025 // We define a "feature" as some interface we wish to program to: for example, 00026 // a library function or system call. A value of `1` indicates support for 00027 // that feature; any other value indicates the feature support is undefined. 00028 // 00029 // Example: 00030 // 00031 // Suppose a programmer wants to write a program that uses the 'mmap()' system 00032 // call. The Abseil macro for that feature (`ABSL_HAVE_MMAP`) allows you to 00033 // selectively include the `mmap.h` header and bracket code using that feature 00034 // in the macro: 00035 // 00036 // #include "absl/base/config.h" 00037 // 00038 // #ifdef ABSL_HAVE_MMAP 00039 // #include "sys/mman.h" 00040 // #endif //ABSL_HAVE_MMAP 00041 // 00042 // ... 00043 // #ifdef ABSL_HAVE_MMAP 00044 // void *ptr = mmap(...); 00045 // ... 00046 // #endif // ABSL_HAVE_MMAP 00047 00048 #ifndef ABSL_BASE_CONFIG_H_ 00049 #define ABSL_BASE_CONFIG_H_ 00050 00051 // Included for the __GLIBC__ macro (or similar macros on other systems). 00052 #include <limits.h> 00053 00054 #ifdef __cplusplus 00055 // Included for __GLIBCXX__, _LIBCPP_VERSION 00056 #include <cstddef> 00057 #endif // __cplusplus 00058 00059 #if defined(__APPLE__) 00060 // Included for TARGET_OS_IPHONE, __IPHONE_OS_VERSION_MIN_REQUIRED, 00061 // __IPHONE_8_0. 00062 #include <Availability.h> 00063 #include <TargetConditionals.h> 00064 #endif 00065 00066 #include "absl/base/policy_checks.h" 00067 00068 // ----------------------------------------------------------------------------- 00069 // Compiler Feature Checks 00070 // ----------------------------------------------------------------------------- 00071 00072 // ABSL_HAVE_BUILTIN() 00073 // 00074 // Checks whether the compiler supports a Clang Feature Checking Macro, and if 00075 // so, checks whether it supports the provided builtin function "x" where x 00076 // is one of the functions noted in 00077 // https://clang.llvm.org/docs/LanguageExtensions.html 00078 // 00079 // Note: Use this macro to avoid an extra level of #ifdef __has_builtin check. 00080 // http://releases.llvm.org/3.3/tools/clang/docs/LanguageExtensions.html 00081 #ifdef __has_builtin 00082 #define ABSL_HAVE_BUILTIN(x) __has_builtin(x) 00083 #else 00084 #define ABSL_HAVE_BUILTIN(x) 0 00085 #endif 00086 00087 // ABSL_HAVE_TLS is defined to 1 when __thread should be supported. 00088 // We assume __thread is supported on Linux when compiled with Clang or compiled 00089 // against libstdc++ with _GLIBCXX_HAVE_TLS defined. 00090 #ifdef ABSL_HAVE_TLS 00091 #error ABSL_HAVE_TLS cannot be directly set 00092 #elif defined(__linux__) && (defined(__clang__) || defined(_GLIBCXX_HAVE_TLS)) 00093 #define ABSL_HAVE_TLS 1 00094 #endif 00095 00096 // ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE 00097 // 00098 // Checks whether `std::is_trivially_destructible<T>` is supported. 00099 // 00100 // Notes: All supported compilers using libc++ support this feature, as does 00101 // gcc >= 4.8.1 using libstdc++, and Visual Studio. 00102 #ifdef ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE 00103 #error ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE cannot be directly set 00104 #elif defined(_LIBCPP_VERSION) || \ 00105 (!defined(__clang__) && defined(__GNUC__) && defined(__GLIBCXX__) && \ 00106 (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))) || \ 00107 defined(_MSC_VER) 00108 #define ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE 1 00109 #endif 00110 00111 // ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE 00112 // 00113 // Checks whether `std::is_trivially_default_constructible<T>` and 00114 // `std::is_trivially_copy_constructible<T>` are supported. 00115 00116 // ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE 00117 // 00118 // Checks whether `std::is_trivially_copy_assignable<T>` is supported. 00119 00120 // Notes: Clang with libc++ supports these features, as does gcc >= 5.1 with 00121 // either libc++ or libstdc++, and Visual Studio (but not NVCC). 00122 #if defined(ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE) 00123 #error ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE cannot be directly set 00124 #elif defined(ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE) 00125 #error ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE cannot directly set 00126 #elif (defined(__clang__) && defined(_LIBCPP_VERSION)) || \ 00127 (!defined(__clang__) && defined(__GNUC__) && \ 00128 (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && \ 00129 (defined(_LIBCPP_VERSION) || defined(__GLIBCXX__))) || \ 00130 (defined(_MSC_VER) && !defined(__NVCC__)) 00131 #define ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE 1 00132 #define ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE 1 00133 #endif 00134 00135 // ABSL_HAVE_THREAD_LOCAL 00136 // 00137 // Checks whether C++11's `thread_local` storage duration specifier is 00138 // supported. 00139 #ifdef ABSL_HAVE_THREAD_LOCAL 00140 #error ABSL_HAVE_THREAD_LOCAL cannot be directly set 00141 #elif defined(__APPLE__) 00142 // Notes: 00143 // * Xcode's clang did not support `thread_local` until version 8, and 00144 // even then not for all iOS < 9.0. 00145 // * Xcode 9.3 started disallowing `thread_local` for 32-bit iOS simulator 00146 // targeting iOS 9.x. 00147 // * Xcode 10 moves the deployment target check for iOS < 9.0 to link time 00148 // making __has_feature unreliable there. 00149 // 00150 // Otherwise, `__has_feature` is only supported by Clang so it has be inside 00151 // `defined(__APPLE__)` check. 00152 #if __has_feature(cxx_thread_local) && \ 00153 !(TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_9_0) 00154 #define ABSL_HAVE_THREAD_LOCAL 1 00155 #endif 00156 #else // !defined(__APPLE__) 00157 #define ABSL_HAVE_THREAD_LOCAL 1 00158 #endif 00159 00160 // There are platforms for which TLS should not be used even though the compiler 00161 // makes it seem like it's supported (Android NDK < r12b for example). 00162 // This is primarily because of linker problems and toolchain misconfiguration: 00163 // Abseil does not intend to support this indefinitely. Currently, the newest 00164 // toolchain that we intend to support that requires this behavior is the 00165 // r11 NDK - allowing for a 5 year support window on that means this option 00166 // is likely to be removed around June of 2021. 00167 // TLS isn't supported until NDK r12b per 00168 // https://developer.android.com/ndk/downloads/revision_history.html 00169 // Since NDK r16, `__NDK_MAJOR__` and `__NDK_MINOR__` are defined in 00170 // <android/ndk-version.h>. For NDK < r16, users should define these macros, 00171 // e.g. `-D__NDK_MAJOR__=11 -D__NKD_MINOR__=0` for NDK r11. 00172 #if defined(__ANDROID__) && defined(__clang__) 00173 #if __has_include(<android/ndk-version.h>) 00174 #include <android/ndk-version.h> 00175 #endif // __has_include(<android/ndk-version.h>) 00176 #if defined(__ANDROID__) && defined(__clang__) && defined(__NDK_MAJOR__) && \ 00177 defined(__NDK_MINOR__) && \ 00178 ((__NDK_MAJOR__ < 12) || ((__NDK_MAJOR__ == 12) && (__NDK_MINOR__ < 1))) 00179 #undef ABSL_HAVE_TLS 00180 #undef ABSL_HAVE_THREAD_LOCAL 00181 #endif 00182 #endif // defined(__ANDROID__) && defined(__clang__) 00183 00184 // ABSL_HAVE_INTRINSIC_INT128 00185 // 00186 // Checks whether the __int128 compiler extension for a 128-bit integral type is 00187 // supported. 00188 // 00189 // Note: __SIZEOF_INT128__ is defined by Clang and GCC when __int128 is 00190 // supported, but we avoid using it in certain cases: 00191 // * On Clang: 00192 // * Building using Clang for Windows, where the Clang runtime library has 00193 // 128-bit support only on LP64 architectures, but Windows is LLP64. 00194 // * On Nvidia's nvcc: 00195 // * nvcc also defines __GNUC__ and __SIZEOF_INT128__, but not all versions 00196 // actually support __int128. 00197 #ifdef ABSL_HAVE_INTRINSIC_INT128 00198 #error ABSL_HAVE_INTRINSIC_INT128 cannot be directly set 00199 #elif defined(__SIZEOF_INT128__) 00200 #if (defined(__clang__) && !defined(_WIN32)) || \ 00201 (defined(__CUDACC__) && __CUDACC_VER_MAJOR__ >= 9) || \ 00202 (defined(__GNUC__) && !defined(__clang__) && !defined(__CUDACC__)) 00203 #define ABSL_HAVE_INTRINSIC_INT128 1 00204 #elif defined(__CUDACC__) 00205 // __CUDACC_VER__ is a full version number before CUDA 9, and is defined to a 00206 // string explaining that it has been removed starting with CUDA 9. We use 00207 // nested #ifs because there is no short-circuiting in the preprocessor. 00208 // NOTE: `__CUDACC__` could be undefined while `__CUDACC_VER__` is defined. 00209 #if __CUDACC_VER__ >= 70000 00210 #define ABSL_HAVE_INTRINSIC_INT128 1 00211 #endif // __CUDACC_VER__ >= 70000 00212 #endif // defined(__CUDACC__) 00213 #endif // ABSL_HAVE_INTRINSIC_INT128 00214 00215 // ABSL_HAVE_EXCEPTIONS 00216 // 00217 // Checks whether the compiler both supports and enables exceptions. Many 00218 // compilers support a "no exceptions" mode that disables exceptions. 00219 // 00220 // Generally, when ABSL_HAVE_EXCEPTIONS is not defined: 00221 // 00222 // * Code using `throw` and `try` may not compile. 00223 // * The `noexcept` specifier will still compile and behave as normal. 00224 // * The `noexcept` operator may still return `false`. 00225 // 00226 // For further details, consult the compiler's documentation. 00227 #ifdef ABSL_HAVE_EXCEPTIONS 00228 #error ABSL_HAVE_EXCEPTIONS cannot be directly set. 00229 00230 #elif defined(__clang__) 00231 // TODO(calabrese) 00232 // Switch to using __cpp_exceptions when we no longer support versions < 3.6. 00233 // For details on this check, see: 00234 // http://releases.llvm.org/3.6.0/tools/clang/docs/ReleaseNotes.html#the-exceptions-macro 00235 #if defined(__EXCEPTIONS) && __has_feature(cxx_exceptions) 00236 #define ABSL_HAVE_EXCEPTIONS 1 00237 #endif // defined(__EXCEPTIONS) && __has_feature(cxx_exceptions) 00238 00239 // Handle remaining special cases and default to exceptions being supported. 00240 #elif !(defined(__GNUC__) && (__GNUC__ < 5) && !defined(__EXCEPTIONS)) && \ 00241 !(defined(__GNUC__) && (__GNUC__ >= 5) && !defined(__cpp_exceptions)) && \ 00242 !(defined(_MSC_VER) && !defined(_CPPUNWIND)) 00243 #define ABSL_HAVE_EXCEPTIONS 1 00244 #endif 00245 00246 // ----------------------------------------------------------------------------- 00247 // Platform Feature Checks 00248 // ----------------------------------------------------------------------------- 00249 00250 // Currently supported operating systems and associated preprocessor 00251 // symbols: 00252 // 00253 // Linux and Linux-derived __linux__ 00254 // Android __ANDROID__ (implies __linux__) 00255 // Linux (non-Android) __linux__ && !__ANDROID__ 00256 // Darwin (Mac OS X and iOS) __APPLE__ 00257 // Akaros (http://akaros.org) __ros__ 00258 // Windows _WIN32 00259 // NaCL __native_client__ 00260 // AsmJS __asmjs__ 00261 // WebAssembly __wasm__ 00262 // Fuchsia __Fuchsia__ 00263 // 00264 // Note that since Android defines both __ANDROID__ and __linux__, one 00265 // may probe for either Linux or Android by simply testing for __linux__. 00266 00267 // ABSL_HAVE_MMAP 00268 // 00269 // Checks whether the platform has an mmap(2) implementation as defined in 00270 // POSIX.1-2001. 00271 #ifdef ABSL_HAVE_MMAP 00272 #error ABSL_HAVE_MMAP cannot be directly set 00273 #elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \ 00274 defined(__ros__) || defined(__native_client__) || defined(__asmjs__) || \ 00275 defined(__wasm__) || defined(__Fuchsia__) || defined(__sun) || \ 00276 defined(__ASYLO__) 00277 #define ABSL_HAVE_MMAP 1 00278 #endif 00279 00280 // ABSL_HAVE_PTHREAD_GETSCHEDPARAM 00281 // 00282 // Checks whether the platform implements the pthread_(get|set)schedparam(3) 00283 // functions as defined in POSIX.1-2001. 00284 #ifdef ABSL_HAVE_PTHREAD_GETSCHEDPARAM 00285 #error ABSL_HAVE_PTHREAD_GETSCHEDPARAM cannot be directly set 00286 #elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \ 00287 defined(__ros__) 00288 #define ABSL_HAVE_PTHREAD_GETSCHEDPARAM 1 00289 #endif 00290 00291 // ABSL_HAVE_SCHED_YIELD 00292 // 00293 // Checks whether the platform implements sched_yield(2) as defined in 00294 // POSIX.1-2001. 00295 #ifdef ABSL_HAVE_SCHED_YIELD 00296 #error ABSL_HAVE_SCHED_YIELD cannot be directly set 00297 #elif defined(__linux__) || defined(__ros__) || defined(__native_client__) 00298 #define ABSL_HAVE_SCHED_YIELD 1 00299 #endif 00300 00301 // ABSL_HAVE_SEMAPHORE_H 00302 // 00303 // Checks whether the platform supports the <semaphore.h> header and sem_open(3) 00304 // family of functions as standardized in POSIX.1-2001. 00305 // 00306 // Note: While Apple provides <semaphore.h> for both iOS and macOS, it is 00307 // explicitly deprecated and will cause build failures if enabled for those 00308 // platforms. We side-step the issue by not defining it here for Apple 00309 // platforms. 00310 #ifdef ABSL_HAVE_SEMAPHORE_H 00311 #error ABSL_HAVE_SEMAPHORE_H cannot be directly set 00312 #elif defined(__linux__) || defined(__ros__) 00313 #define ABSL_HAVE_SEMAPHORE_H 1 00314 #endif 00315 00316 // ABSL_HAVE_ALARM 00317 // 00318 // Checks whether the platform supports the <signal.h> header and alarm(2) 00319 // function as standardized in POSIX.1-2001. 00320 #ifdef ABSL_HAVE_ALARM 00321 #error ABSL_HAVE_ALARM cannot be directly set 00322 #elif defined(__GOOGLE_GRTE_VERSION__) 00323 // feature tests for Google's GRTE 00324 #define ABSL_HAVE_ALARM 1 00325 #elif defined(__GLIBC__) 00326 // feature test for glibc 00327 #define ABSL_HAVE_ALARM 1 00328 #elif defined(_MSC_VER) 00329 // feature tests for Microsoft's library 00330 #elif defined(__EMSCRIPTEN__) 00331 // emscripten doesn't support signals 00332 #elif defined(__native_client__) 00333 #else 00334 // other standard libraries 00335 #define ABSL_HAVE_ALARM 1 00336 #endif 00337 00338 // ABSL_IS_LITTLE_ENDIAN 00339 // ABSL_IS_BIG_ENDIAN 00340 // 00341 // Checks the endianness of the platform. 00342 // 00343 // Notes: uses the built in endian macros provided by GCC (since 4.6) and 00344 // Clang (since 3.2); see 00345 // https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html. 00346 // Otherwise, if _WIN32, assume little endian. Otherwise, bail with an error. 00347 #if defined(ABSL_IS_BIG_ENDIAN) 00348 #error "ABSL_IS_BIG_ENDIAN cannot be directly set." 00349 #endif 00350 #if defined(ABSL_IS_LITTLE_ENDIAN) 00351 #error "ABSL_IS_LITTLE_ENDIAN cannot be directly set." 00352 #endif 00353 00354 #if (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \ 00355 __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) 00356 #define ABSL_IS_LITTLE_ENDIAN 1 00357 #elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \ 00358 __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 00359 #define ABSL_IS_BIG_ENDIAN 1 00360 #elif defined(_WIN32) 00361 #define ABSL_IS_LITTLE_ENDIAN 1 00362 #else 00363 #error "absl endian detection needs to be set up for your compiler" 00364 #endif 00365 00366 // MacOS 10.13 doesn't let you use <any>, <optional>, or <variant> even though 00367 // the headers exist and are publicly noted to work. See 00368 // https://github.com/abseil/abseil-cpp/issues/207 and 00369 // https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes 00370 #if defined(__APPLE__) && defined(_LIBCPP_VERSION) && \ 00371 defined(__MAC_OS_X_VERSION_MIN_REQUIRED__) && \ 00372 __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101400 00373 #define ABSL_INTERNAL_MACOS_CXX17_TYPES_UNAVAILABLE 1 00374 #else 00375 #define ABSL_INTERNAL_MACOS_CXX17_TYPES_UNAVAILABLE 0 00376 #endif 00377 00378 // ABSL_HAVE_STD_ANY 00379 // 00380 // Checks whether C++17 std::any is available by checking whether <any> exists. 00381 #ifdef ABSL_HAVE_STD_ANY 00382 #error "ABSL_HAVE_STD_ANY cannot be directly set." 00383 #endif 00384 00385 #ifdef __has_include 00386 #if __has_include(<any>) && __cplusplus >= 201703L && \ 00387 !ABSL_INTERNAL_MACOS_CXX17_TYPES_UNAVAILABLE 00388 #define ABSL_HAVE_STD_ANY 1 00389 #endif 00390 #endif 00391 00392 // ABSL_HAVE_STD_OPTIONAL 00393 // 00394 // Checks whether C++17 std::optional is available. 00395 #ifdef ABSL_HAVE_STD_OPTIONAL 00396 #error "ABSL_HAVE_STD_OPTIONAL cannot be directly set." 00397 #endif 00398 00399 #ifdef __has_include 00400 #if __has_include(<optional>) && __cplusplus >= 201703L && \ 00401 !ABSL_INTERNAL_MACOS_CXX17_TYPES_UNAVAILABLE 00402 #define ABSL_HAVE_STD_OPTIONAL 1 00403 #endif 00404 #endif 00405 00406 // ABSL_HAVE_STD_VARIANT 00407 // 00408 // Checks whether C++17 std::variant is available. 00409 #ifdef ABSL_HAVE_STD_VARIANT 00410 #error "ABSL_HAVE_STD_VARIANT cannot be directly set." 00411 #endif 00412 00413 #ifdef __has_include 00414 #if __has_include(<variant>) && __cplusplus >= 201703L && \ 00415 !ABSL_INTERNAL_MACOS_CXX17_TYPES_UNAVAILABLE 00416 #define ABSL_HAVE_STD_VARIANT 1 00417 #endif 00418 #endif 00419 00420 // ABSL_HAVE_STD_STRING_VIEW 00421 // 00422 // Checks whether C++17 std::string_view is available. 00423 #ifdef ABSL_HAVE_STD_STRING_VIEW 00424 #error "ABSL_HAVE_STD_STRING_VIEW cannot be directly set." 00425 #endif 00426 00427 #ifdef __has_include 00428 #if __has_include(<string_view>) && __cplusplus >= 201703L 00429 #define ABSL_HAVE_STD_STRING_VIEW 1 00430 #endif 00431 #endif 00432 00433 // For MSVC, `__has_include` is supported in VS 2017 15.3, which is later than 00434 // the support for <optional>, <any>, <string_view>, <variant>. So we use 00435 // _MSC_VER to check whether we have VS 2017 RTM (when <optional>, <any>, 00436 // <string_view>, <variant> is implemented) or higher. Also, `__cplusplus` is 00437 // not correctly set by MSVC, so we use `_MSVC_LANG` to check the language 00438 // version. 00439 // TODO(zhangxy): fix tests before enabling aliasing for `std::any`. 00440 #if defined(_MSC_VER) && _MSC_VER >= 1910 && \ 00441 ((defined(_MSVC_LANG) && _MSVC_LANG > 201402) || __cplusplus > 201402) 00442 // #define ABSL_HAVE_STD_ANY 1 00443 #define ABSL_HAVE_STD_OPTIONAL 1 00444 #define ABSL_HAVE_STD_VARIANT 1 00445 #define ABSL_HAVE_STD_STRING_VIEW 1 00446 #endif 00447 00448 // In debug mode, MSVC 2017's std::variant throws a EXCEPTION_ACCESS_VIOLATION 00449 // SEH exception from emplace for variant<SomeStruct> when constructing the 00450 // struct can throw. This defeats some of variant_test and 00451 // variant_exception_safety_test. 00452 #if defined(_MSC_VER) && _MSC_VER >= 1700 && defined(_DEBUG) 00453 #define ABSL_INTERNAL_MSVC_2017_DBG_MODE 00454 #endif 00455 00456 #endif // ABSL_BASE_CONFIG_H_