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