All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
defines.h
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
14#if defined(__linux__)
15#define ARCH_OS_LINUX
16#elif defined(__APPLE__)
17#include "TargetConditionals.h"
18#define ARCH_OS_DARWIN
19#if TARGET_OS_IPHONE
20// TARGET_OS_IPHONE refers to all iOS derivative platforms
21// TARGET_OS_IOS refers to iPhone/iPad
22// For now, we specialize for the umbrella TARGET_OS_IPHONE group
23#define ARCH_OS_IPHONE
24#else
25#define ARCH_OS_OSX
26#endif
27#elif defined(_WIN32) || defined(_WIN64)
28#define ARCH_OS_WINDOWS
29#endif
30
31//
32// Processor
33//
34
35#if defined(i386) || defined(__i386__) || defined(__x86_64__) || \
36 defined(_M_IX86) || defined(_M_X64)
37#define ARCH_CPU_INTEL
38#elif defined(__arm__) || defined(__aarch64__) || defined(_M_ARM)
39#define ARCH_CPU_ARM
40#endif
41
42//
43// Bits
44//
45
46#if defined(__x86_64__) || defined(__aarch64__) || defined(_M_X64)
47#define ARCH_BITS_64
48#else
49#error "Unsupported architecture. x86_64 or ARM64 required."
50#endif
51
52//
53// Compiler
54//
55
56#if defined(__clang__)
57#define ARCH_COMPILER_CLANG
58#define ARCH_COMPILER_CLANG_MAJOR __clang_major__
59#define ARCH_COMPILER_CLANG_MINOR __clang_minor__
60#define ARCH_COMPILER_CLANG_PATCHLEVEL __clang_patchlevel__
61#elif defined(__GNUC__)
62#define ARCH_COMPILER_GCC
63#define ARCH_COMPILER_GCC_MAJOR __GNUC__
64#define ARCH_COMPILER_GCC_MINOR __GNUC_MINOR__
65#define ARCH_COMPILER_GCC_PATCHLEVEL __GNUC_PATCHLEVEL__
66#elif defined(__ICC)
67#define ARCH_COMPILER_ICC
68#elif defined(_MSC_VER)
69#define ARCH_COMPILER_MSVC
70#define ARCH_COMPILER_MSVC_VERSION _MSC_VER
71#endif
72
73//
74// Features
75//
76
77// Only use the GNU STL extensions on Linux when using gcc.
78#if defined(ARCH_OS_LINUX) && defined(ARCH_COMPILER_GCC)
79#define ARCH_HAS_GNU_STL_EXTENSIONS
80#endif
81
82// The current version of Apple clang does not support the thread_local
83// keyword.
84#if !(defined(ARCH_OS_DARWIN) && defined(ARCH_COMPILER_CLANG))
85#define ARCH_HAS_THREAD_LOCAL
86#endif
87
88// The MAP_POPULATE flag for mmap calls only exists on Linux platforms.
89#if defined(ARCH_OS_LINUX)
90#define ARCH_HAS_MMAP_MAP_POPULATE
91#endif
92
93// When using MSVC, provide an easy way to detect whether the older
94// "traditional" preprocessor is being used as opposed to the newer, more
95// standards-conforming preprocessor. The traditional preprocessor may require
96// custom versions of macros.
97// See here for more detail about MSVC's preprocessors:
98// https://learn.microsoft.com/en-us/cpp/preprocessor/preprocessor-experimental-overview
99#if defined(ARCH_COMPILER_MSVC)
100 #if !defined(_MSVC_TRADITIONAL) || _MSVC_TRADITIONAL
101 #define ARCH_PREPROCESSOR_MSVC_TRADITIONAL
102 #endif
103#endif
104
105#endif // PXR_BASE_ARCH_DEFINES_H