Worldstone
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
Platform.h
Go to the documentation of this file.
1 
6 #pragma once
7 // We're disabling clang format here, as IndentPPDirectives is only in clang-format v6
8 // clang-format off
9 
12 
13 #ifdef FORCE_DOXYGEN
14 # define WS_GCC_FAMILY
15 # define WS_CLANG
16 # define WS_GCC
17 # define WS_MSC
18 
19 # define WS_64BITS
20 # define WS_32BITS
21 #endif
22 
23 #if defined(__GNUC__) || defined(__GNUG__)
24 # define WS_GCC_FAMILY
25 # if defined(__clang__)
26 # define WS_CLANG
27 # else
28 # define WS_GCC
29 # endif
30 #elif defined(_MSC_VER)
31 # define WS_MSC
32 #else
33 # error "Unknown compiler"
34 #endif
35 
36 #ifdef WS_MSC
37 # include <intrin.h> // MSVC requires this header to use intrinsics
38 #endif
39 
40 #if defined(__LP64__) || defined(_WIN64)
41 # define WS_64BITS
42 #else
43 # define WS_32BITS
44 #endif
45 
47 
48 
49 
50 #ifdef FORCE_DOXYGEN
51 # define WS_PLATFORM_WINDOWS
52 # define WS_PLATFORM_LINUX
53 # define WS_PLATFORM_MAC
54 # define WS_PLATFORM_IOS
55 # define WS_PLATFORM_EMSCRIPTEN
56 #endif
57 
60 #if defined(_WIN32) || defined(_WIN64)
61 # ifndef NOMINMAX
62 # define NOMINMAX // Already set by CMake, but might be required for consumers
63 # endif // NOMINMAX
64 # define WS_PLATFORM_WINDOWS
65 #elif defined(__linux__)
66 # define WS_PLATFORM_LINUX
67 #elif __APPLE__
68 # define WS_PLATFORM_MAC
69 # include <TargetConditionals.h>
70 # if defined(TARGET_OS_IOS)
71 # define WS_PLATFORM_IOS
72 # endif
73 #elif defined(__EMSCRIPTEN__)
74 # define WS_PLATFORM_EMSCRIPTEN
75 #else
76 # error "Unknown platform"
77 #endif
78 
80 
81 
82 
83 #define WS_STRINGIZE(_x) #_x
84 
92 #ifdef FORCE_DOXYGEN
93 # define WS_PRAGMA_DIAGNOSTIC_PUSH()
94 # define WS_PRAGMA_DIAGNOSTIC_POP()
95 # define WS_PRAGMA_DIAGNOSTIC_IGNORED_GNU(_x)
96 # define WS_PRAGMA_DIAGNOSTIC_IGNORED_GCC(_x)
97 # define WS_PRAGMA_DIAGNOSTIC_IGNORED_CLANG(_x)
98 # define WS_PRAGMA_DIAGNOSTIC_IGNORED_MSC(_x)
99 #else
100 # if defined(WS_CLANG)
101 # define WS_PRAGMA_DIAGNOSTIC_PUSH() _Pragma("clang diagnostic push")
102 # define WS_PRAGMA_DIAGNOSTIC_POP() _Pragma("clang diagnostic pop")
103 # define WS_PRAGMA_DIAGNOSTIC_IGNORED_CLANG(_x) _Pragma(WS_STRINGIZE(clang diagnostic ignored _x))
104 # define WS_PRAGMA_DIAGNOSTIC_IGNORED_GNU(_x) WS_PRAGMA_DIAGNOSTIC_IGNORED_CLANG(_x)
105 # else
106 # define WS_PRAGMA_DIAGNOSTIC_IGNORED_CLANG(_x)
107 # endif
108 # if defined(WS_GCC)
109 # define WS_PRAGMA_DIAGNOSTIC_PUSH() _Pragma("GCC diagnostic push")
110 # define WS_PRAGMA_DIAGNOSTIC_POP() _Pragma("GCC diagnostic pop")
111 # define WS_PRAGMA_DIAGNOSTIC_IGNORED_GCC(_x) _Pragma(WS_STRINGIZE(GCC diagnostic ignored _x) )
112 # define WS_PRAGMA_DIAGNOSTIC_IGNORED_GNU(_x) WS_PRAGMA_DIAGNOSTIC_IGNORED_GCC(_x)
113 # else
114 # define WS_PRAGMA_DIAGNOSTIC_IGNORED_GCC(_x)
115 # endif
116 # if defined(WS_MSC)
117 # define WS_PRAGMA_DIAGNOSTIC_PUSH() __pragma(warning(push) )
118 # define WS_PRAGMA_DIAGNOSTIC_POP() __pragma(warning(pop) )
119 # define WS_PRAGMA_DIAGNOSTIC_IGNORED_MSC(_x) __pragma(warning(disable:_x) )
120 # define WS_PRAGMA_DIAGNOSTIC_IGNORED_GNU(_x)
121 # else
122 # define WS_PRAGMA_DIAGNOSTIC_IGNORED_MSC(_x)
123 # endif
124 
125 #endif
126 
145 #if __cplusplus >= 201703 || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703)
146 # define WS_FALLTHROUGH [[fallthrough]]
147 #elif defined(WS_CLANG)
148 # if __cplusplus >= 201103L && defined(__has_warning)
149 # if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
150 # define WS_FALLTHROUGH [[clang::fallthrough]]
151 # endif
152 # endif
153 #elif defined(WS_GCC) && __GNUC__ >= 7
154 # define WS_FALLTHROUGH __attribute__((fallthrough))
155 #endif
156 #ifndef WS_FALLTHROUGH
157 # define WS_FALLTHROUGH ((void)0)
158 #endif
159 // clang-format on
160 
164 #include <stddef.h>
165 #include <stdint.h>
169 constexpr size_t operator"" _z(unsigned long long int n) { return size_t(n); }