1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
|
#pragma once
#if defined(__APPLE__)
#include <machine/endian.h>
#elif defined(linux) || defined(__linux__)
#include <endian.h>
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__)
#include <sys/endian.h>
#endif
namespace nall {
/* Compiler detection */
#if defined(__clang__)
#define COMPILER_CLANG
struct Compiler {
static constexpr bool Clang = 1;
static constexpr bool GCC = 0;
static constexpr bool Microsoft = 0;
};
#pragma clang diagnostic warning "-Wreturn-type"
#pragma clang diagnostic ignored "-Wunused-result"
#pragma clang diagnostic ignored "-Wunknown-pragmas"
#pragma clang diagnostic ignored "-Wempty-body"
#pragma clang diagnostic ignored "-Wparentheses"
#pragma clang diagnostic ignored "-Wswitch"
#pragma clang diagnostic ignored "-Wswitch-bool"
#pragma clang diagnostic ignored "-Wabsolute-value"
#pragma clang diagnostic ignored "-Wtrigraphs"
#pragma clang diagnostic ignored "-Wnarrowing"
#pragma clang diagnostic ignored "-Wattributes"
#elif defined(__GNUC__)
#define COMPILER_GCC
struct Compiler {
static constexpr bool Clang = 0;
static constexpr bool GCC = 1;
static constexpr bool Microsoft = 0;
};
#pragma GCC diagnostic warning "-Wreturn-type"
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#pragma GCC diagnostic ignored "-Wpragmas"
#pragma GCC diagnostic ignored "-Wswitch-bool"
#pragma GCC diagnostic ignored "-Wtrigraphs"
#pragma GCC diagnostic ignored "-Wnarrowing"
#pragma GCC diagnostic ignored "-Wattributes"
#pragma GCC diagnostic ignored "-Wstringop-overflow" //GCC 10.2 warning heuristic is buggy
#elif defined(_MSC_VER)
#define COMPILER_MICROSOFT
struct Compiler {
static constexpr bool Clang = 0;
static constexpr bool GCC = 0;
static constexpr bool Microsoft = 1;
};
#pragma warning(disable:4996) //libc "deprecation" warnings
#else
#error "unable to detect compiler"
#endif
/* Platform detection */
#if defined(_WIN32)
#define PLATFORM_WINDOWS
struct Platform {
static constexpr bool Windows = 1;
static constexpr bool MacOS = 0;
static constexpr bool Android = 0;
static constexpr bool Linux = 0;
static constexpr bool BSD = 0;
};
#elif defined(__APPLE__)
#define PLATFORM_MACOS
struct Platform {
static constexpr bool Windows = 0;
static constexpr bool MacOS = 1;
static constexpr bool Android = 0;
static constexpr bool Linux = 0;
static constexpr bool BSD = 0;
};
#elif defined(__ANDROID__)
#define PLATFORM_ANDROID
struct Platform {
static constexpr bool Windows = 0;
static constexpr bool MacOS = 0;
static constexpr bool Android = 1;
static constexpr bool Linux = 0;
static constexpr bool BSD = 0;
};
#elif defined(linux) || defined(__linux__)
#define PLATFORM_LINUX
struct Platform {
static constexpr bool Windows = 0;
static constexpr bool MacOS = 0;
static constexpr bool Android = 0;
static constexpr bool Linux = 1;
static constexpr bool BSD = 0;
};
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__)
#define PLATFORM_BSD
struct Platform {
static constexpr bool Windows = 0;
static constexpr bool MacOS = 0;
static constexpr bool Android = 0;
static constexpr bool Linux = 0;
static constexpr bool BSD = 1;
};
#else
#error "unable to detect platform"
#endif
/* ABI detection */
#if defined(_WIN32)
#define ABI_WINDOWS
struct ABI {
static constexpr bool Windows = 1;
static constexpr bool SystemV = 0;
};
#else
#define ABI_SYSTEMV
struct ABI {
static constexpr bool Windows = 0;
static constexpr bool SystemV = 1;
};
#endif
/* API detection */
#if defined(_WIN32)
#define API_WINDOWS
struct API {
static constexpr bool Windows = 1;
static constexpr bool Posix = 0;
};
#else
#define API_POSIX
struct API {
static constexpr bool Windows = 0;
static constexpr bool Posix = 1;
};
#endif
/* Display server detection */
#if defined(_WIN32)
#define DISPLAY_WINDOWS
struct DisplayServer {
static constexpr bool Windows = 1;
static constexpr bool Quartz = 0;
static constexpr bool Xorg = 0;
};
#elif defined(__APPLE__)
#define DISPLAY_QUARTZ
struct DisplayServer {
static constexpr bool Windows = 0;
static constexpr bool Quartz = 1;
static constexpr bool Xorg = 0;
};
#else
#define DISPLAY_XORG
struct DisplayServer {
static constexpr bool Windows = 0;
static constexpr bool Quartz = 0;
static constexpr bool Xorg = 1;
};
#endif
/* Architecture detection */
#if defined(__i386__) || defined(_M_IX86)
#define ARCHITECTURE_X86
struct Architecture {
static constexpr bool x86 = 1;
static constexpr bool amd64 = 0;
static constexpr bool arm64 = 0;
static constexpr bool arm32 = 0;
static constexpr bool ppc64 = 0;
static constexpr bool ppc32 = 0;
};
#elif defined(__amd64__) || defined(_M_AMD64)
#define ARCHITECTURE_AMD64
struct Architecture {
static constexpr bool x86 = 0;
static constexpr bool amd64 = 1;
static constexpr bool arm64 = 0;
static constexpr bool arm32 = 0;
static constexpr bool ppc64 = 0;
static constexpr bool ppc32 = 0;
};
#elif defined(__aarch64__)
#define ARCHITECTURE_ARM64
struct Architecture {
static constexpr bool x86 = 0;
static constexpr bool amd64 = 0;
static constexpr bool arm64 = 1;
static constexpr bool arm32 = 0;
static constexpr bool ppc64 = 0;
static constexpr bool ppc32 = 0;
};
#elif defined(__arm__)
#define ARCHITECTURE_ARM32
struct Architecture {
static constexpr bool x86 = 0;
static constexpr bool amd64 = 0;
static constexpr bool arm64 = 0;
static constexpr bool arm32 = 1;
static constexpr bool ppc64 = 0;
static constexpr bool ppc32 = 0;
};
#elif defined(__ppc64__) || defined(_ARCH_PPC64)
#define ARCHITECTURE_PPC64
struct Architecture {
static constexpr bool x86 = 0;
static constexpr bool amd64 = 0;
static constexpr bool arm64 = 0;
static constexpr bool arm32 = 0;
static constexpr bool ppc64 = 1;
static constexpr bool ppc32 = 0;
};
#elif defined(__ppc__) || defined(_ARCH_PPC) || defined(_M_PPC)
#define ARCHITECTURE_PPC32
struct Architecture {
static constexpr bool x86 = 0;
static constexpr bool amd64 = 0;
static constexpr bool arm64 = 0;
static constexpr bool arm32 = 0;
static constexpr bool ppc64 = 0;
static constexpr bool ppc32 = 1;
};
#else
#warning "unable to detect architecture"
#define ARCHITECTURE_UNKNOWN
struct Architecture {
static constexpr bool x86 = 0;
static constexpr bool amd64 = 0;
static constexpr bool arm64 = 0;
static constexpr bool arm32 = 0;
static constexpr bool ppc64 = 0;
static constexpr bool ppc32 = 0;
};
#endif
/* Endian detection */
#if (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && __BYTE_ORDER == __LITTLE_ENDIAN) || defined(__LITTLE_ENDIAN__) || defined(__i386__) || defined(__amd64__) || defined(_M_IX86) || defined(_M_AMD64)
#define ENDIAN_LITTLE
struct Endian {
static constexpr bool Little = 1;
static constexpr bool Big = 0;
};
#elif (defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && __BYTE_ORDER == __BIG_ENDIAN) || defined(__BIG_ENDIAN__) || defined(__powerpc__) || defined(_M_PPC)
#define ENDIAN_BIG
struct Endian {
static constexpr bool Little = 0;
static constexpr bool Big = 1;
};
#else
#error "unable to detect endian"
#endif
/* Build optimization level detection */
#undef DEBUG
#undef NDEBUG
#if defined(BUILD_DEBUG)
#define DEBUG
struct Build {
static constexpr bool Debug = 1;
static constexpr bool Stable = 0;
static constexpr bool Minified = 0;
static constexpr bool Release = 0;
static constexpr bool Optimized = 0;
};
#elif defined(BUILD_STABLE)
#define DEBUG
struct Build {
static constexpr bool Debug = 0;
static constexpr bool Stable = 1;
static constexpr bool Minified = 0;
static constexpr bool Release = 0;
static constexpr bool Optimized = 0;
};
#elif defined(BUILD_MINIFIED)
#define NDEBUG
struct Build {
static constexpr bool Debug = 0;
static constexpr bool Stable = 0;
static constexpr bool Minified = 1;
static constexpr bool Release = 0;
static constexpr bool Optimized = 0;
};
#elif defined(BUILD_RELEASE)
#define NDEBUG
struct Build {
static constexpr bool Debug = 0;
static constexpr bool Stable = 0;
static constexpr bool Minified = 0;
static constexpr bool Release = 1;
static constexpr bool Optimized = 0;
};
#elif defined(BUILD_OPTIMIZED)
#define NDEBUG
struct Build {
static constexpr bool Debug = 0;
static constexpr bool Stable = 0;
static constexpr bool Minified = 0;
static constexpr bool Release = 0;
static constexpr bool Optimized = 1;
};
#else
//default to debug mode
#define BUILD_DEBUG
#define DEBUG
struct Build {
static constexpr bool Debug = 1;
static constexpr bool Stable = 0;
static constexpr bool Minified = 0;
static constexpr bool Release = 0;
static constexpr bool Optimized = 0;
};
#endif
}
|