platform_macros.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2012 Google Inc. All rights reserved.
  3. // https://developers.google.com/protocol-buffers/
  4. //
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are
  7. // met:
  8. //
  9. // * Redistributions of source code must retain the above copyright
  10. // notice, this list of conditions and the following disclaimer.
  11. // * Redistributions in binary form must reproduce the above
  12. // copyright notice, this list of conditions and the following disclaimer
  13. // in the documentation and/or other materials provided with the
  14. // distribution.
  15. // * Neither the name of Google Inc. nor the names of its
  16. // contributors may be used to endorse or promote products derived from
  17. // this software without specific prior written permission.
  18. //
  19. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. #ifndef GOOGLE_PROTOBUF_PLATFORM_MACROS_H_
  31. #define GOOGLE_PROTOBUF_PLATFORM_MACROS_H_
  32. #define GOOGLE_PROTOBUF_PLATFORM_ERROR \
  33. #error "Host platform was not detected as supported by protobuf"
  34. // Processor architecture detection. For more info on what's defined, see:
  35. // http://msdn.microsoft.com/en-us/library/b0084kay.aspx
  36. // http://www.agner.org/optimize/calling_conventions.pdf
  37. // or with gcc, run: "echo | gcc -E -dM -"
  38. #if defined(_M_X64) || defined(__x86_64__)
  39. #define GOOGLE_PROTOBUF_ARCH_X64 1
  40. #define GOOGLE_PROTOBUF_ARCH_64_BIT 1
  41. #elif defined(_M_IX86) || defined(__i386__)
  42. #define GOOGLE_PROTOBUF_ARCH_IA32 1
  43. #define GOOGLE_PROTOBUF_ARCH_32_BIT 1
  44. #elif defined(__QNX__)
  45. #define GOOGLE_PROTOBUF_ARCH_ARM_QNX 1
  46. #if defined(__aarch64__)
  47. #define GOOGLE_PROTOBUF_ARCH_64_BIT 1
  48. #else
  49. #define GOOGLE_PROTOBUF_ARCH_32_BIT 1
  50. #endif
  51. #elif defined(_M_ARM) || defined(__ARMEL__)
  52. #define GOOGLE_PROTOBUF_ARCH_ARM 1
  53. #define GOOGLE_PROTOBUF_ARCH_32_BIT 1
  54. #elif defined(_M_ARM64)
  55. #define GOOGLE_PROTOBUF_ARCH_ARM 1
  56. #define GOOGLE_PROTOBUF_ARCH_64_BIT 1
  57. #elif defined(__aarch64__)
  58. #define GOOGLE_PROTOBUF_ARCH_AARCH64 1
  59. #define GOOGLE_PROTOBUF_ARCH_64_BIT 1
  60. #elif defined(__mips__)
  61. #if defined(__LP64__)
  62. #define GOOGLE_PROTOBUF_ARCH_MIPS64 1
  63. #define GOOGLE_PROTOBUF_ARCH_64_BIT 1
  64. #else
  65. #define GOOGLE_PROTOBUF_ARCH_MIPS 1
  66. #define GOOGLE_PROTOBUF_ARCH_32_BIT 1
  67. #endif
  68. #elif defined(__pnacl__)
  69. #define GOOGLE_PROTOBUF_ARCH_32_BIT 1
  70. #elif defined(sparc)
  71. #define GOOGLE_PROTOBUF_ARCH_SPARC 1
  72. #if defined(__sparc_v9__) || defined(__sparcv9) || defined(__arch64__)
  73. #define GOOGLE_PROTOBUF_ARCH_64_BIT 1
  74. #else
  75. #define GOOGLE_PROTOBUF_ARCH_32_BIT 1
  76. #endif
  77. #elif defined(_POWER) || defined(__powerpc64__) || defined(__PPC64__)
  78. #define GOOGLE_PROTOBUF_ARCH_POWER 1
  79. #define GOOGLE_PROTOBUF_ARCH_64_BIT 1
  80. #elif defined(__PPC__)
  81. #define GOOGLE_PROTOBUF_ARCH_PPC 1
  82. #define GOOGLE_PROTOBUF_ARCH_32_BIT 1
  83. #elif defined(__GNUC__)
  84. # if (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 4))
  85. // We fallback to the generic Clang/GCC >= 4.7 implementation in atomicops.h
  86. # elif defined(__clang__)
  87. # if !__has_extension(c_atomic)
  88. GOOGLE_PROTOBUF_PLATFORM_ERROR
  89. # endif
  90. // We fallback to the generic Clang/GCC >= 4.7 implementation in atomicops.h
  91. # endif
  92. # if __LP64__
  93. # define GOOGLE_PROTOBUF_ARCH_64_BIT 1
  94. # else
  95. # define GOOGLE_PROTOBUF_ARCH_32_BIT 1
  96. # endif
  97. #else
  98. GOOGLE_PROTOBUF_PLATFORM_ERROR
  99. #endif
  100. #if defined(__APPLE__)
  101. #define GOOGLE_PROTOBUF_OS_APPLE
  102. #include <Availability.h>
  103. #include <TargetConditionals.h>
  104. #if TARGET_OS_IPHONE
  105. #define GOOGLE_PROTOBUF_OS_IPHONE
  106. #endif
  107. #elif defined(__EMSCRIPTEN__)
  108. #define GOOGLE_PROTOBUF_OS_EMSCRIPTEN
  109. #elif defined(__native_client__)
  110. #define GOOGLE_PROTOBUF_OS_NACL
  111. #elif defined(sun)
  112. #define GOOGLE_PROTOBUF_OS_SOLARIS
  113. #elif defined(_AIX)
  114. #define GOOGLE_PROTOBUF_OS_AIX
  115. #elif defined(__ANDROID__)
  116. #define GOOGLE_PROTOBUF_OS_ANDROID
  117. #endif
  118. #undef GOOGLE_PROTOBUF_PLATFORM_ERROR
  119. #if defined(GOOGLE_PROTOBUF_OS_ANDROID) || defined(GOOGLE_PROTOBUF_OS_IPHONE) || defined(__OpenBSD__)
  120. // Android ndk does not support the __thread keyword very well yet. Here
  121. // we use pthread_key_create()/pthread_getspecific()/... methods for
  122. // TLS support on android.
  123. // iOS and OpenBSD also do not support the __thread keyword.
  124. #define GOOGLE_PROTOBUF_NO_THREADLOCAL
  125. #endif
  126. #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 1070
  127. // __thread keyword requires at least 10.7
  128. #define GOOGLE_PROTOBUF_NO_THREADLOCAL
  129. #endif
  130. #endif // GOOGLE_PROTOBUF_PLATFORM_MACROS_H_