Blender  V2.93
numaapi/source/build_config.h
Go to the documentation of this file.
1 // Copyright (c) 2018, libnumaapi authors
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to
5 // deal in the Software without restriction, including without limitation the
6 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 // sell copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 // IN THE SOFTWARE.
20 //
21 // Author: Sergey Sharybin <sergey.vfx@gmail.com>
22 
23 #ifndef __BUILD_CONFIG_H__
24 #define __BUILD_CONFIG_H__
25 
26 #include <limits.h>
27 #include <stdint.h>
28 
29 // Initially is based on Chromium's build_config.h, with tweaks and extensions
30 // needed for this project.
31 //
32 // NOTE: All commonly used symbols (which are checked on a "top" level, from
33 // outside of any platform-specific ifdef block) are to be explicitly defined
34 // to 0 when they are not "active". This is extra lines of code in this file,
35 // but is not being edited that often. Such approach helps catching cases when
36 // one attempted to access build configuration variable without including the
37 // header by simply using -Wundef compiler attribute.
38 //
39 // NOTE: Not having things explicitly defined to 0 is harmless (in terms it
40 // follows same rules as Google projects) and will simply cause compiler to
41 // become more noisy, which is simple to correct.
42 
44 // A set of macros to use for platform detection.
45 
46 #if defined(__native_client__)
47 // __native_client__ must be first, so that other OS_ defines are not set.
48 # define OS_NACL 1
49 // OS_NACL comes in two sandboxing technology flavors, SFI or Non-SFI.
50 // PNaCl toolchain defines __native_client_nonsfi__ macro in Non-SFI build
51 // mode, while it does not in SFI build mode.
52 # if defined(__native_client_nonsfi__)
53 # define OS_NACL_NONSFI
54 # else
55 # define OS_NACL_SFI
56 # endif
57 #elif defined(_AIX)
58 # define OS_AIX 1
59 #elif defined(ANDROID)
60 # define OS_ANDROID 1
61 #elif defined(__APPLE__)
62 // Only include TargetConditions after testing ANDROID as some android builds
63 // on mac don't have this header available and it's not needed unless the target
64 // is really mac/ios.
65 # include <TargetConditionals.h>
66 # define OS_MACOSX 1
67 # if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
68 # define OS_IOS 1
69 # endif // defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
70 #elif defined(__HAIKU__)
71 # define OS_HAIKU 1
72 #elif defined(__hpux)
73 # define OS_HPUX 1
74 #elif defined(__linux__)
75 # define OS_LINUX 1
76 // Include a system header to pull in features.h for glibc/uclibc macros.
77 # include <unistd.h>
78 # if defined(__GLIBC__) && !defined(__UCLIBC__)
79 // We really are using glibc, not uClibc pretending to be glibc.
80 # define LIBC_GLIBC 1
81 # endif
82 #elif defined(__sgi)
83 # define OS_IRIX 1
84 #elif defined(_WIN32)
85 # define OS_WIN 1
86 #elif defined(__Fuchsia__)
87 # define OS_FUCHSIA 1
88 #elif defined(__FreeBSD__)
89 # define OS_FREEBSD 1
90 #elif defined(__NetBSD__)
91 # define OS_NETBSD 1
92 #elif defined(__OpenBSD__)
93 # define OS_OPENBSD 1
94 #elif defined(__sun)
95 # define OS_SOLARIS 1
96 #elif defined(__QNXNTO__)
97 # define OS_QNX 1
98 #elif defined(__asmjs__) || defined(__wasm__)
99 # define OS_ASMJS 1
100 #else
101 # error Please add support for your platform in build_config.h
102 #endif
103 
104 #if !defined(OS_AIX)
105 # define OS_AIX 0
106 #endif
107 #if !defined(OS_ASMJS)
108 # define OS_ASMJS 0
109 #endif
110 #if !defined(OS_NACL)
111 # define OS_NACL 0
112 #endif
113 #if !defined(OS_NACL_NONSFI)
114 # define OS_NACL_NONSFI 0
115 #endif
116 #if !defined(OS_NACL_SFI)
117 # define OS_NACL_SFI 0
118 #endif
119 #if !defined(OS_ANDROID)
120 # define OS_ANDROID 0
121 #endif
122 #if !defined(OS_MACOSX)
123 # define OS_MACOSX 0
124 #endif
125 #if !defined(OS_IOS)
126 # define OS_IOS 0
127 #endif
128 #if !defined(OS_HAIKU)
129 # define OS_HAIKU 0
130 #endif
131 #if !defined(OS_HPUX)
132 # define OS_HPUX 0
133 #endif
134 #if !defined(OS_IRIX)
135 # define OS_IRIX 0
136 #endif
137 #if !defined(OS_LINUX)
138 # define OS_LINUX 0
139 #endif
140 #if !defined(LIBC_GLIBC)
141 # define LIBC_GLIBC 0
142 #endif
143 #if !defined(OS_WIN)
144 # define OS_WIN 0
145 #endif
146 #if !defined(OS_FUCHSIA)
147 # define OS_FUCHSIA 0
148 #endif
149 #if !defined(OS_FREEBSD)
150 # define OS_FREEBSD 0
151 #endif
152 #if !defined(OS_NETBSD)
153 # define OS_NETBSD 0
154 #endif
155 #if !defined(OS_OPENBSD)
156 # define OS_OPENBSD 0
157 #endif
158 #if !defined(OS_SOLARIS)
159 # define OS_SOLARIS 0
160 #endif
161 #if !defined(OS_QNX)
162 # define OS_QNX 0
163 #endif
164 
166 // *BSD OS family detection.
167 //
168 // For access to standard BSD features, use OS_BSD instead of a
169 // more specific macro.
170 #if OS_FREEBSD || OS_OPENBSD || OS_NETBSD
171 # define OS_BSD 1
172 #else
173 # define OS_BSD 0
174 #endif
175 
177 // POSIX system detection.
178 //
179 // For access to standard POSIXish features use OS_POSIX instead of a
180 // more specific macro.
181 #if OS_AIX || OS_ANDROID || OS_ASMJS || OS_FREEBSD || OS_LINUX || OS_MACOSX || \
182  OS_NACL || OS_NETBSD || OS_OPENBSD || OS_QNX || OS_SOLARIS
183 # define OS_POSIX 1
184 #else
185 # define OS_POSIX 0
186 #endif
187 
189 // Compiler detection, including its capabilities.
190 
191 #if defined(__clang__)
192 # define COMPILER_CLANG 1
193 #elif defined(__GNUC__)
194 # define COMPILER_GCC 1
195 # define COMPILER_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
196 #elif defined(_MSC_VER)
197 # define COMPILER_MSVC 1
198 # define COMPILER_MSVC_VERSION (_MSC_VER)
199 #elif defined(__MINGW32__)
200 # define COMPILER_MINGW32 1
201 #elif defined(__MINGW64__)
202 # define COMPILER_MINGW64 1
203 #else
204 # error Please add support for your compiler in build_config.h
205 #endif
206 
207 #if !defined(COMPILER_CLANG)
208 # define COMPILER_CLANG 0
209 #endif
210 #if !defined(COMPILER_GCC)
211 # define COMPILER_GCC 0
212 #endif
213 #if !defined(COMPILER_MSVC)
214 # define COMPILER_MSVC 0
215 #endif
216 #if !defined(COMPILER_MINGW32)
217 # define COMPILER_MINGW32 0
218 #endif
219 #if !defined(COMPILER_MINGW64)
220 # define COMPILER_MINGW64 0
221 #endif
222 
223 // Compiler is any of MinGW family.
224 #if COMPILER_MINGW32 || COMPILER_MINGW64
225 # define COMPILER_MINGW 1
226 #else
227 # define COMPILER_MINGW 0
228 #endif
229 
230 // Check what is the latest C++ specification the compiler supports.
231 //
232 // NOTE: Use explicit definition here to avoid expansion-to-defined warning from
233 // being geenrated. While this will most likely a false-positive warning in this
234 // particular case, that warning might be helpful to catch errors elsewhere.
235 
236 // C++11 check.
237 #if ((defined(__cplusplus) && (__cplusplus > 199711L)) || \
238  (defined(_MSC_VER) && (_MSC_VER >= 1800)))
239 # define COMPILER_SUPPORTS_CXX11 1
240 #else
241 # define COMPILER_SUPPORTS_CXX11 0
242 #endif
243 // C++14 check.
244 #if (defined(__cplusplus) && (__cplusplus > 201311L))
245 # define COMPILER_SUPPORTS_CXX14 1
246 #else
247 # define COMPILER_SUPPORTS_CXX14 0
248 #endif
249 // C++17 check.
250 #if (defined(__cplusplus) && (__cplusplus > 201611L))
251 # define COMPILER_SUPPORTS_CXX17 1
252 #else
253 # define COMPILER_SUPPORTS_CXX17 0
254 #endif
255 // C++20 check.
256 #if (defined(__cplusplus) && (__cplusplus > 201911L))
257 # define COMPILER_SUPPORTS_CXX20 1
258 #else
259 # define COMPILER_SUPPORTS_CXX20 0
260 #endif
261 
262 // COMPILER_USE_ADDRESS_SANITIZER is defined when program is detected that
263 // compilation happened wit haddress sanitizer enabled. This allows to give
264 // tips to sanitizer, or maybe work around some known issues with third party
265 // libraries.
266 #if !defined(COMPILER_USE_ADDRESS_SANITIZER)
267 # if defined(__has_feature)
268 # define COMPILER_USE_ADDRESS_SANITIZER 1
269 # elif defined(__SANITIZE_ADDRESS__)
270 # define COMPILER_USE_ADDRESS_SANITIZER 1
271 # endif
272 #endif
273 
274 #if !defined(COMPILER_USE_ADDRESS_SANITIZER)
275 # define COMPILER_USE_ADDRESS_SANITIZER 0
276 #endif
277 
279 // Processor architecture detection.
280 //
281 // For more info on what's defined, see:
282 //
283 // http://msdn.microsoft.com/en-us/library/b0084kay.aspx
284 // http://www.agner.org/optimize/calling_conventions.pdf
285 //
286 // or with gcc, run: "echo | gcc -E -dM -"
287 #if defined(_M_X64) || defined(__x86_64__)
288 # define ARCH_CPU_X86_FAMILY 1
289 # define ARCH_CPU_X86_64 1
290 # define ARCH_CPU_64_BITS 1
291 # define ARCH_CPU_LITTLE_ENDIAN 1
292 #elif defined(_M_IX86) || defined(__i386__)
293 # define ARCH_CPU_X86_FAMILY 1
294 # define ARCH_CPU_X86 1
295 # define ARCH_CPU_32_BITS 1
296 # define ARCH_CPU_LITTLE_ENDIAN 1
297 #elif defined(__s390x__)
298 # define ARCH_CPU_S390_FAMILY 1
299 # define ARCH_CPU_S390X 1
300 # define ARCH_CPU_64_BITS 1
301 # define ARCH_CPU_BIG_ENDIAN 1
302 #elif defined(__s390__)
303 # define ARCH_CPU_S390_FAMILY 1
304 # define ARCH_CPU_S390 1
305 # define ARCH_CPU_31_BITS 1
306 # define ARCH_CPU_BIG_ENDIAN 1
307 #elif (defined(__PPC64__) || defined(__PPC__)) && defined(__BIG_ENDIAN__)
308 # define ARCH_CPU_PPC64_FAMILY 1
309 # define ARCH_CPU_PPC64 1
310 # define ARCH_CPU_64_BITS 1
311 # define ARCH_CPU_BIG_ENDIAN 1
312 #elif defined(__PPC64__)
313 # define ARCH_CPU_PPC64_FAMILY 1
314 # define ARCH_CPU_PPC64 1
315 # define ARCH_CPU_64_BITS 1
316 # define ARCH_CPU_LITTLE_ENDIAN 1
317 #elif defined(__ARMEL__)
318 # define ARCH_CPU_ARM_FAMILY 1
319 # define ARCH_CPU_ARMEL 1
320 # define ARCH_CPU_32_BITS 1
321 # define ARCH_CPU_LITTLE_ENDIAN 1
322 #elif defined(__aarch64__) || defined(_M_ARM64)
323 # define ARCH_CPU_ARM_FAMILY 1
324 # define ARCH_CPU_ARM64 1
325 # define ARCH_CPU_64_BITS 1
326 # define ARCH_CPU_LITTLE_ENDIAN 1
327 #elif defined(__pnacl__) || defined(__asmjs__) || defined(__wasm__)
328 # define ARCH_CPU_32_BITS 1
329 # define ARCH_CPU_LITTLE_ENDIAN 1
330 #elif defined(__MIPSEL__)
331 # if defined(__LP64__)
332 # define ARCH_CPU_MIPS_FAMILY 1
333 # define ARCH_CPU_MIPS64EL 1
334 # define ARCH_CPU_64_BITS 1
335 # define ARCH_CPU_LITTLE_ENDIAN 1
336 # else
337 # define ARCH_CPU_MIPS_FAMILY 1
338 # define ARCH_CPU_MIPSEL 1
339 # define ARCH_CPU_32_BITS 1
340 # define ARCH_CPU_LITTLE_ENDIAN 1
341 # endif
342 #elif defined(__MIPSEB__)
343 # if defined(__LP64__)
344 # define ARCH_CPU_MIPS_FAMILY 1
345 # define ARCH_CPU_MIPS64 1
346 # define ARCH_CPU_64_BITS 1
347 # define ARCH_CPU_BIG_ENDIAN 1
348 # else
349 # define ARCH_CPU_MIPS_FAMILY 1
350 # define ARCH_CPU_MIPS 1
351 # define ARCH_CPU_32_BITS 1
352 # define ARCH_CPU_BIG_ENDIAN 1
353 # endif
354 #else
355 # error Please add support for your architecture in build_config.h
356 #endif
357 
358 #if !defined(ARCH_CPU_LITTLE_ENDIAN)
359 # define ARCH_CPU_LITTLE_ENDIAN 0
360 #endif
361 #if !defined(ARCH_CPU_BIG_ENDIAN)
362 # define ARCH_CPU_BIG_ENDIAN 0
363 #endif
364 
365 #if !defined(ARCH_CPU_32_BITS)
366 # define ARCH_CPU_32_BITS 0
367 #endif
368 #if !defined(ARCH_CPU_64_BITS)
369 # define ARCH_CPU_64_BITS 0
370 #endif
371 
372 #if !defined(ARCH_CPU_X86_FAMILY)
373 # define ARCH_CPU_X86_FAMILY 0
374 #endif
375 #if !defined(ARCH_CPU_ARM_FAMILY)
376 # define ARCH_CPU_ARM_FAMILY 0
377 #endif
378 #if !defined(ARCH_CPU_MIPS_FAMILY)
379 # define ARCH_CPU_MIPS_FAMILY 0
380 #endif
381 #if !defined(ARCH_CPU_PPC64_FAMILY)
382 # define ARCH_CPU_PPC64_FAMILY 0
383 #endif
384 #if !defined(ARCH_CPU_S390_FAMILY)
385 # define ARCH_CPU_S390_FAMILY 0
386 #endif
387 
389 // Sizes of platform-dependent types.
390 
391 #if defined(__SIZEOF_POINTER__)
392 # define PLATFORM_SIZEOF_PTR __SIZEOF_POINTER__
393 #elif defined(UINTPTR_MAX)
394 # if (UINTPTR_MAX == 0xffffffff)
395 # define PLATFORM_SIZEOF_PTR 4
396 # elif (UINTPTR_MAX == 0xffffffffffffffff) // NOLINT
397 # define PLATFORM_SIZEOF_PTR 8
398 # endif
399 #elif defined(__WORDSIZE)
400 # if (__WORDSIZE == 32)
401 # define PLATFORM_SIZEOF_PTR 4
402 # else if (__WORDSIZE == 64)
403 # define PLATFORM_SIZEOF_PTR 8
404 # endif
405 #endif
406 #if !defined(PLATFORM_SIZEOF_PTR)
407 # error Cannot find pointer size.
408 #endif
409 
410 #if (UINT_MAX == 0xffffffff)
411 # define PLATFORM_SIZEOF_INT 4
412 #elif (UINT_MAX == 0xffffffffffffffff) // NOLINT
413 # define PLATFORM_SIZEOF_INT 8
414 #else
415 # error Cannot find "int" size.
416 #endif
417 
418 #if (USHRT_MAX == 0xffffffff)
419 # define PLATFORM_SIZEOF_SHORT 4
420 #elif (USHRT_MAX == 0xffff) // NOLINT
421 # define PLATFORM_SIZEOF_SHORT 2
422 #else
423 # error Cannot find "short" size.
424 #endif
425 
426 #endif // __BUILD_CONFIG_H__