plugify 1.2.8
Loading...
Searching...
No Matches
config.hpp
1#pragma once
2
3#ifndef __has_cpp_attribute
4# define __has_cpp_attribute(x) 0
5#endif
6#ifndef __has_extension
7# define __has_extension(x) 0
8#endif
9#ifndef __has_feature
10# define __has_feature(x) 0
11#endif
12#ifndef __has_include
13# define __has_include(x) 0
14#endif
15#ifndef __has_builtin
16# define __has_builtin(x) 0
17#endif
18
19#if !__has_builtin(__builtin_constant_p)
20# define __builtin_constant_p(x) std::is_constant_evaluated()
21#endif
22
23#if __has_include(<version>)
24# include <version>
25#endif
26
27#if __has_include(<cassert>)
28# include <cassert>
29# define PLUGIFY_ASSERT(cond, mesg) assert((cond) && (mesg))
30#endif
31
32#define PLUGIFY_HAS_EXCEPTIONS __cpp_exceptions || _CPPUNWIND || __EXCEPTIONS
33#if PLUGIFY_HAS_EXCEPTIONS
34# include <stdexcept>
35# include <type_traits>
36namespace plg {
37 template<typename E, typename... Args>
38 [[noreturn]] constexpr void throw_exception(const char* msg, Args...args) {
39 if constexpr (std::is_constructible_v<E, const char*>) {
40 throw E(msg);
41 } else {
42 throw E(std::forward<Args>(args)...);
43 }
44 }
45} // namespace plg
46# define PLUGIFY_THROW(str, exp, ...) ::plg::throw_exception<exp>(str __VA_OPT__(,) __VA_ARGS__);
47#else
48# include <cstdlib>
49# include <cstdio>
50# define PLUGIFY_THROW(str, ...) \
51 std::fputs(str "\n", stderr); \
52 std::abort();
53#endif
54
55#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
56# define PLUGIFY_INSTRUMENTED_WITH_ASAN 1
57# include <sanitizer/asan_interface.h>
58#else
59# define PLUGIFY_INSTRUMENTED_WITH_ASAN 0
60#endif
61
62# define PLUGIFY_COMPILER_MAKE_VERSION2(version, sp) ((version) * 100 + (sp))
63# define PLUGIFY_COMPILER_MAKE_VERSION3(major, minor, patch) ((major) * 10000 + (minor) * 100 + (patch))
64
65#if defined(__clang__)
66
67# ifndef PLUGIFY_COMPILER_CLANG
68# define PLUGIFY_COMPILER_CLANG 1
69# endif
70
71# define PLUGIFY_COMPILER_CLANG_VERSION PLUGIFY_COMPILER_MAKE_VERSION3(__clang_major__, __clang_minor__, __clang_patchlevel__)
72# define PLUGIFY_CLANG_AT_LEAST(major, minor, patch) (PLUGIFY_COMPILER_CLANG_VERSION >= PLUGIFY_COMPILER_MAKE_VERSION3((major), (minor), (patch)))
73# define PLUGIFY_CLANG_BEFORE(major, minor, patch) (PLUGIFY_COMPILER_CLANG_VERSION < PLUGIFY_COMPILER_MAKE_VERSION3((major), (minor), (patch)))
74
75#if PLUGIFY_CLANG_BEFORE(15, 0, 0)
76# error "clang version 15 required"
77#endif
78
79#elif defined(__GNUC__)
80
81# ifndef PLUGIFY_COMPILER_GCC
82# define PLUGIFY_COMPILER_GCC 1
83# endif
84
85# define PLUGIFY_COMPILER_GCC_VERSION PLUGIFY_COMPILER_MAKE_VERSION3(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
86# define PLUGIFY_GCC_AT_LEAST(major, minor, patch) (PLUGIFY_COMPILER_GCC_VERSION >= PLUGIFY_COMPILER_MAKE_VERSION3((major), (minor), (patch)))
87# define PLUGIFY_GCC_BEFORE(major, minor, patch) (PLUGIFY_COMPILER_GCC_VERSION < PLUGIFY_COMPILER_MAKE_VERSION3((major), (minor), (patch)))
88
89#if PLUGIFY_GCC_BEFORE(11, 1, 0)
90# error "GCC version 11.1 required"
91#endif
92
93#elif defined(_MSC_VER)
94
95# ifndef PLUGIFY_COMPILER_MSVC
96# define PLUGIFY_COMPILER_MSVC 1
97# endif
98
99#if (_MSC_VER >= 1943)
100# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2022, 13)
101#elif (_MSC_VER >= 1942)
102# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2022, 12)
103#elif (_MSC_VER >= 1941)
104# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2022, 11)
105#elif (_MSC_VER >= 1940)
106# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2022, 10)
107#elif (_MSC_VER >= 1939)
108# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2022, 9)
109#elif (_MSC_VER >= 1938)
110# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2022, 8)
111#elif (_MSC_VER >= 1937)
112# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2022, 7)
113#elif (_MSC_VER >= 1936)
114# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2022, 6)
115#elif (_MSC_VER >= 1935)
116# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2022, 5)
117#elif (_MSC_VER >= 1934)
118# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2022, 4)
119#elif (_MSC_VER >= 1933)
120# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2022, 3)
121#elif (_MSC_VER >= 1932)
122# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2022, 2)
123#elif (_MSC_VER >= 1931)
124# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2022, 1)
125#elif (_MSC_VER >= 1930)
126# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2022, 0)
127#elif (_MSC_VER >= 1929)
128# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2019, 10)
129#elif (_MSC_VER >= 1928)
130# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2019, 8)
131#elif (_MSC_VER >= 1927)
132# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2019, 7)
133#elif (_MSC_VER >= 1926)
134# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2019, 6)
135#elif (_MSC_VER >= 1925)
136# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2019, 5)
137#elif (_MSC_VER >= 1924)
138# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2019, 4)
139#elif (_MSC_VER >= 1923)
140# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2019, 3)
141#elif (_MSC_VER >= 1922)
142# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2019, 2)
143#elif (_MSC_VER >= 1921)
144# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2019, 1)
145#elif (_MSC_VER >= 1920)
146# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2019, 0)
147#elif (_MSC_VER >= 1916)
148# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2017, 9)
149#elif (_MSC_VER >= 1915)
150# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2017, 8)
151#elif (_MSC_VER >= 1914)
152# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2017, 7)
153#elif (_MSC_VER >= 1913)
154# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2017, 6)
155#elif (_MSC_VER >= 1912)
156# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2017, 5)
157#elif (_MSC_VER >= 1911)
158# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2017, 3)
159#elif (_MSC_VER >= 1910)
160# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2017, 0)
161#elif (_MSC_VER >= 1900) && defined(_MSVC_LANG)
162# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2015, 3)
163#elif (_MSC_VER >= 1900)
164# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2015, 0)
165#elif (_MSC_VER >= 1800)
166# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2013, 0)
167#elif (_MSC_VER >= 1700)
168# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2012, 0)
169#elif (_MSC_VER >= 1600)
170# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2010, 0)
171#elif (_MSC_VER >= 1500)
172# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2008, 0)
173#else
174# define PLUGIFY_COMPILER_MSVC_VERSION PLUGIFY_COMPILER_MAKE_VERSION2(2005, 0)
175#endif
176#define PLUGIFY_MSVC_AT_LEAST(version, sp) (PLUGIFY_COMPILER_MSVC_VERSION >= PLUGIFY_COMPILER_MAKE_VERSION2((version), (sp)))
177#define PLUGIFY_MSVC_BEFORE(version, sp) (PLUGIFY_COMPILER_MSVC_VERSION < PLUGIFY_COMPILER_MAKE_VERSION2((version), (sp)))
178
179#if PLUGIFY_MSVC_BEFORE(2022, 9)
180#error "MSVC version 2022 17.13.0 required"
181#endif
182
183#endif
184
185// Define version detection for MSVC (_MSVC_LANG) and GCC/Clang (__cplusplus)
186#if defined(_MSC_VER) && defined(_MSVC_LANG)
187# define PLUGIFY_CPP_VERSION _MSVC_LANG
188#else
189# define PLUGIFY_CPP_VERSION __cplusplus
190#endif
191
192// Check for C++ version and define corresponding macros
193#if PLUGIFY_CPP_VERSION >= 202602L
194# define PLUGIFY_HAS_CXX26 1
195#endif
196
197#if PLUGIFY_CPP_VERSION >= 202302L
198# define PLUGIFY_HAS_CXX23 1
199#endif
200
201#define PLUGIFY_PRAGMA_IMPL(x) _Pragma(#x)
202#define PLUGIFY_PRAGMA(x) PLUGIFY_PRAGMA_IMPL(x)
203
204#if PLUGIFY_COMPILER_CLANG
205# define PLUGIFY_PRAGMA_DIAG_PREFIX clang
206#elif PLUGIFY_COMPILER_GCC
207# define PLUGIFY_PRAGMA_DIAG_PREFIX GCC
208#endif
209
210#if PLUGIFY_COMPILER_GCC || PLUGIFY_COMPILER_CLANG
211# define PLUGIFY_WARN_PUSH() PLUGIFY_PRAGMA(PLUGIFY_PRAGMA_DIAG_PREFIX diagnostic push)
212# define PLUGIFY_WARN_IGNORE(wrn) PLUGIFY_PRAGMA(PLUGIFY_PRAGMA_DIAG_PREFIX diagnostic ignored wrn)
213# define PLUGIFY_WARN_POP() PLUGIFY_PRAGMA(PLUGIFY_PRAGMA_DIAG_PREFIX diagnostic pop)
214#elif PLUGIFY_COMPILER_MSVC
215# define PLUGIFY_WARN_PUSH() __pragma(warning(push))
216# define PLUGIFY_WARN_IGNORE(wrn) __pragma(warning(disable: wrn))
217# define PLUGIFY_WARN_POP() __pragma(warning(pop))
218#endif
219
220#if PLUGIFY_COMPILER_GCC || PLUGIFY_COMPILER_CLANG
221# define PLUGIFY_PACK(decl) decl __attribute__((__packed__))
222#elif PLUGIFY_COMPILER_MSVC
223# define PLUGIFY_PACK(decl) __pragma(pack(push, 1)) decl __pragma(pack(pop))
224#else
225# define PLUGIFY_PACK(decl) decl
226#endif
227
228#if defined(_MSC_VER) && _MSC_VER >= 1929
229# define PLUGIFY_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
230#else
231# define PLUGIFY_NO_UNIQUE_ADDRESS [[no_unique_address]]
232#endif
233
234#if PLUGIFY_COMPILER_GCC || PLUGIFY_COMPILER_CLANG
235# define PLUGIFY_UNREACHABLE() __builtin_unreachable()
236#elif PLUGIFY_COMPILER_MSVC
237# define PLUGIFY_UNREACHABLE() __assume(false)
238#else
239# define PLUGIFY_UNREACHABLE()
240#endif
241
242#if PLUGIFY_COMPILER_CLANG
243# define PLUGIFY_FORCE_INLINE [[gnu::always_inline]] [[gnu::gnu_inline]] extern inline
244# define PLUGIFY_NOINLINE [[gnu::noinline]]
245#elif PLUGIFY_COMPILER_GCC
246# define PLUGIFY_FORCE_INLINE [[gnu::always_inline]] inline
247# define PLUGIFY_NOINLINE [[gnu::noinline]]
248#elif PLUGIFY_COMPILER_MSVC
249# pragma warning(error: 4714)
250# define PLUGIFY_FORCE_INLINE [[msvc::forceinline]]
251# define PLUGIFY_NOINLINE [[msvc::noinline]]
252#else
253# define PLUGIFY_FORCE_INLINE inline
254# define PLUGIFY_NOINLINE
255#endif
256
257#if __has_feature(nullability)
258# define PLUGIFY_NO_NULL _Nonnull
259#else
260# define PLUGIFY_NO_NULL
261#endif
262
263#if __has_cpp_attribute(__no_sanitize__)
264# define PLUGIFY_NO_CFI __attribute__((__no_sanitize__("cfi")))
265#else
266# define PLUGIFY_NO_CFI
267#endif
268
269#if PLUGIFY_COMPILER_GCC || PLUGIFY_COMPILER_CLANG
270# define PLUGIFY_RESTRICT __restrict__
271#elif PLUGIFY_COMPILER_MSVC
272# define PLUGIFY_RESTRICT __restrict
273#else
274# define PLUGIFY_RESTRICT
275#endif
276
277#ifndef PLUGIFY_PLATFORM_WINDOWS
278# if defined(_WIN32) || defined(_WIN64)
279# define PLUGIFY_PLATFORM_WINDOWS 1
280# endif
281#endif
282
283#ifndef PLUGIFY_PLATFORM_APPLE
284# if defined(__APPLE__) && defined(__MACH__)
285# define PLUGIFY_PLATFORM_APPLE 1
286# endif
287#endif
288
289#ifndef PLUGIFY_PLATFORM_LINUX
290# if defined(__linux__)
291# define PLUGIFY_PLATFORM_LINUX 1
292# endif
293#endif
294
295#ifndef PLUGIFY_PLATFORM_ANDROID
296# if defined(__ANDROID__)
297# define PLUGIFY_PLATFORM_ANDROID 1
298# endif
299#endif
300
301#ifndef PLUGIFY_PLATFORM_ORBIS
302# if defined(__ORBIS__)
303# define PLUGIFY_PLATFORM_ORBIS 1
304# endif
305#endif
306
307#ifndef PLUGIFY_PLATFORM_PROSPERO
308# if defined(__PROSPERO__)
309# define PLUGIFY_PLATFORM_PROSPERO 1
310# endif
311#endif
312
313#ifndef PLUGIFY_PLATFORM_SWITCH
314# if defined(__NX__)
315# define PLUGIFY_PLATFORM_SWITCH 1
316# endif
317#endif
318
319#ifndef PLUGIFY_PLATFORM_BSD
320# if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
321# define PLUGIFY_PLATFORM_BSD 1
322# endif
323#endif
324
325#ifndef PLUGIFY_PLATFORM_UNIX
326# if defined(__unix__) || defined(__unix) || defined(unix) || defined(__APPLE__)
327# define PLUGIFY_PLATFORM_UNIX 1
328# endif
329#endif
330
331#if !defined(PLUGIFY_PLATFORM_WINDOWS) && \
332 !defined(PLUGIFY_PLATFORM_APPLE) && \
333 !defined(PLUGIFY_PLATFORM_LINUX) && \
334 !defined(PLUGIFY_PLATFORM_ANDROID) && \
335 !defined(PLUGIFY_PLATFORM_ORBIS) && \
336 !defined(PLUGIFY_PLATFORM_PROSPERO)&& \
337 !defined(PLUGIFY_PLATFORM_SWITCH) && \
338 !defined(PLUGIFY_PLATFORM_BSD) && \
339 !defined(PLUGIFY_PLATFORM_UNIX)
340# error "Unsupported platform! Please extend macro.hpp"
341#endif