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.
5 // This file doesn't belong to any GN target by design for faster build and
6 // less developer overhead.
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)
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
27 // This file also adds defines specific to the platform, architecture etc.
33 // COMPILER_MSVC / COMPILER_GCC
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
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
52 #ifndef BUILD_BUILD_CONFIG_H_
53 #define BUILD_BUILD_CONFIG_H_
55 #include "build/buildflag.h" // IWYU pragma: export
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.
61 #elif defined(ANDROID)
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
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
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.
83 #endif // !defined(OS_CHROMEOS)
84 // Include a system header to pull in features.h for glibc/uclibc macros.
86 #if defined(__GLIBC__) && !defined(__UCLIBC__)
87 // We really are using glibc, not uClibc pretending to be glibc.
92 #elif defined(__Fuchsia__)
94 #elif defined(__FreeBSD__)
96 #elif defined(__NetBSD__)
98 #elif defined(__OpenBSD__)
102 #elif defined(__QNXNTO__)
106 #elif defined(__asmjs__) || defined(__wasm__)
108 #elif defined(__MVS__)
111 #error Please add support for your platform in build/build_config.h
113 // NOTE: Adding a new port? Please follow
114 // https://chromium.googlesource.com/chromium/src/+/main/docs/new_port_policy.md
116 #if defined(OS_MAC) || defined(OS_IOS)
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)
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)
137 #if defined(OS_TIZEN)
138 #define BUILDFLAG_INTERNAL_IS_TIZEN() (1)
140 #define BUILDFLAG_INTERNAL_IS_TIZEN() (0)
143 #if defined(USE_CLANG)
144 #define BUILDFLAG_INTERNAL_IS_CLANG() (1)
146 #define BUILDFLAG_INTERNAL_IS_CLANG() (0)
149 #if defined(OS_TIZEN_TV_PRODUCT)
150 #define BUILDFLAG_INTERNAL_IS_TIZEN_TV() (1)
152 #define BUILDFLAG_INTERNAL_IS_TIZEN_TV() (0)
155 #if defined(OS_TIZEN_DA_PRODUCT)
156 #define BUILDFLAG_INTERNAL_IS_TIZEN_DA() (1)
158 #define BUILDFLAG_INTERNAL_IS_TIZEN_DA() (0)
162 #define BUILDFLAG_INTERNAL_IS_EFL() (1)
164 #define BUILDFLAG_INTERNAL_IS_EFL() (0)
168 #define BUILDFLAG_INTERNAL_IS_AIX() (1)
170 #define BUILDFLAG_INTERNAL_IS_AIX() (0)
173 #if defined(OS_ANDROID)
174 #define BUILDFLAG_INTERNAL_IS_ANDROID() (1)
176 #define BUILDFLAG_INTERNAL_IS_ANDROID() (0)
179 #if defined(OS_APPLE)
180 #define BUILDFLAG_INTERNAL_IS_APPLE() (1)
182 #define BUILDFLAG_INTERNAL_IS_APPLE() (0)
185 #if defined(OS_ASMJS)
186 #define BUILDFLAG_INTERNAL_IS_ASMJS() (1)
188 #define BUILDFLAG_INTERNAL_IS_ASMJS() (0)
192 #define BUILDFLAG_INTERNAL_IS_BSD() (1)
194 #define BUILDFLAG_INTERNAL_IS_BSD() (0)
197 #if defined(OS_CHROMEOS)
198 #define BUILDFLAG_INTERNAL_IS_CHROMEOS() (1)
200 #define BUILDFLAG_INTERNAL_IS_CHROMEOS() (0)
203 #if defined(OS_FREEBSD)
204 #define BUILDFLAG_INTERNAL_IS_FREEBSD() (1)
206 #define BUILDFLAG_INTERNAL_IS_FREEBSD() (0)
209 #if defined(OS_FUCHSIA)
210 #define BUILDFLAG_INTERNAL_IS_FUCHSIA() (1)
212 #define BUILDFLAG_INTERNAL_IS_FUCHSIA() (0)
216 #define BUILDFLAG_INTERNAL_IS_IOS() (1)
218 #define BUILDFLAG_INTERNAL_IS_IOS() (0)
221 #if defined(OS_IOS_MACCATALYST)
222 #define BUILDFLAG_INTERNAL_IS_IOS_MACCATALYST() (1)
224 #define BUILDFLAG_INTERNAL_IS_IOS_MACCATALYST() (0)
227 #if defined(OS_LINUX)
228 #define BUILDFLAG_INTERNAL_IS_LINUX() (1)
230 #define BUILDFLAG_INTERNAL_IS_LINUX() (0)
234 #define BUILDFLAG_INTERNAL_IS_MAC() (1)
236 #define BUILDFLAG_INTERNAL_IS_MAC() (0)
240 #define BUILDFLAG_INTERNAL_IS_NACL() (1)
242 #define BUILDFLAG_INTERNAL_IS_NACL() (0)
245 #if defined(OS_NETBSD)
246 #define BUILDFLAG_INTERNAL_IS_NETBSD() (1)
248 #define BUILDFLAG_INTERNAL_IS_NETBSD() (0)
251 #if defined(OS_OPENBSD)
252 #define BUILDFLAG_INTERNAL_IS_OPENBSD() (1)
254 #define BUILDFLAG_INTERNAL_IS_OPENBSD() (0)
257 #if defined(OS_POSIX)
258 #define BUILDFLAG_INTERNAL_IS_POSIX() (1)
260 #define BUILDFLAG_INTERNAL_IS_POSIX() (0)
264 #define BUILDFLAG_INTERNAL_IS_QNX() (1)
266 #define BUILDFLAG_INTERNAL_IS_QNX() (0)
269 #if defined(OS_SOLARIS)
270 #define BUILDFLAG_INTERNAL_IS_SOLARIS() (1)
272 #define BUILDFLAG_INTERNAL_IS_SOLARIS() (0)
276 #define BUILDFLAG_INTERNAL_IS_WIN() (1)
278 #define BUILDFLAG_INTERNAL_IS_WIN() (0)
281 #if defined(USE_OZONE)
282 #define BUILDFLAG_INTERNAL_IS_OZONE() (1)
284 #define BUILDFLAG_INTERNAL_IS_OZONE() (0)
287 // Compiler detection. Note: clang masquerades as GCC on POSIX and as MSVC on
289 #if defined(__GNUC__)
290 #define COMPILER_GCC 1
291 #elif defined(_MSC_VER)
292 #define COMPILER_MSVC 1
294 #error Please add support for your compiler in build/build_config.h
297 // Processor architecture detection. For more info on what's defined, see:
298 // http://msdn.microsoft.com/en-us/library/b0084kay.aspx
299 // http://www.agner.org/optimize/calling_conventions.pdf
300 // or with gcc, run: "echo | gcc -E -dM -"
301 #if defined(_M_X64) || defined(__x86_64__)
302 #define ARCH_CPU_X86_FAMILY 1
303 #define ARCH_CPU_X86_64 1
304 #define ARCH_CPU_64_BITS 1
305 #define ARCH_CPU_LITTLE_ENDIAN 1
306 #elif defined(_M_IX86) || defined(__i386__)
307 #define ARCH_CPU_X86_FAMILY 1
308 #define ARCH_CPU_X86 1
309 #define ARCH_CPU_32_BITS 1
310 #define ARCH_CPU_LITTLE_ENDIAN 1
311 #elif defined(__s390x__)
312 #define ARCH_CPU_S390_FAMILY 1
313 #define ARCH_CPU_S390X 1
314 #define ARCH_CPU_64_BITS 1
315 #define ARCH_CPU_BIG_ENDIAN 1
316 #elif defined(__s390__)
317 #define ARCH_CPU_S390_FAMILY 1
318 #define ARCH_CPU_S390 1
319 #define ARCH_CPU_31_BITS 1
320 #define ARCH_CPU_BIG_ENDIAN 1
321 #elif (defined(__PPC64__) || defined(__PPC__)) && defined(__BIG_ENDIAN__)
322 #define ARCH_CPU_PPC64_FAMILY 1
323 #define ARCH_CPU_PPC64 1
324 #define ARCH_CPU_64_BITS 1
325 #define ARCH_CPU_BIG_ENDIAN 1
326 #elif defined(__PPC64__)
327 #define ARCH_CPU_PPC64_FAMILY 1
328 #define ARCH_CPU_PPC64 1
329 #define ARCH_CPU_64_BITS 1
330 #define ARCH_CPU_LITTLE_ENDIAN 1
331 #elif defined(__ARMEL__)
332 #define ARCH_CPU_ARM_FAMILY 1
333 #define ARCH_CPU_ARMEL 1
334 #define ARCH_CPU_32_BITS 1
335 #define ARCH_CPU_LITTLE_ENDIAN 1
336 #elif defined(__aarch64__) || defined(_M_ARM64)
337 #define ARCH_CPU_ARM_FAMILY 1
338 #define ARCH_CPU_ARM64 1
339 #define ARCH_CPU_64_BITS 1
340 #define ARCH_CPU_LITTLE_ENDIAN 1
341 #elif defined(__pnacl__) || defined(__asmjs__) || defined(__wasm__)
342 #define ARCH_CPU_32_BITS 1
343 #define ARCH_CPU_LITTLE_ENDIAN 1
344 #elif defined(__MIPSEL__)
345 #if defined(__LP64__)
346 #define ARCH_CPU_MIPS_FAMILY 1
347 #define ARCH_CPU_MIPS64EL 1
348 #define ARCH_CPU_64_BITS 1
349 #define ARCH_CPU_LITTLE_ENDIAN 1
351 #define ARCH_CPU_MIPS_FAMILY 1
352 #define ARCH_CPU_MIPSEL 1
353 #define ARCH_CPU_32_BITS 1
354 #define ARCH_CPU_LITTLE_ENDIAN 1
356 #elif defined(__MIPSEB__)
357 #if defined(__LP64__)
358 #define ARCH_CPU_MIPS_FAMILY 1
359 #define ARCH_CPU_MIPS64 1
360 #define ARCH_CPU_64_BITS 1
361 #define ARCH_CPU_BIG_ENDIAN 1
363 #define ARCH_CPU_MIPS_FAMILY 1
364 #define ARCH_CPU_MIPS 1
365 #define ARCH_CPU_32_BITS 1
366 #define ARCH_CPU_BIG_ENDIAN 1
368 #elif defined(__loongarch__)
369 #define ARCH_CPU_LOONGARCH_FAMILY 1
370 #define ARCH_CPU_LITTLE_ENDIAN 1
371 #if __loongarch_grlen == 64
372 #define ARCH_CPU_LOONGARCH64 1
373 #define ARCH_CPU_64_BITS 1
375 #define ARCH_CPU_LOONGARCH32 1
376 #define ARCH_CPU_32_BITS 1
378 #elif defined(__riscv) && (__riscv_xlen == 64)
379 #define ARCH_CPU_RISCV_FAMILY 1
380 #define ARCH_CPU_RISCV64 1
381 #define ARCH_CPU_64_BITS 1
382 #define ARCH_CPU_LITTLE_ENDIAN 1
384 #error Please add support for your architecture in build/build_config.h
387 // Type detection for wchar_t.
389 #define WCHAR_T_IS_UTF16
390 #elif defined(OS_FUCHSIA)
391 #define WCHAR_T_IS_UTF32
392 #elif defined(OS_POSIX) && defined(COMPILER_GCC) && defined(__WCHAR_MAX__) && \
393 (__WCHAR_MAX__ == 0x7fffffff || __WCHAR_MAX__ == 0xffffffff)
394 #define WCHAR_T_IS_UTF32
395 #elif defined(OS_POSIX) && defined(COMPILER_GCC) && defined(__WCHAR_MAX__) && \
396 (__WCHAR_MAX__ == 0x7fff || __WCHAR_MAX__ == 0xffff)
397 // On Posix, we'll detect short wchar_t, but projects aren't guaranteed to
398 // compile in this mode (in particular, Chrome doesn't). This is intended for
399 // other projects using base who manage their own dependencies and make sure
400 // short wchar works for them.
401 #define WCHAR_T_IS_UTF16
403 #error Please add support for your compiler in build/build_config.h
406 #if defined(OS_ANDROID)
407 // The compiler thinks std::string::const_iterator and "const char*" are
409 #define STD_STRING_ITERATOR_IS_CHAR_POINTER
410 // The compiler thinks std::u16string::const_iterator and "char16*" are
412 #define BASE_STRING16_ITERATOR_IS_CHAR16_POINTER
415 #endif // BUILD_BUILD_CONFIG_H_