qb
2.0.0.0
C++17 Actor Framework
Issue
Watch
Star
Fork
Follow @isndev
Loading...
Searching...
No Matches
build_macros.h
Go to the documentation of this file.
1
19
20
#include <cerrno>
21
#include <cstdint>
22
23
#ifndef QB_BUILD_MACROS_H_
24
#define QB_BUILD_MACROS_H_
25
26
#if defined(_WIN32) || defined(_WIN64)
27
#define __WIN__SYSTEM__
28
#ifndef WIN32_LEAN_AND_MEAN
29
#define WIN32_LEAN_AND_MEAN
30
#endif
31
#ifndef NOMINMAX
32
#define NOMINMAX
33
#endif
34
35
#elif defined(__linux__) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
36
// Linux
37
#define __LINUX__SYSTEM__
38
#else
39
#error "Unsupported Operating System"
40
#endif
41
42
#if defined(__WIN__SYSTEM__)
43
#define QB_GET __cdecl
44
#ifdef QB_DYNAMIC
45
// Windows platforms
46
#ifndef QB_LINKED_AS_SHARED
47
#pragma message("WILL EXPORT DYNAMIC")
48
// From DLL side, we must export
49
#define QB_API __declspec(dllexport)
50
#else
51
#pragma message("WILL IMPORT DYNAMIC")
52
// From client application side, we must import
53
#define QB_GET __cdecl
54
#define QB_API __declspec(dllimport)
55
#endif
56
// For Visual C++ compilers, we also need to turn off this annoying C4251 warning.
57
// You can read lots ot different things about it, but the point is the code will
58
// just work fine, and so the simplest way to get rid of this warning is to disable it
59
#ifdef _MSC_VER
60
#pragma warning(disable : 4251)
61
#pragma warning(disable : 4250)
62
#endif
63
#else
64
// No specific directive needed for static build
65
#define QB_API
66
#endif
67
#define QB_UNUSED_VAR
68
#else
69
// Other platforms don't need to define anything
70
#define QB_GET
71
#define QB_API
72
#ifdef __clang__
73
#define QB_UNUSED_VAR __attribute__((unused))
74
#else
75
#define QB_UNUSED_VAR
76
#endif
77
#endif
78
79
// Tests whether compiler has fully c++11 support
80
// About preprocessor '_MSC_VER', please see:
81
// https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2019
82
#if defined(_MSC_VER)
83
#if _MSC_VER < 1900
84
#define QB__HAS_FULL_CXX11 0
85
#else
86
#define QB__HAS_FULL_CXX11 1
87
#if _MSC_VER > 1900
// VS2017 or later
88
#include <vcruntime.h>
89
#include <sdkddkver.h>
90
#endif
91
#endif
92
#else
93
#define QB__HAS_FULL_CXX11 1
94
#endif
95
96
// Tests whether compiler has c++14 support
97
#if (defined(__cplusplus) && __cplusplus >= 201402L) || \
98
(defined(_MSC_VER) && _MSC_VER >= 1900 && \
99
(defined(_MSVC_LANG) && (_MSVC_LANG >= 201402L)))
100
#ifndef QB_HAS_CXX14
101
#define QB__HAS_CXX14 1
102
#endif
// C++14 features macro
103
#endif
// C++14 features check
104
#if !defined(QB__HAS_CXX14)
105
#define QB__HAS_CXX14 0
106
#endif
107
108
// Tests whether compiler has c++17 support
109
#if (defined(__cplusplus) && __cplusplus >= 201703L) || \
110
(defined(_MSC_VER) && _MSC_VER > 1900 && \
111
((defined(_HAS_CXX17) && _HAS_CXX17 == 1) || \
112
(defined(_MSVC_LANG) && (_MSVC_LANG > 201402L))))
113
#ifndef QB_HAS_CXX17
114
#define QB__HAS_CXX17 1
115
#endif
// C++17 features macro
116
#endif
// C++17 features check
117
#if !defined(QB__HAS_CXX17)
118
#define QB__HAS_CXX17 0
119
#endif
120
121
// Tests whether compiler has c++20 support
122
#if (defined(__cplusplus) && __cplusplus > 201703L) || \
123
(defined(_MSC_VER) && _MSC_VER > 1900 && \
124
((defined(_HAS_CXX20) && _HAS_CXX20 == 1) || \
125
(defined(_MSVC_LANG) && (_MSVC_LANG > 201703L))))
126
#ifndef QB__HAS_CXX20
127
#define QB__HAS_CXX20 1
128
#endif
// C++20 features macro
129
#endif
// C++20 features check
130
#if !defined(QB__HAS_CXX20)
131
#define QB__HAS_CXX20 0
132
#endif
133
134
// Workaround for compiler without fully c++11 support, such as vs2013
135
#if QB__HAS_FULL_CXX11
136
#define QB__HAS_NS_INLINE 1
137
#define QB__NS_INLINE inline
138
#else
139
#define QB__HAS_NS_INLINE 0
140
#define QB__NS_INLINE
141
#if defined(constexpr)
142
#undef constexpr
143
#endif
144
#define constexpr const
145
#endif
146
147
// Unix domain socket feature test
148
#if !defined(_WIN32) || defined(NTDDI_WIN10_RS5)
149
#define QB__HAS_UDS 1
150
#else
151
#define QB__HAS_UDS 0
152
#endif
153
154
// Test whether sockaddr has member 'sa_len'
155
#if defined(__linux__) || defined(_WIN32)
156
#define QB__HAS_SA_LEN 0
157
#else
158
#if defined(__unix__) || defined(__APPLE__)
159
#define QB__HAS_SA_LEN 1
160
#else
161
#define QB__HAS_SA_LEN 0
162
#endif
163
#endif
164
165
#if !defined(_WIN32) || defined(NTDDI_VISTA)
166
#define QB__HAS_NTOP 1
167
#else
168
#define QB__HAS_NTOP 0
169
#endif
170
171
// 64bits Sense Macros
172
#if defined(_M_X64) || defined(_WIN64) || defined(__LP64__) || defined(_LP64) || \
173
defined(__x86_64) || defined(__arm64__) || defined(__aarch64__)
174
#define QB__64BITS 1
175
#else
176
#define QB__64BITS 0
177
#endif
178
179
// Try detect compiler exceptions
180
#if !defined(__cpp_exceptions)
181
#define QB__NO_EXCEPTIONS 1
182
#endif
183
184
#if !defined(QB__NO_EXCEPTIONS)
185
#define QB__THROW(x, retval) throw(x)
186
#define QB__THROW0(x) throw(x)
187
#else
188
#define QB__THROW(x, retval) return (retval)
189
#define QB__THROW0(x) return
190
#endif
191
192
// Compatibility with non-clang compilers...
193
#ifndef __has_attribute
194
#define __has_attribute(x) 0
195
#endif
196
#ifndef __has_builtin
197
#define __has_builtin(x) 0
198
#endif
199
200
/*
201
* Helps the compiler's optimizer predicting branches
202
*/
203
#if __has_builtin(__builtin_expect)
204
#ifdef __cplusplus
205
#define qb__likely(exp) (__builtin_expect(!!(exp), true))
206
#define qb__unlikely(exp) (__builtin_expect(!!(exp), false))
207
#else
208
#define qb__likely(exp) (__builtin_expect(!!(exp), 1))
209
#define qb__unlikely(exp) (__builtin_expect(!!(exp), 0))
210
#endif
211
#else
212
#define qb__likely(exp) (!!(exp))
213
#define qb__unlikely(exp) (!!(exp))
214
#endif
215
216
#define QB__STD ::std::
217
218
#if defined(_MSC_VER)
219
#define DISABLE_WARNING_PUSH __pragma(warning(push))
220
#define DISABLE_WARNING_POP __pragma(warning(pop))
221
#define DISABLE_WARNING(warningNumber) __pragma(warning(disable : warningNumber))
222
223
#define DISABLE_WARNING_UNREFERENCED_FORMAL_PARAMETER DISABLE_WARNING(4100)
224
#define DISABLE_WARNING_UNREFERENCED_FUNCTION DISABLE_WARNING(4505)
225
#define DISABLE_WARNING_NARROWING \
226
DISABLE_WARNING(4245) \
227
DISABLE_WARNING(4838)
228
229
#define DISABLE_WARNING_DEPRECATED DISABLE_WARNING(4996)
230
#define DISABLE_WARNING_OLD_STYLE_CAST
231
#define DISABLE_WARNING_IMPLICIT_FALLTHROUGH
232
// other warnings you want to deactivate...
233
234
#elif defined(__GNUC__) || defined(__clang__)
235
#define DO_PRAGMA(X) _Pragma(#X)
236
#define DISABLE_WARNING_PUSH DO_PRAGMA(GCC diagnostic push)
237
#define DISABLE_WARNING_POP DO_PRAGMA(GCC diagnostic pop)
238
#define DISABLE_WARNING(warningName) DO_PRAGMA(GCC diagnostic ignored #warningName)
239
// clang-format off
240
#define DISABLE_WARNING_UNREFERENCED_FORMAL_PARAMETER DISABLE_WARNING(-Wunused-parameter)
241
#define DISABLE_WARNING_UNREFERENCED_FUNCTION DISABLE_WARNING(-Wunused-function)
242
#define DISABLE_WARNING_NARROWING DISABLE_WARNING(-Wnarrowing)
243
#define DISABLE_WARNING_DEPRECATED DISABLE_WARNING(-Wdeprecated-declarations)
244
#define DISABLE_WARNING_OLD_STYLE_CAST DISABLE_WARNING(-Wold-style-cast)
245
#define DISABLE_WARNING_IMPLICIT_FALLTHROUGH DISABLE_WARNING(-Wimplicit-fallthrough)
246
// other warnings you want to deactivate...
247
// clang-format on
248
249
#else
250
#define DISABLE_WARNING_PUSH
251
#define DISABLE_WARNING_POP
252
#define DISABLE_WARNING_UNREFERENCED_FORMAL_PARAMETER
253
#define DISABLE_WARNING_UNREFERENCED_FUNCTION
254
#define DISABLE_WARNING_NARROWING
255
#define DISABLE_WARNING_DEPRECATED
256
#define DISABLE_WARNING_OLD_STYLE_CAST
257
#define DISABLE_WARNING_IMPLICIT_FALLTHROUGH
258
259
#endif
260
261
#endif
include
qb
utility
build_macros.h
Generated by
1.14.0