HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
defines.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_BASE_ARCH_DEFINES_H
8 #define PXR_BASE_ARCH_DEFINES_H
9 
10 //
11 // OS
12 //
13 #if defined(__EMSCRIPTEN__)
14 #define ARCH_OS_WASM_VM
15 #elif defined(__linux__)
16 #define ARCH_OS_LINUX
17 #elif defined(__APPLE__)
18 #include "TargetConditionals.h"
19 #define ARCH_OS_DARWIN
20 #if TARGET_OS_IPHONE
21 // TARGET_OS_IPHONE refers to all iOS derivative platforms
22 // TARGET_OS_IOS refers to iPhone/iPad
23 // For now, we specialize for the umbrella TARGET_OS_IPHONE group
24 #define ARCH_OS_IPHONE
25 #else
26 #define ARCH_OS_OSX
27 #endif
28 #elif defined(_WIN32) || defined(_WIN64)
29 #define ARCH_OS_WINDOWS
30 #endif
31 
32 //
33 // Processor
34 //
35 
36 #if defined(i386) || defined(__i386__) || defined(__x86_64__) || \
37  defined(_M_IX86) || defined(_M_X64)
38 #define ARCH_CPU_INTEL
39 #elif defined(__arm__) || defined(__aarch64__) || defined(_M_ARM) || \
40  defined(_M_ARM64)
41 #define ARCH_CPU_ARM
42 #endif
43 
44 //
45 // Bits
46 //
47 
48 #if defined(__x86_64__) || defined(__aarch64__) || defined(_M_X64) || \
49  defined(_M_ARM64) || defined(__wasm64__)
50 #define ARCH_BITS_64
51 #elif defined(__wasm32__)
52 #define ARCH_BITS_32
53 #else
54 #error "Unsupported architecture. x86_64 or ARM64 required."
55 #endif
56 
57 //
58 // Compiler
59 //
60 
61 #if defined(__clang__)
62 #define ARCH_COMPILER_CLANG
63 #define ARCH_COMPILER_CLANG_MAJOR __clang_major__
64 #define ARCH_COMPILER_CLANG_MINOR __clang_minor__
65 #define ARCH_COMPILER_CLANG_PATCHLEVEL __clang_patchlevel__
66 #elif defined(__GNUC__)
67 #define ARCH_COMPILER_GCC
68 #define ARCH_COMPILER_GCC_MAJOR __GNUC__
69 #define ARCH_COMPILER_GCC_MINOR __GNUC_MINOR__
70 #define ARCH_COMPILER_GCC_PATCHLEVEL __GNUC_PATCHLEVEL__
71 #elif defined(__ICC)
72 #define ARCH_COMPILER_ICC
73 #elif defined(_MSC_VER)
74 #define ARCH_COMPILER_MSVC
75 #define ARCH_COMPILER_MSVC_VERSION _MSC_VER
76 #endif
77 
78 //
79 // Features
80 //
81 
82 // Only use the GNU STL extensions on Linux when using gcc.
83 #if defined(ARCH_OS_LINUX) && defined(ARCH_COMPILER_GCC)
84 #define ARCH_HAS_GNU_STL_EXTENSIONS
85 #endif
86 
87 // The MAP_POPULATE flag for mmap calls only exists on Linux platforms.
88 #if defined(ARCH_OS_LINUX)
89 #define ARCH_HAS_MMAP_MAP_POPULATE
90 #endif
91 
92 // When using MSVC, provide an easy way to detect whether the older
93 // "traditional" preprocessor is being used as opposed to the newer, more
94 // standards-conforming preprocessor. The traditional preprocessor may require
95 // custom versions of macros.
96 // See here for more detail about MSVC's preprocessors:
97 // https://learn.microsoft.com/en-us/cpp/preprocessor/preprocessor-experimental-overview
98 #if defined(ARCH_COMPILER_MSVC)
99  #if !defined(_MSVC_TRADITIONAL) || _MSVC_TRADITIONAL
100  #define ARCH_PREPROCESSOR_MSVC_TRADITIONAL
101  #endif
102 #endif
103 
104 //
105 // Sanitizers
106 //
107 
108 // For most compilers sanitizers are enabled with something similar to
109 // -fsanitize={address,thread,undefined}.
110 // But detecting if the compiler is currently trying to make a sanitized build
111 // can vary depending on the compiler (or between versions of the compiler).
112 // The following checks will determine if the compiler is making a sanitized
113 // build and set a definition if so.
114 //
115 // These definitions can be used to conditionally compile code where
116 // instrumentation from the sanitizer needs augmentation; for instance
117 // building a test for bad memory allocations when using address
118 // sanitizers. Such a test would produce a false-positive from
119 // address sanitizer at run-time resulting in a failed test.
120 //
121 // The definitions will only be defined if the compiler is actually
122 // building with a specific sanitizer. The absence of a definition
123 // means the compiler is not building with that sanitizer.
124 #if defined(ARCH_COMPILER_CLANG)
125  #if defined(__has_feature)
126  #if __has_feature(address_sanitizer)
127  #define ARCH_SANITIZE_ADDRESS
128  #endif
129 
130  // Definitions for other sanitizers intentionally
131  // omitted here
132 
133  #endif
134 #elif defined(ARCH_COMPILER_GCC)
135  #if defined(__has_feature)
136  #if __has_feature(address_sanitizer)
137  #define ARCH_SANITIZE_ADDRESS
138  #endif
139 
140  // Definitions for other sanitizers intentionally
141  // omitted here
142 
143  #else
144  #if defined(__SANITIZE_ADDRESS__)
145  #define ARCH_SANITIZE_ADDRESS
146  #endif
147 
148  // Definitions for other sanitizers intentionally
149  // omitted here
150 
151  #endif
152 #elif defined(ARCH_COMPILER_MSVC)
153  #if defined(__SANITIZE_ADDRESS__)
154  #define ARCH_SANITIZE_ADDRESS
155  #endif
156 
157  // Definitions for other sanitizers intentionally
158  // omitted here
159 #endif
160 
161 #endif // PXR_BASE_ARCH_DEFINES_H