Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
detect.hpp
Go to the documentation of this file.
1#pragma once
2
3// pulp::platform — compile-time and runtime platform detection
4
5namespace pulp::platform {
6
7// ── Operating System ───────────────────────────────────────────────────────
8
9enum class OS { macOS, iOS, Windows, Linux, Android, Unknown };
10
11#if defined(__APPLE__)
12 #include <TargetConditionals.h>
13 #if TARGET_OS_IPHONE
14 inline constexpr OS current_os = OS::iOS;
15 #else
16 inline constexpr OS current_os = OS::macOS;
17 #endif
18 inline constexpr bool is_apple = true;
19#elif defined(_WIN32)
20 inline constexpr OS current_os = OS::Windows;
21 inline constexpr bool is_apple = false;
22#elif defined(__ANDROID__)
23 inline constexpr OS current_os = OS::Android;
24 inline constexpr bool is_apple = false;
25#elif defined(__linux__)
26 inline constexpr OS current_os = OS::Linux;
27 inline constexpr bool is_apple = false;
28#else
29 inline constexpr OS current_os = OS::Unknown;
30 inline constexpr bool is_apple = false;
31#endif
32
33inline constexpr bool is_macos = (current_os == OS::macOS);
34inline constexpr bool is_ios = (current_os == OS::iOS);
35inline constexpr bool is_windows = (current_os == OS::Windows);
36inline constexpr bool is_linux = (current_os == OS::Linux);
37inline constexpr bool is_android = (current_os == OS::Android);
38inline constexpr bool is_desktop = is_macos || is_windows || is_linux;
39inline constexpr bool is_mobile = is_ios || is_android;
40
41// ── Architecture ───────────────────────────────────────────────────────────
42
43enum class Arch { x86_64, ARM64, ARM32, x86, Unknown };
44
45#if defined(__aarch64__) || defined(_M_ARM64)
46 inline constexpr Arch current_arch = Arch::ARM64;
47#elif defined(__x86_64__) || defined(_M_X64)
48 inline constexpr Arch current_arch = Arch::x86_64;
49#elif defined(__arm__) || defined(_M_ARM)
50 inline constexpr Arch current_arch = Arch::ARM32;
51#elif defined(__i386__) || defined(_M_IX86)
52 inline constexpr Arch current_arch = Arch::x86;
53#else
54 inline constexpr Arch current_arch = Arch::Unknown;
55#endif
56
57inline constexpr bool is_arm = (current_arch == Arch::ARM64 || current_arch == Arch::ARM32);
58inline constexpr bool is_x86 = (current_arch == Arch::x86_64 || current_arch == Arch::x86);
59inline constexpr bool is_64bit = (current_arch == Arch::x86_64 || current_arch == Arch::ARM64);
60
61// ── Compiler ───────────────────────────────────────────────────────────────
62
64
65#if defined(__clang__)
66 #if defined(__apple_build_version__)
68 #else
69 inline constexpr Compiler current_compiler = Compiler::Clang;
70 #endif
71#elif defined(__GNUC__)
72 inline constexpr Compiler current_compiler = Compiler::GCC;
73#elif defined(_MSC_VER)
74 inline constexpr Compiler current_compiler = Compiler::MSVC;
75#else
77#endif
78
79// ── Endianness ─────────────────────────────────────────────────────────────
80
81enum class Endian { Little, Big };
82
83#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
84 inline constexpr Endian current_endian = Endian::Big;
85#else
87#endif
88
89inline constexpr bool is_little_endian = (current_endian == Endian::Little);
90inline constexpr bool is_big_endian = (current_endian == Endian::Big);
91
92// ── Debug ──────────────────────────────────────────────────────────────────
93
94#if defined(NDEBUG)
95 inline constexpr bool is_debug = false;
96#else
97 inline constexpr bool is_debug = true;
98#endif
99
100} // namespace pulp::platform
Device capability vocabulary: one tier ladder, one thermal ladder, and the projection from observed i...
Definition child_process.hpp:15
constexpr bool is_macos
Definition detect.hpp:33
constexpr Endian current_endian
Definition detect.hpp:86
OS
Definition detect.hpp:9
@ iOS
Definition detect.hpp:9
@ Unknown
Definition detect.hpp:9
@ macOS
Definition detect.hpp:9
@ Windows
Definition detect.hpp:9
@ Android
Definition detect.hpp:9
@ Linux
Definition detect.hpp:9
constexpr bool is_mobile
Definition detect.hpp:39
Arch
Definition detect.hpp:43
@ x86_64
Definition detect.hpp:43
@ ARM32
Definition detect.hpp:43
@ Unknown
Definition detect.hpp:43
@ x86
Definition detect.hpp:43
@ ARM64
Definition detect.hpp:43
constexpr bool is_arm
Definition detect.hpp:57
constexpr bool is_little_endian
Definition detect.hpp:89
Endian
Definition detect.hpp:81
@ Little
Definition detect.hpp:81
@ Big
Definition detect.hpp:81
constexpr bool is_windows
Definition detect.hpp:35
constexpr OS current_os
Definition detect.hpp:16
constexpr Compiler current_compiler
Definition detect.hpp:76
Compiler
Definition detect.hpp:63
@ MSVC
Definition detect.hpp:63
@ GCC
Definition detect.hpp:63
@ AppleClang
Definition detect.hpp:63
@ Unknown
Definition detect.hpp:63
@ Clang
Definition detect.hpp:63
constexpr bool is_linux
Definition detect.hpp:36
constexpr bool is_apple
Definition detect.hpp:18
constexpr Arch current_arch
Definition detect.hpp:54
constexpr bool is_ios
Definition detect.hpp:34
constexpr bool is_big_endian
Definition detect.hpp:90
constexpr bool is_debug
Definition detect.hpp:97
constexpr bool is_desktop
Definition detect.hpp:38
constexpr bool is_64bit
Definition detect.hpp:59
constexpr bool is_x86
Definition detect.hpp:58
constexpr bool is_android
Definition detect.hpp:37