• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2012 Google Inc.  All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
7 
8 #ifndef GOOGLE_PROTOBUF_PLATFORM_MACROS_H_
9 #define GOOGLE_PROTOBUF_PLATFORM_MACROS_H_
10 
11 #define GOOGLE_PROTOBUF_PLATFORM_ERROR \
12 #error "Host platform was not detected as supported by protobuf"
13 
14 // Processor architecture detection.  For more info on what's defined, see:
15 //   http://msdn.microsoft.com/en-us/library/b0084kay.aspx
16 //   http://www.agner.org/optimize/calling_conventions.pdf
17 //   or with gcc, run: "echo | gcc -E -dM -"
18 #if defined(_M_X64) || defined(__x86_64__)
19 #define GOOGLE_PROTOBUF_ARCH_X64 1
20 #define GOOGLE_PROTOBUF_ARCH_64_BIT 1
21 #elif defined(_M_IX86) || defined(__i386__)
22 #define GOOGLE_PROTOBUF_ARCH_IA32 1
23 #define GOOGLE_PROTOBUF_ARCH_32_BIT 1
24 #elif defined(__QNX__)
25 #define GOOGLE_PROTOBUF_ARCH_ARM_QNX 1
26 #if defined(__aarch64__)
27 #define GOOGLE_PROTOBUF_ARCH_64_BIT 1
28 #else
29 #define GOOGLE_PROTOBUF_ARCH_32_BIT 1
30 #endif
31 #elif defined(_M_ARM) || defined(__ARMEL__)
32 #define GOOGLE_PROTOBUF_ARCH_ARM 1
33 #define GOOGLE_PROTOBUF_ARCH_32_BIT 1
34 #elif defined(_M_ARM64)
35 #define GOOGLE_PROTOBUF_ARCH_ARM 1
36 #define GOOGLE_PROTOBUF_ARCH_64_BIT 1
37 #elif defined(__aarch64__)
38 #define GOOGLE_PROTOBUF_ARCH_AARCH64 1
39 #define GOOGLE_PROTOBUF_ARCH_64_BIT 1
40 #elif defined(__mips__)
41 #if defined(__LP64__)
42 #define GOOGLE_PROTOBUF_ARCH_MIPS64 1
43 #define GOOGLE_PROTOBUF_ARCH_64_BIT 1
44 #else
45 #define GOOGLE_PROTOBUF_ARCH_MIPS 1
46 #define GOOGLE_PROTOBUF_ARCH_32_BIT 1
47 #endif
48 #elif defined(__pnacl__)
49 #define GOOGLE_PROTOBUF_ARCH_32_BIT 1
50 #elif defined(sparc)
51 #define GOOGLE_PROTOBUF_ARCH_SPARC 1
52 #if defined(__sparc_v9__) || defined(__sparcv9) || defined(__arch64__)
53 #define GOOGLE_PROTOBUF_ARCH_64_BIT 1
54 #else
55 #define GOOGLE_PROTOBUF_ARCH_32_BIT 1
56 #endif
57 #elif defined(_POWER) || defined(__powerpc64__) || defined(__PPC64__)
58 #define GOOGLE_PROTOBUF_ARCH_POWER 1
59 #define GOOGLE_PROTOBUF_ARCH_64_BIT 1
60 #elif defined(__PPC__)
61 #define GOOGLE_PROTOBUF_ARCH_PPC 1
62 #define GOOGLE_PROTOBUF_ARCH_32_BIT 1
63 #elif defined(__GNUC__)
64 # if (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 4))
65 // We fallback to the generic Clang/GCC >= 4.7 implementation in atomicops.h
66 # elif defined(__clang__)
67 #  if !__has_extension(c_atomic)
68 GOOGLE_PROTOBUF_PLATFORM_ERROR
69 #  endif
70 // We fallback to the generic Clang/GCC >= 4.7 implementation in atomicops.h
71 # endif
72 # if __LP64__
73 #  define GOOGLE_PROTOBUF_ARCH_64_BIT 1
74 # else
75 #  define GOOGLE_PROTOBUF_ARCH_32_BIT 1
76 # endif
77 #else
78 GOOGLE_PROTOBUF_PLATFORM_ERROR
79 #endif
80 
81 #if defined(__APPLE__)
82 #define GOOGLE_PROTOBUF_OS_APPLE
83 #include <Availability.h>
84 #include <TargetConditionals.h>
85 #if TARGET_OS_IPHONE
86 #define GOOGLE_PROTOBUF_OS_IPHONE
87 #endif
88 #elif defined(__EMSCRIPTEN__)
89 #define GOOGLE_PROTOBUF_OS_EMSCRIPTEN
90 #elif defined(__native_client__)
91 #define GOOGLE_PROTOBUF_OS_NACL
92 #elif defined(sun)
93 #define GOOGLE_PROTOBUF_OS_SOLARIS
94 #elif defined(_AIX)
95 #define GOOGLE_PROTOBUF_OS_AIX
96 #elif defined(__ANDROID__)
97 #define GOOGLE_PROTOBUF_OS_ANDROID
98 #endif
99 
100 #undef GOOGLE_PROTOBUF_PLATFORM_ERROR
101 
102 #if defined(GOOGLE_PROTOBUF_OS_ANDROID) || defined(GOOGLE_PROTOBUF_OS_IPHONE)
103 // Android ndk does not support the __thread keyword very well yet. Here
104 // we use pthread_key_create()/pthread_getspecific()/... methods for
105 // TLS support on android.
106 // iOS also does not support the __thread keyword.
107 #define GOOGLE_PROTOBUF_NO_THREADLOCAL
108 #endif
109 
110 #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 1070
111 // __thread keyword requires at least 10.7
112 #define GOOGLE_PROTOBUF_NO_THREADLOCAL
113 #endif
114 
115 #endif  // GOOGLE_PROTOBUF_PLATFORM_MACROS_H_
116