Last active
April 28, 2020 20:17
-
-
Save luavixen/8fc76071f277b7a30fbffd36ed658525 to your computer and use it in GitHub Desktop.
Header file that detects and defines what platform you are compiling for
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) | |
#define PLATFORM_WINDOWS 1 | |
#define PLATFORM_NT 1 | |
#ifdef _WIN64 | |
#define PLATFORM_WINDOWS64 1 | |
#define PLATFORM_64 1 | |
#else | |
#define PLATFORM_WINDOWS32 1 | |
#define PLATFORM_32 1 | |
#endif | |
#elif defined(__APPLE__) | |
#include <TargetConditionals.h> | |
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR | |
#define PLATFORM_IOS 1 | |
#elif TARGET_OS_MAC | |
#define PLATFORM_MACOS 1 | |
#endif | |
#define PLATFORM_APPLE 1 | |
#define PLATFORM_NIX 1 | |
#elif defined(__linux__) | |
#define PLATFORM_LINUX 1 | |
#define PLATFORM_NIX 1 | |
#elif defined(__unix__) || defined(_POSIX_VERSION) | |
#define PLATFORM_NIX 1 | |
#else | |
#define PLATFORM_UNKNOWN 1 | |
#endif | |
#ifndef PLATFORM_WINDOWS | |
#if defined(__x86_64__) || defined(__aarch64__) || defined(__powerpc64__) || UINTPTR_MAX == 0xffffffffffffffff | |
#define PLATFORM_64 1 | |
#elif defined(__i386__) || defined(__arm__) || UINTPTR_MAX == 0xffffffff | |
#define PLATFORM_32 1 | |
#else | |
#define PLATFORM_UNKNOWNBITS 1 | |
#endif | |
#endif | |
#if PLATFORM_WINDOWS64 | |
#define PLATFORM_ARCH_WIN64 1 | |
#elif PLATFORM_WINDOWS32 | |
#define PLATFORM_ARCH_WIN32 1 | |
#elif PLATFORM_64 | |
#if defined(__x86_64__) | |
#define PLATFORM_ARCH_x86_64 1 | |
#elif defined(__aarch64__) | |
#define PLATFORM_ARCH_AARCH64 1 | |
#elif defined(__powerpc64__) | |
#define PLATFORM_ARCH_POWERPC64 1 | |
#else | |
#define PLATFORM_ARCH_64 1 | |
#endif | |
#elif PLATFORM_32 | |
#if defined(__i386__) | |
#define PLATFORM_ARCH_I386 1 | |
#elif defined(__arm_) | |
#define PLATFORM_ARCH_ARM 1 | |
#else | |
#define PLATFORM_ARCH_32 1 | |
#endif | |
#else | |
#define PLATFORM_ARCH_UNKNOWN 1 | |
#endif | |
#if PLATFORM_WINDOWS | |
#define PLATFORM_STR_OS "Windows" | |
#elif PLATFORM_MACOS | |
#define PLATFORM_STR_OS "macOS" | |
#elif PLATFORM_IOS | |
#define PLATFORM_STR_OS "iOS" | |
#elif PLATFORM_APPLE | |
#define PLATFORM_STR_OS "Apple" | |
#elif PLATFORM_LINUX | |
#define PLATFORM_STR_OS "Linux" | |
#elif PLATFORM_NIX | |
#define PLATFORM_STR_OS "UNIX-like" | |
#else | |
#define PLATFORM_STR_OS "Unknown" | |
#endif | |
#if PLATFORM_ARCH_WIN64 | |
#define PLATFORM_STR_ARCH "Win64" | |
#elif PLATFORM_ARCH_WIN32 | |
#define PLATFORM_STR_ARCH "Win32" | |
#elif PLATFORM_ARCH_x86_64 | |
#define PLATFORM_STR_ARCH "x86_64" | |
#elif PLATFORM_ARCH_AARCH64 | |
#define PLATFORM_STR_ARCH "aarch64" | |
#elif PLATFORM_ARCH_POWERPC64 | |
#define PLATFORM_STR_ARCH "powerpc64" | |
#elif PLATFORM_ARCH_64 | |
#define PLATFORM_STR_ARCH "64-bit (Unknown)" | |
#elif PLATFORM_ARCH_I386 | |
#define PLATFORM_STR_ARCH "i386" | |
#elif PLATFORM_ARCH_ARM | |
#define PLATFORM_STR_ARCH "arm" | |
#elif PLATFORM_ARCH_32 | |
#define PLATFORM_STR_ARCH "32-bit (Unknown)" | |
#else | |
#define PLATFORM_STR_ARCH "Unknown" | |
#endif | |
#define PLATFORM_STR (PLATFORM_STR_OS " " PLATFORM_STR_ARCH) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment