IceShard 1
A personal game engine project, with development focused on 2D/2.5D games.
Loading...
Searching...
No Matches
platform.hxx
Go to the documentation of this file.
1
3
4#pragma once
5#include <ice/types.hxx>
6#include <string_view>
7
8namespace ice::build
9{
10
19
20 enum class ArchFamily : ice::u8
21 {
26 };
27
35
36 enum class Compiler : ice::u8
37 {
41 };
42
51
52
53 constexpr auto arch_family(Architecture arch) noexcept -> ArchFamily;
54
55 constexpr bool operator==(Platform const& left, System right) noexcept;
56 constexpr bool operator!=(Platform const& left, System right) noexcept;
57
58 constexpr bool operator==(Platform const& left, ArchFamily right) noexcept;
59 constexpr bool operator!=(Platform const& left, ArchFamily right) noexcept;
60
61 constexpr bool operator==(Platform const& left, Architecture right) noexcept;
62 constexpr bool operator!=(Platform const& left, Architecture right) noexcept;
63
64 constexpr bool operator==(Platform const& left, Compiler right) noexcept;
65 constexpr bool operator!=(Platform const& left, Compiler right) noexcept;
66
67 constexpr bool operator==(Platform const& left, Platform const& right) noexcept;
68 constexpr bool operator!=(Platform const& left, Platform const& right) noexcept;
69
70
71 constexpr auto to_string(System type) noexcept -> std::string_view;
72 constexpr auto to_string(ArchFamily type) noexcept -> std::string_view;
73 constexpr auto to_string(Architecture type) noexcept -> std::string_view;
74 constexpr auto to_string(Compiler type) noexcept -> std::string_view;
75 constexpr auto to_string(Platform const& type) noexcept -> std::string_view;
76
77 static constexpr Platform platform_uwp_x64_msvc = {
78 .name = "uwp-x64-msvc",
79 .system = System::UWP,
80 .architecture = Architecture::x86_x64,
81 .compiler = Compiler::MSVC
82 };
83
85 .name = "windows-x64-msvc",
86 .system = System::Windows,
87 .architecture = Architecture::x86_x64,
88 .compiler = Compiler::MSVC
89 };
90
92 .name = "windows-x64-clang",
93 .system = System::Windows,
94 .architecture = Architecture::x86_x64,
95 .compiler = Compiler::Clang
96 };
97
99 .name = "android-arm64-clang",
100 .system = System::Android,
101 .architecture = Architecture::Arm64,
102 .compiler = Compiler::Clang
103 };
104
106 .name = "android-x64-clang",
107 .system = System::Android,
108 .architecture = Architecture::x86_x64,
109 .compiler = Compiler::Clang
110 };
111
113 .name = "linux-x64-clang",
114 .system = System::Linux,
115 .architecture = Architecture::x86_x64,
116 .compiler = Compiler::Clang
117 };
118
120 .name = "webapp-webasm32-clang",
121 .system = System::WebApp,
122 .architecture = Architecture::WebAsm32,
123 .compiler = Compiler::Clang
124 };
125
135
136
137#if INTPTR_MAX == INT64_MAX
138#define ISP_ARCH_BITS 64
139#elif INTPTR_MAX == INT32_MAX
140#define ISP_ARCH_BITS 32
141#else
142#error Unknown pointer size or missing size macros!
143#endif
144
145#if defined(_WIN64)
146# define ISP_UNIX 0
147# define ISP_LINUX 0
148# define ISP_WINDOWS 1
149# define ISP_ANDROID 0
150# define ISP_WEBAPP 0
151# if defined(__clang__)
152# define ISP_COMPILER_MSVC 0
153# define ISP_COMPILER_CLANG __clang_major__
154# define ISP_COMPILER_GCC 0
155
156 static constexpr Platform current_platform = platform_windows_x64_clang;
157# else
158# define ISP_COMPILER_MSVC 1
159# define ISP_COMPILER_CLANG 0
160# define ISP_COMPILER_GCC 0
161
162 static constexpr Platform current_platform = platform_windows_x64_msvc;
163# endif
164# define ISP_ARCHFAM_X86 1
165# define ISP_ARCHFAM_ARM 0
166# define ISP_ARCHFAM_WEBASM 0
167# define ISP_HW_DESTRUCTIVE_INTERFERENCE 64
168# define ISP_TEXT(val) L ## val
169#elif defined(__ANDROID__)
170# define ISP_UNIX 1
171# define ISP_LINUX 0
172# define ISP_WINDOWS 0
173# define ISP_ANDROID __ANDROID_API__
174# define ISP_WEBAPP 0
175# define ISP_COMPILER_MSVC 0
176# define ISP_COMPILER_CLANG __clang_major__
177# define ISP_COMPILER_GCC 0
178
179# if defined(__aarch64__) || defined(_M_ARM64)
180# define ISP_ARCHFAM_X86 0
181# define ISP_ARCHFAM_ARM 1
182# define ISP_ARCHFAM_WEBASM 0
183 static constexpr Platform current_platform = platform_android_arm64_clang;
184# else
185# define ISP_ARCHFAM_X86 1
186# define ISP_ARCHFAM_ARM 0
187# define ISP_ARCHFAM_WEBASM 0
188 static constexpr Platform current_platform = platform_android_x64_clang;
189# endif
190# define ISP_HW_DESTRUCTIVE_INTERFERENCE 64 // NOT CHECKED
191# define ISP_TEXT(val) val
192#elif defined(EMSCRIPTEN)
193# define ISP_UNIX 1
194# define ISP_LINUX 0
195# define ISP_WINDOWS 0
196# define ISP_ANDROID 0
197# define ISP_WEBAPP 1
198# define ISP_COMPILER_MSVC 0
199# define ISP_COMPILER_CLANG __clang_major__
200# define ISP_COMPILER_GCC 0
201
202# define ISP_ARCHFAM_X86 0
203# define ISP_ARCHFAM_ARM 0
204# define ISP_ARCHFAM_WEBASM 1
205
206 static constexpr Platform current_platform = platform_webapp_webasm32_clang;
207# define ISP_HW_DESTRUCTIVE_INTERFERENCE 64 // NOT CHECKED
208# define ISP_TEXT(val) val
209#elif __unix__ && !__clang__
210# define ISP_UNIX 1
211# define ISP_LINUX 1
212# define ISP_WINDOWS 0
213# define ISP_ANDROID 0
214# define ISP_WEBAPP 0
215# define ISP_COMPILER_MSVC 0
216# define ISP_COMPILER_CLANG 0
217# define ISP_COMPILER_GCC 1
218# define ISP_ARCHFAM_X86 1
219# define ISP_ARCHFAM_ARM 0
220# define ISP_ARCHFAM_WEBASM 0
221
222 static constexpr Platform current_platform = platform_unix_x64_gcc;
223# define ISP_HW_DESTRUCTIVE_INTERFERENCE 64 // NOT CHECKED
224# define ISP_TEXT(val) val
225#elif __unix__ && __clang__
226# define ISP_UNIX 1
227# define ISP_LINUX 1
228# define ISP_WINDOWS 0
229# define ISP_ANDROID 0
230# define ISP_WEBAPP 0
231# define ISP_COMPILER_MSVC 0
232# define ISP_COMPILER_CLANG __clang_major__
233# define ISP_COMPILER_GCC 0
234# define ISP_ARCHFAM_X86 1
235# define ISP_ARCHFAM_ARM 0
236# define ISP_ARCHFAM_WEBASM 0
237
238 static constexpr Platform current_platform = platform_linux_x64_clang;
239# define ISP_HW_DESTRUCTIVE_INTERFERENCE 64 // NOT CHECKED
240# define ISP_TEXT(val) val
241#else
242# define ISP_UNIX 0
243# define ISP_WINDOWS 0
244# define ISP_ANDROID 0
245# define ISP_WEBAPP 0
246# define ISP_COMPILER_MSVC 0
247# define ISP_COMPILER_CLANG 0
248# define ISP_COMPILER_GCC 0
249# define ISP_ARCHFAM_X86 0
250# define ISP_ARCHFAM_ARM 0
251# define ISP_ARCHFAM_WEBASM 0
252
253 static_assert(false, "Unknow platform!");
254# define ISP_HW_DESTRUCTIVE_INTERFERENCE ISP_UNDEFINED
255# define ISP_TEXT(val) ISP_UNDEFINED
256#endif
257
258 constexpr auto arch_family(Architecture arch) noexcept -> ArchFamily
259 {
260 switch(arch)
261 {
262 using enum Architecture;
263 case x86:
264 case x86_x64: return ArchFamily::X86;
265 case Arm64: return ArchFamily::ARM;
266 default: return ArchFamily::Unknown;
267 }
268 }
269
270 constexpr bool operator==(Platform const& left, System right) noexcept
271 {
272 return left.system == right;
273 }
274
275 constexpr bool operator!=(Platform const& left, System right) noexcept
276 {
277 return !(left == right);
278 }
279
280 constexpr bool operator==(Platform const& left, ArchFamily right) noexcept
281 {
282 return arch_family(left.architecture) == right;
283 }
284
285 constexpr bool operator!=(Platform const& left, ArchFamily right) noexcept
286 {
287 return !(left == right);
288 }
289
290 constexpr bool operator==(Platform const& left, Architecture right) noexcept
291 {
292 return left.architecture == right;
293 }
294
295 constexpr bool operator!=(Platform const& left, Architecture right) noexcept
296 {
297 return !(left == right);
298 }
299
300 constexpr bool operator==(Platform const& left, Compiler right) noexcept
301 {
302 return left.compiler == right;
303 }
304
305 constexpr bool operator!=(Platform const& left, Compiler right) noexcept
306 {
307 return !(left == right);
308 }
309
310 constexpr bool operator==(Platform const& left, Platform const& right) noexcept
311 {
312 return left.system == right.system
313 && left.architecture == right.architecture
314 && left.compiler == right.compiler;
315 }
316
317 constexpr bool operator!=(Platform const& left, Platform const& right) noexcept
318 {
319 return !(left == right);
320 }
321
322
323 constexpr auto to_string(System system) noexcept -> std::string_view
324 {
325 switch (system)
326 {
328 return "universal_windows_platform";
330 return "windows";
332 return "android";
334 return "linux";
335 default:
336 return "<invalid>";
337 }
338 }
339
340 constexpr auto to_string(ArchFamily family) noexcept -> std::string_view
341 {
342 switch (family)
343 {
344 case ArchFamily::X86:
345 return "X86";
346 case ArchFamily::ARM:
347 return "ARM";
348 default:
349 return "<invalid>";
350 }
351 }
352
353 constexpr auto to_string(Architecture arch) noexcept -> std::string_view
354 {
355 switch (arch)
356 {
358 return "x86";
360 return "x64";
362 return "arm64";
363 default:
364 return "<invalid>";
365 }
366 }
367
368 constexpr auto to_string(Compiler compiler) noexcept -> std::string_view
369 {
370 switch (compiler)
371 {
372 case Compiler::MSVC:
373 return "msvc";
374 case Compiler::Clang:
375 return "clang";
376 case Compiler::GCC:
377 return "gcc";
378 default:
379 return "<invalid>";
380 }
381 }
382
383 constexpr auto to_string(Platform const& platform) noexcept -> std::string_view
384 {
385 return platform.name;
386 }
387
388} // namespace ice::build
Definition build.hxx:12
System
Definition platform.hxx:12
@ UWP
Definition platform.hxx:13
@ Windows
Definition platform.hxx:14
@ WebApp
Definition platform.hxx:17
@ Android
Definition platform.hxx:15
@ Linux
Definition platform.hxx:16
static constexpr Platform platform_webapp_webasm32_clang
Definition platform.hxx:119
static constexpr Platform platform_android_arm64_clang
Definition platform.hxx:98
static constexpr Platform platform_linux_x64_clang
Definition platform.hxx:112
constexpr bool operator==(Platform const &left, System right) noexcept
Definition platform.hxx:270
static constexpr Platform platform_windows_x64_clang
Definition platform.hxx:91
static constexpr Platform all_platforms[]
Definition platform.hxx:126
ArchFamily
Definition platform.hxx:21
@ ARM
Definition platform.hxx:24
@ Unknown
Definition platform.hxx:22
@ WebAsm
Definition platform.hxx:25
@ X86
Definition platform.hxx:23
static constexpr Platform platform_windows_x64_msvc
Definition platform.hxx:84
constexpr auto to_string(Configuration type) noexcept -> std::string_view
Definition config.hxx:69
constexpr bool operator!=(Platform const &left, System right) noexcept
Definition platform.hxx:275
static constexpr Platform platform_uwp_x64_msvc
Definition platform.hxx:77
Compiler
Definition platform.hxx:37
@ MSVC
Definition platform.hxx:38
@ GCC
Definition platform.hxx:40
@ Clang
Definition platform.hxx:39
static constexpr Platform platform_android_x64_clang
Definition platform.hxx:105
Architecture
Definition platform.hxx:29
@ WebAsm32
Definition platform.hxx:33
@ x86_x64
Definition platform.hxx:31
@ x86
Definition platform.hxx:30
@ Arm64
Definition platform.hxx:32
constexpr auto arch_family(Architecture arch) noexcept -> ArchFamily
Definition platform.hxx:258
std::uint8_t u8
Definition types.hxx:24
Definition platform.hxx:44
Architecture architecture
Definition platform.hxx:48
System system
Definition platform.hxx:47
Compiler compiler
Definition platform.hxx:49
std::string_view name
Definition platform.hxx:45