Sane C++ Libraries
C++ Platform Abstraction Libraries
Platform.h
1// Copyright (c) Stefano Cristiano
2// SPDX-License-Identifier: MIT
3#pragma once
4
7
8#if defined(DEBUG) || defined(_DEBUG)
9#define SC_CONFIGURATION_DEBUG 1
10#define SC_CONFIGURATION_RELEASE 0
11#else
12#define SC_CONFIGURATION_DEBUG 0
13#define SC_CONFIGURATION_RELEASE 1
14#endif
15
16namespace SC
17{
19enum class Platform
20{
21 Apple,
22 Linux,
23 Windows,
24 Emscripten,
25};
26
29{
30 enum Type
31 {
32 macOS,
33 iOS,
34 Emscripten,
35 Windows,
36 Linux,
37 };
38
40 [[nodiscard]] static Type getHostOS();
41};
42
43#if defined(__APPLE__)
44
45#define SC_PLATFORM_APPLE 1
46#define SC_PLATFORM_LINUX 0
47#define SC_PLATFORM_WINDOWS 0
48#define SC_PLATFORM_EMSCRIPTEN 0
49static constexpr Platform HostPlatform = Platform::Apple;
50
51#elif defined(_WIN32) || defined(_WIN64)
52
53#define SC_PLATFORM_APPLE 0
54#define SC_PLATFORM_LINUX 0
55#define SC_PLATFORM_WINDOWS 1
56#define SC_PLATFORM_EMSCRIPTEN 0
57static constexpr Platform HostPlatform = Platform::Windows;
58
59#elif defined(__EMSCRIPTEN__)
60
61#define SC_PLATFORM_APPLE 0
62#define SC_PLATFORM_LINUX 0
63#define SC_PLATFORM_WINDOWS 0
64#define SC_PLATFORM_EMSCRIPTEN 1
65static constexpr Platform HostPlatform = Platform::Emscripten;
66
67#elif defined(__linux__)
68
69#define SC_PLATFORM_APPLE 0
70#define SC_PLATFORM_LINUX 1
71#define SC_PLATFORM_WINDOWS 0
72#define SC_PLATFORM_EMSCRIPTEN 0
73static constexpr Platform HostPlatform = Platform::Linux;
74
75#else
76
77#error "Unsupported platform"
78
79#endif
80
81#if defined(_WIN64)
82#define SC_PLATFORM_64_BIT 1
83#elif defined(_WIN32)
84#define SC_PLATFORM_64_BIT 0
85#else
86#define SC_PLATFORM_64_BIT 1
87#endif
88
90enum class InstructionSet
91{
92 ARM64,
93 Intel64,
94 Intel32
95};
96
97#if defined(_M_ARM64) || defined(__aarch64__)
98#define SC_PLATFORM_ARM64 1
99#define SC_PLATFORM_INTEL 0
100static constexpr InstructionSet HostInstructionSet = InstructionSet::ARM64;
101#else
102#define SC_PLATFORM_ARM64 0
103#define SC_PLATFORM_INTEL 1
104#if SC_PLATFORM_64_BIT
105static constexpr InstructionSet HostInstructionSet = InstructionSet::Intel64;
106#else
107static constexpr InstructionSet HostInstructionSet = InstructionSet::Intel32;
108#endif
109#endif
110
111} // namespace SC
112
Holds information about operating system.
Definition: Platform.h:29
static Type getHostOS()
Returns the currently active host operating system.