build_config.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. // This file doesn't belong to any GN target by design for faster build and
  5. // less developer overhead.
  6. // This file adds build flags about the OS we're currently building on. They are
  7. // defined directly in this file instead of via a `buildflag_header` target in a
  8. // GN file for faster build. They are defined using the corresponding OS defines
  9. // (e.g. OS_WIN) which are also defined in this file (except for OS_CHROMEOS,
  10. // which is set by the build system). These defines are deprecated and should
  11. // NOT be used directly. For example:
  12. // Please Use: #if BUILDFLAG(IS_WIN)
  13. // Deprecated: #if defined(OS_WIN)
  14. //
  15. // Operating System:
  16. // IS_AIX / IS_ANDROID / IS_ASMJS / IS_CHROMEOS / IS_FREEBSD / IS_FUCHSIA /
  17. // IS_IOS / IS_IOS_MACCATALYST / IS_LINUX / IS_MAC / IS_NACL / IS_NETBSD /
  18. // IS_OPENBSD / IS_QNX / IS_SOLARIS / IS_WIN
  19. // Operating System family:
  20. // IS_APPLE: IOS or MAC or IOS_MACCATALYST
  21. // IS_BSD: FREEBSD or NETBSD or OPENBSD
  22. // IS_POSIX: AIX or ANDROID or ASMJS or CHROMEOS or FREEBSD or IOS or LINUX
  23. // or MAC or NACL or NETBSD or OPENBSD or QNX or SOLARIS
  24. // This file also adds defines specific to the platform, architecture etc.
  25. //
  26. // Compiler:
  27. // COMPILER_MSVC / COMPILER_GCC
  28. //
  29. // Processor:
  30. // ARCH_CPU_ARM64 / ARCH_CPU_ARMEL / ARCH_CPU_LOONG32 / ARCH_CPU_LOONG64 /
  31. // ARCH_CPU_MIPS / ARCH_CPU_MIPS64 / ARCH_CPU_MIPS64EL / ARCH_CPU_MIPSEL /
  32. // ARCH_CPU_PPC64 / ARCH_CPU_S390 / ARCH_CPU_S390X / ARCH_CPU_X86 /
  33. // ARCH_CPU_X86_64 / ARCH_CPU_RISCV64
  34. // Processor family:
  35. // ARCH_CPU_ARM_FAMILY: ARMEL or ARM64
  36. // ARCH_CPU_LOONG_FAMILY: LOONG32 or LOONG64
  37. // ARCH_CPU_MIPS_FAMILY: MIPS64EL or MIPSEL or MIPS64 or MIPS
  38. // ARCH_CPU_PPC64_FAMILY: PPC64
  39. // ARCH_CPU_S390_FAMILY: S390 or S390X
  40. // ARCH_CPU_X86_FAMILY: X86 or X86_64
  41. // ARCH_CPU_RISCV_FAMILY: Riscv64
  42. // Processor features:
  43. // ARCH_CPU_31_BITS / ARCH_CPU_32_BITS / ARCH_CPU_64_BITS
  44. // ARCH_CPU_BIG_ENDIAN / ARCH_CPU_LITTLE_ENDIAN
  45. #ifndef BUILD_BUILD_CONFIG_H_
  46. #define BUILD_BUILD_CONFIG_H_
  47. #include "build/buildflag.h" // IWYU pragma: export
  48. // A set of macros to use for platform detection.
  49. #if defined(__native_client__)
  50. // __native_client__ must be first, so that other OS_ defines are not set.
  51. #define OS_NACL 1
  52. #elif defined(ANDROID)
  53. #define OS_ANDROID 1
  54. #elif defined(__APPLE__)
  55. // Only include TargetConditionals after testing ANDROID as some Android builds
  56. // on the Mac have this header available and it's not needed unless the target
  57. // is really an Apple platform.
  58. #include <TargetConditionals.h>
  59. #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
  60. #define OS_IOS 1
  61. // Catalyst is the technology that allows running iOS apps on macOS. These
  62. // builds are both OS_IOS and OS_IOS_MACCATALYST.
  63. #if defined(TARGET_OS_MACCATALYST) && TARGET_OS_MACCATALYST
  64. #define OS_IOS_MACCATALYST
  65. #endif // defined(TARGET_OS_MACCATALYST) && TARGET_OS_MACCATALYST
  66. #else
  67. #define OS_MAC 1
  68. #endif // defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
  69. #elif defined(__linux__)
  70. #if !defined(OS_CHROMEOS)
  71. // Do not define OS_LINUX on Chrome OS build.
  72. // The OS_CHROMEOS macro is defined in GN.
  73. #define OS_LINUX 1
  74. #endif // !defined(OS_CHROMEOS)
  75. // Include a system header to pull in features.h for glibc/uclibc macros.
  76. #include <assert.h>
  77. #if defined(__GLIBC__) && !defined(__UCLIBC__)
  78. // We really are using glibc, not uClibc pretending to be glibc.
  79. #define LIBC_GLIBC 1
  80. #endif
  81. #elif defined(_WIN32)
  82. #define OS_WIN 1
  83. #elif defined(__Fuchsia__)
  84. #define OS_FUCHSIA 1
  85. #elif defined(__FreeBSD__)
  86. #define OS_FREEBSD 1
  87. #elif defined(__NetBSD__)
  88. #define OS_NETBSD 1
  89. #elif defined(__OpenBSD__)
  90. #define OS_OPENBSD 1
  91. #elif defined(__sun)
  92. #define OS_SOLARIS 1
  93. #elif defined(__QNXNTO__)
  94. #define OS_QNX 1
  95. #elif defined(_AIX)
  96. #define OS_AIX 1
  97. #elif defined(__asmjs__) || defined(__wasm__)
  98. #define OS_ASMJS 1
  99. #elif defined(__MVS__)
  100. #define OS_ZOS 1
  101. #else
  102. #error Please add support for your platform in build/build_config.h
  103. #endif
  104. // NOTE: Adding a new port? Please follow
  105. // https://chromium.googlesource.com/chromium/src/+/main/docs/new_port_policy.md
  106. #if defined(OS_MAC) || defined(OS_IOS)
  107. #define OS_APPLE 1
  108. #endif
  109. // For access to standard BSD features, use OS_BSD instead of a
  110. // more specific macro.
  111. #if defined(OS_FREEBSD) || defined(OS_NETBSD) || defined(OS_OPENBSD)
  112. #define OS_BSD 1
  113. #endif
  114. // For access to standard POSIXish features, use OS_POSIX instead of a
  115. // more specific macro.
  116. #if defined(OS_AIX) || defined(OS_ANDROID) || defined(OS_ASMJS) || \
  117. defined(OS_FREEBSD) || defined(OS_IOS) || defined(OS_LINUX) || \
  118. defined(OS_CHROMEOS) || defined(OS_MAC) || defined(OS_NACL) || \
  119. defined(OS_NETBSD) || defined(OS_OPENBSD) || defined(OS_QNX) || \
  120. defined(OS_SOLARIS) || defined(OS_ZOS)
  121. #define OS_POSIX 1
  122. #endif
  123. // OS build flags
  124. #if defined(OS_AIX)
  125. #define BUILDFLAG_INTERNAL_IS_AIX() (1)
  126. #else
  127. #define BUILDFLAG_INTERNAL_IS_AIX() (0)
  128. #endif
  129. #if defined(OS_ANDROID)
  130. #define BUILDFLAG_INTERNAL_IS_ANDROID() (1)
  131. #else
  132. #define BUILDFLAG_INTERNAL_IS_ANDROID() (0)
  133. #endif
  134. #if defined(OS_APPLE)
  135. #define BUILDFLAG_INTERNAL_IS_APPLE() (1)
  136. #else
  137. #define BUILDFLAG_INTERNAL_IS_APPLE() (0)
  138. #endif
  139. #if defined(OS_ASMJS)
  140. #define BUILDFLAG_INTERNAL_IS_ASMJS() (1)
  141. #else
  142. #define BUILDFLAG_INTERNAL_IS_ASMJS() (0)
  143. #endif
  144. #if defined(OS_BSD)
  145. #define BUILDFLAG_INTERNAL_IS_BSD() (1)
  146. #else
  147. #define BUILDFLAG_INTERNAL_IS_BSD() (0)
  148. #endif
  149. #if defined(OS_CHROMEOS)
  150. #define BUILDFLAG_INTERNAL_IS_CHROMEOS() (1)
  151. #else
  152. #define BUILDFLAG_INTERNAL_IS_CHROMEOS() (0)
  153. #endif
  154. #if defined(OS_FREEBSD)
  155. #define BUILDFLAG_INTERNAL_IS_FREEBSD() (1)
  156. #else
  157. #define BUILDFLAG_INTERNAL_IS_FREEBSD() (0)
  158. #endif
  159. #if defined(OS_FUCHSIA)
  160. #define BUILDFLAG_INTERNAL_IS_FUCHSIA() (1)
  161. #else
  162. #define BUILDFLAG_INTERNAL_IS_FUCHSIA() (0)
  163. #endif
  164. #if defined(OS_IOS)
  165. #define BUILDFLAG_INTERNAL_IS_IOS() (1)
  166. #else
  167. #define BUILDFLAG_INTERNAL_IS_IOS() (0)
  168. #endif
  169. #if defined(OS_IOS_MACCATALYST)
  170. #define BUILDFLAG_INTERNAL_IS_IOS_MACCATALYST() (1)
  171. #else
  172. #define BUILDFLAG_INTERNAL_IS_IOS_MACCATALYST() (0)
  173. #endif
  174. #if defined(OS_LINUX)
  175. #define BUILDFLAG_INTERNAL_IS_LINUX() (1)
  176. #else
  177. #define BUILDFLAG_INTERNAL_IS_LINUX() (0)
  178. #endif
  179. #if defined(OS_MAC)
  180. #define BUILDFLAG_INTERNAL_IS_MAC() (1)
  181. #else
  182. #define BUILDFLAG_INTERNAL_IS_MAC() (0)
  183. #endif
  184. #if defined(OS_NACL)
  185. #define BUILDFLAG_INTERNAL_IS_NACL() (1)
  186. #else
  187. #define BUILDFLAG_INTERNAL_IS_NACL() (0)
  188. #endif
  189. #if defined(OS_NETBSD)
  190. #define BUILDFLAG_INTERNAL_IS_NETBSD() (1)
  191. #else
  192. #define BUILDFLAG_INTERNAL_IS_NETBSD() (0)
  193. #endif
  194. #if defined(OS_OPENBSD)
  195. #define BUILDFLAG_INTERNAL_IS_OPENBSD() (1)
  196. #else
  197. #define BUILDFLAG_INTERNAL_IS_OPENBSD() (0)
  198. #endif
  199. #if defined(OS_POSIX)
  200. #define BUILDFLAG_INTERNAL_IS_POSIX() (1)
  201. #else
  202. #define BUILDFLAG_INTERNAL_IS_POSIX() (0)
  203. #endif
  204. #if defined(OS_QNX)
  205. #define BUILDFLAG_INTERNAL_IS_QNX() (1)
  206. #else
  207. #define BUILDFLAG_INTERNAL_IS_QNX() (0)
  208. #endif
  209. #if defined(OS_SOLARIS)
  210. #define BUILDFLAG_INTERNAL_IS_SOLARIS() (1)
  211. #else
  212. #define BUILDFLAG_INTERNAL_IS_SOLARIS() (0)
  213. #endif
  214. #if defined(OS_WIN)
  215. #define BUILDFLAG_INTERNAL_IS_WIN() (1)
  216. #else
  217. #define BUILDFLAG_INTERNAL_IS_WIN() (0)
  218. #endif
  219. // Compiler detection. Note: clang masquerades as GCC on POSIX and as MSVC on
  220. // Windows.
  221. #if defined(__GNUC__)
  222. #define COMPILER_GCC 1
  223. #elif defined(_MSC_VER)
  224. #define COMPILER_MSVC 1
  225. #else
  226. #error Please add support for your compiler in build/build_config.h
  227. #endif
  228. // Processor architecture detection. For more info on what's defined, see:
  229. // http://msdn.microsoft.com/en-us/library/b0084kay.aspx
  230. // http://www.agner.org/optimize/calling_conventions.pdf
  231. // or with gcc, run: "echo | gcc -E -dM -"
  232. #if defined(_M_X64) || defined(__x86_64__)
  233. #define ARCH_CPU_X86_FAMILY 1
  234. #define ARCH_CPU_X86_64 1
  235. #define ARCH_CPU_64_BITS 1
  236. #define ARCH_CPU_LITTLE_ENDIAN 1
  237. #elif defined(_M_IX86) || defined(__i386__)
  238. #define ARCH_CPU_X86_FAMILY 1
  239. #define ARCH_CPU_X86 1
  240. #define ARCH_CPU_32_BITS 1
  241. #define ARCH_CPU_LITTLE_ENDIAN 1
  242. #elif defined(__s390x__)
  243. #define ARCH_CPU_S390_FAMILY 1
  244. #define ARCH_CPU_S390X 1
  245. #define ARCH_CPU_64_BITS 1
  246. #define ARCH_CPU_BIG_ENDIAN 1
  247. #elif defined(__s390__)
  248. #define ARCH_CPU_S390_FAMILY 1
  249. #define ARCH_CPU_S390 1
  250. #define ARCH_CPU_31_BITS 1
  251. #define ARCH_CPU_BIG_ENDIAN 1
  252. #elif (defined(__PPC64__) || defined(__PPC__)) && defined(__BIG_ENDIAN__)
  253. #define ARCH_CPU_PPC64_FAMILY 1
  254. #define ARCH_CPU_PPC64 1
  255. #define ARCH_CPU_64_BITS 1
  256. #define ARCH_CPU_BIG_ENDIAN 1
  257. #elif defined(__PPC64__)
  258. #define ARCH_CPU_PPC64_FAMILY 1
  259. #define ARCH_CPU_PPC64 1
  260. #define ARCH_CPU_64_BITS 1
  261. #define ARCH_CPU_LITTLE_ENDIAN 1
  262. #elif defined(__ARMEL__)
  263. #define ARCH_CPU_ARM_FAMILY 1
  264. #define ARCH_CPU_ARMEL 1
  265. #define ARCH_CPU_32_BITS 1
  266. #define ARCH_CPU_LITTLE_ENDIAN 1
  267. #elif defined(__aarch64__) || defined(_M_ARM64)
  268. #define ARCH_CPU_ARM_FAMILY 1
  269. #define ARCH_CPU_ARM64 1
  270. #define ARCH_CPU_64_BITS 1
  271. #define ARCH_CPU_LITTLE_ENDIAN 1
  272. #elif defined(__pnacl__) || defined(__asmjs__) || defined(__wasm__)
  273. #define ARCH_CPU_32_BITS 1
  274. #define ARCH_CPU_LITTLE_ENDIAN 1
  275. #elif defined(__MIPSEL__)
  276. #if defined(__LP64__)
  277. #define ARCH_CPU_MIPS_FAMILY 1
  278. #define ARCH_CPU_MIPS64EL 1
  279. #define ARCH_CPU_64_BITS 1
  280. #define ARCH_CPU_LITTLE_ENDIAN 1
  281. #else
  282. #define ARCH_CPU_MIPS_FAMILY 1
  283. #define ARCH_CPU_MIPSEL 1
  284. #define ARCH_CPU_32_BITS 1
  285. #define ARCH_CPU_LITTLE_ENDIAN 1
  286. #endif
  287. #elif defined(__MIPSEB__)
  288. #if defined(__LP64__)
  289. #define ARCH_CPU_MIPS_FAMILY 1
  290. #define ARCH_CPU_MIPS64 1
  291. #define ARCH_CPU_64_BITS 1
  292. #define ARCH_CPU_BIG_ENDIAN 1
  293. #else
  294. #define ARCH_CPU_MIPS_FAMILY 1
  295. #define ARCH_CPU_MIPS 1
  296. #define ARCH_CPU_32_BITS 1
  297. #define ARCH_CPU_BIG_ENDIAN 1
  298. #endif
  299. #elif defined(__loongarch32)
  300. #define ARCH_CPU_LOONG_FAMILY 1
  301. #define ARCH_CPU_LOONG32 1
  302. #define ARCH_CPU_32_BITS 1
  303. #define ARCH_CPU_LITTLE_ENDIAN 1
  304. #elif defined(__loongarch64)
  305. #define ARCH_CPU_LOONG_FAMILY 1
  306. #define ARCH_CPU_LOONG64 1
  307. #define ARCH_CPU_64_BITS 1
  308. #define ARCH_CPU_LITTLE_ENDIAN 1
  309. #elif defined(__riscv) && (__riscv_xlen == 64)
  310. #define ARCH_CPU_RISCV_FAMILY 1
  311. #define ARCH_CPU_RISCV64 1
  312. #define ARCH_CPU_64_BITS 1
  313. #define ARCH_CPU_LITTLE_ENDIAN 1
  314. #else
  315. #error Please add support for your architecture in build/build_config.h
  316. #endif
  317. // Type detection for wchar_t.
  318. #if defined(OS_WIN)
  319. #define WCHAR_T_IS_UTF16
  320. #elif defined(OS_FUCHSIA)
  321. #define WCHAR_T_IS_UTF32
  322. #elif defined(OS_POSIX) && defined(COMPILER_GCC) && defined(__WCHAR_MAX__) && \
  323. (__WCHAR_MAX__ == 0x7fffffff || __WCHAR_MAX__ == 0xffffffff)
  324. #define WCHAR_T_IS_UTF32
  325. #elif defined(OS_POSIX) && defined(COMPILER_GCC) && defined(__WCHAR_MAX__) && \
  326. (__WCHAR_MAX__ == 0x7fff || __WCHAR_MAX__ == 0xffff)
  327. // On Posix, we'll detect short wchar_t, but projects aren't guaranteed to
  328. // compile in this mode (in particular, Chrome doesn't). This is intended for
  329. // other projects using base who manage their own dependencies and make sure
  330. // short wchar works for them.
  331. #define WCHAR_T_IS_UTF16
  332. #else
  333. #error Please add support for your compiler in build/build_config.h
  334. #endif
  335. #if defined(OS_ANDROID)
  336. // The compiler thinks std::string::const_iterator and "const char*" are
  337. // equivalent types.
  338. #define STD_STRING_ITERATOR_IS_CHAR_POINTER
  339. // The compiler thinks std::u16string::const_iterator and "char16*" are
  340. // equivalent types.
  341. #define BASE_STRING16_ITERATOR_IS_CHAR16_POINTER
  342. #endif
  343. #endif // BUILD_BUILD_CONFIG_H_