1 | /* |
2 | * Copyright Andrey Semashev 2007 - 2015. |
3 | * Distributed under the Boost Software License, Version 1.0. |
4 | * (See accompanying file LICENSE_1_0.txt or copy at |
5 | * http://www.boost.org/LICENSE_1_0.txt) |
6 | */ |
7 | /*! |
8 | * \file config.hpp |
9 | * \author Andrey Semashev |
10 | * \date 08.03.2007 |
11 | * |
12 | * \brief This header is the Boost.Log library implementation, see the library documentation |
13 | * at http://www.boost.org/doc/libs/release/libs/log/doc/html/index.html. In this file |
14 | * internal configuration macros are defined. |
15 | */ |
16 | |
17 | #ifndef BOOST_LOG_DETAIL_CONFIG_HPP_INCLUDED_ |
18 | #define BOOST_LOG_DETAIL_CONFIG_HPP_INCLUDED_ |
19 | |
20 | // Try including WinAPI config as soon as possible so that any other headers don't include Windows SDK headers |
21 | #if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__) |
22 | #include <boost/winapi/config.hpp> |
23 | #endif |
24 | |
25 | #include <limits.h> // To bring in libc macros |
26 | #include <boost/config.hpp> |
27 | |
28 | // The library requires dynamic_cast in a few places |
29 | #if defined(BOOST_NO_RTTI) |
30 | # error Boost.Log: RTTI is required by the library |
31 | #endif |
32 | |
33 | #if defined(_MSC_VER) && _MSC_VER >= 1600 |
34 | # define BOOST_LOG_HAS_PRAGMA_DETECT_MISMATCH |
35 | #endif |
36 | |
37 | #if !defined(BOOST_WINDOWS) |
38 | # ifndef BOOST_LOG_WITHOUT_DEBUG_OUTPUT |
39 | # define BOOST_LOG_WITHOUT_DEBUG_OUTPUT |
40 | # endif |
41 | # ifndef BOOST_LOG_WITHOUT_EVENT_LOG |
42 | # define BOOST_LOG_WITHOUT_EVENT_LOG |
43 | # endif |
44 | #endif |
45 | |
46 | #ifdef BOOST_HAS_PRAGMA_ONCE |
47 | #pragma once |
48 | #endif |
49 | |
50 | #if defined(BOOST_MSVC) |
51 | // For some reason MSVC 9.0 fails to link the library if static integral constants are defined in cpp |
52 | # define BOOST_LOG_BROKEN_STATIC_CONSTANTS_LINKAGE |
53 | # if _MSC_VER <= 1310 |
54 | // MSVC 7.1 sometimes fails to match out-of-class template function definitions with |
55 | // their declarations if the return type or arguments of the functions involve typename keyword |
56 | // and depend on the template parameters. |
57 | # define BOOST_LOG_BROKEN_TEMPLATE_DEFINITION_MATCHING |
58 | # endif |
59 | # if _MSC_VER <= 1400 |
60 | // Older MSVC versions reject friend declarations for class template specializations |
61 | # define BOOST_LOG_BROKEN_FRIEND_TEMPLATE_SPECIALIZATIONS |
62 | # endif |
63 | # if _MSC_VER <= 1600 |
64 | // MSVC up to 10.0 attempts to invoke copy constructor when initializing a const reference from rvalue returned from a function. |
65 | // This fails when the returned value cannot be copied (only moved): |
66 | // |
67 | // class base {}; |
68 | // class derived : public base { BOOST_MOVABLE_BUT_NOT_COPYABLE(derived) }; |
69 | // derived foo(); |
70 | // base const& var = foo(); // attempts to call copy constructor of derived |
71 | # define BOOST_LOG_BROKEN_REFERENCE_FROM_RVALUE_INIT |
72 | # endif |
73 | # if !defined(_STLPORT_VERSION) |
74 | // MSVC 9.0 mandates packaging of STL classes, which apparently affects alignment and |
75 | // makes alignment_of< T >::value no longer be a power of 2 for types that derive from STL classes. |
76 | // This breaks type_with_alignment and everything that relies on it. |
77 | // This doesn't happen with non-native STLs, such as STLPort. Strangely, this doesn't show with |
78 | // STL classes themselves or most of the user-defined derived classes. |
79 | // Not sure if that happens with other MSVC versions. |
80 | // See: http://svn.boost.org/trac/boost/ticket/1946 |
81 | # define BOOST_LOG_BROKEN_STL_ALIGNMENT |
82 | # endif |
83 | #endif |
84 | |
85 | #if defined(BOOST_INTEL) || defined(__SUNPRO_CC) |
86 | // Intel compiler and Sun Studio 12.3 have problems with friend declarations for nested class templates |
87 | # define BOOST_LOG_NO_MEMBER_TEMPLATE_FRIENDS |
88 | #endif |
89 | |
90 | #if defined(BOOST_MSVC) && BOOST_MSVC <= 1600 |
91 | // MSVC cannot interpret constant expressions in certain contexts, such as non-type template parameters |
92 | # define BOOST_LOG_BROKEN_CONSTANT_EXPRESSIONS |
93 | #endif |
94 | |
95 | #if (defined(BOOST_NO_CXX11_HDR_CODECVT) && BOOST_CXX_VERSION < 201703) || (defined(_MSVC_STL_VERSION) && _MSVC_STL_VERSION < 142) |
96 | // The compiler does not support std::codecvt<char16_t> and std::codecvt<char32_t> specializations. |
97 | // The BOOST_NO_CXX11_HDR_CODECVT means there's no usable <codecvt>, which is slightly different from this macro. |
98 | // But in order for <codecvt> to be implemented the std::codecvt specializations have to be implemented as well. |
99 | // We need to check the C++ version as well, since <codecvt> is deprecated from C++17 onwards which may cause |
100 | // BOOST_NO_CXX11_HDR_CODECVT to be set, even though std::codecvt in <locale> is just fine. |
101 | # define BOOST_LOG_NO_CXX11_CODECVT_FACETS |
102 | #endif |
103 | |
104 | #if defined(__CYGWIN__) |
105 | // Boost.ASIO is broken on Cygwin |
106 | # define BOOST_LOG_NO_ASIO |
107 | #endif |
108 | |
109 | #if defined(__VXWORKS__) |
110 | # define BOOST_LOG_NO_GETPGRP |
111 | # define BOOST_LOG_NO_GETSID |
112 | // for _WRS_CONFIG_USER_MANAGEMENT used below |
113 | # include <vsbConfig.h> |
114 | #endif |
115 | |
116 | #if (!defined(__CRYSTAX__) && defined(__ANDROID__) && (__ANDROID_API__ < 21)) \ |
117 | || (defined(__VXWORKS__) && !defined(_WRS_CONFIG_USER_MANAGEMENT)) |
118 | // Until Android API version 21 Google NDK does not provide getpwuid_r |
119 | # define BOOST_LOG_NO_GETPWUID_R |
120 | #endif |
121 | |
122 | #if !defined(BOOST_LOG_USE_NATIVE_SYSLOG) && defined(BOOST_LOG_NO_ASIO) |
123 | # ifndef BOOST_LOG_WITHOUT_SYSLOG |
124 | # define BOOST_LOG_WITHOUT_SYSLOG |
125 | # endif |
126 | #endif |
127 | |
128 | #if defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ <= 2) |
129 | // GCC 4.1 and 4.2 have buggy anonymous namespaces support, which interferes with symbol linkage |
130 | # define BOOST_LOG_ANONYMOUS_NAMESPACE namespace anonymous {} using namespace anonymous; namespace anonymous |
131 | #else |
132 | # define BOOST_LOG_ANONYMOUS_NAMESPACE namespace |
133 | #endif |
134 | |
135 | #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || (defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ <= 6)) |
136 | // GCC up to 4.6 (inclusively) did not support expanding template argument packs into non-variadic template arguments |
137 | #define BOOST_LOG_NO_CXX11_ARG_PACKS_TO_NON_VARIADIC_ARGS_EXPANSION |
138 | #endif |
139 | |
140 | #if defined(BOOST_NO_CXX11_CONSTEXPR) || (defined(BOOST_GCC) && (BOOST_GCC / 100) <= 406) |
141 | // GCC 4.6 does not support in-class brace initializers for static constexpr array members |
142 | #define BOOST_LOG_NO_CXX11_CONSTEXPR_DATA_MEMBER_BRACE_INITIALIZERS |
143 | #endif |
144 | |
145 | #if defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) || (defined(BOOST_GCC) && (BOOST_GCC / 100) <= 406) |
146 | // GCC 4.6 cannot handle defaulted functions with noexcept specifier or virtual functions |
147 | #define BOOST_LOG_NO_CXX11_DEFAULTED_NOEXCEPT_FUNCTIONS |
148 | #define BOOST_LOG_NO_CXX11_DEFAULTED_VIRTUAL_FUNCTIONS |
149 | #endif |
150 | |
151 | #if defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) || (defined(BOOST_CLANG) && ((__clang_major__ == 3) && (__clang_minor__ <= 1))) |
152 | // Clang 3.1 cannot handle a defaulted constexpr constructor in some cases (presumably, if the class contains a member with a constexpr constructor) |
153 | #define BOOST_LOG_NO_CXX11_DEFAULTED_CONSTEXPR_CONSTRUCTORS |
154 | #endif |
155 | |
156 | // The macro indicates that the compiler does not support C++20 pack expansions in lambda init-captures. |
157 | // Early gcc, clang and MSVC versions support C++20 pack expansions in lambda init-captures, |
158 | // but define __cpp_init_captures to a lower value. |
159 | #if (!defined(__cpp_init_captures) || (__cpp_init_captures < 201803)) && \ |
160 | !(\ |
161 | BOOST_CXX_VERSION > 201703 && \ |
162 | (\ |
163 | (defined(BOOST_GCC) && (BOOST_GCC >= 90000)) || \ |
164 | (defined(BOOST_CLANG) && (BOOST_CLANG_VERSION >= 90000)) || \ |
165 | (defined(BOOST_MSVC) && (BOOST_MSVC >= 1922))\ |
166 | )\ |
167 | ) |
168 | #define BOOST_LOG_NO_CXX20_PACK_EXPANSION_IN_LAMBDA_INIT_CAPTURE |
169 | #endif |
170 | |
171 | #if defined(_MSC_VER) |
172 | # define BOOST_LOG_NO_VTABLE __declspec(novtable) |
173 | #else |
174 | # define BOOST_LOG_NO_VTABLE |
175 | #endif |
176 | |
177 | // An MS-like compilers' extension that allows to optimize away the needless code |
178 | #if defined(_MSC_VER) |
179 | # define BOOST_LOG_ASSUME(expr) __assume(expr) |
180 | #elif defined(__has_builtin) |
181 | // Clang 3.6 adds __builtin_assume, but enabling it causes weird compilation errors, where the compiler |
182 | // doesn't see one of attachable_sstream_buf::append overloads. It works fine with Clang 3.7 and later. |
183 | # if __has_builtin(__builtin_assume) && (!defined(__clang__) || (__clang_major__ * 100 + __clang_minor__) >= 307) |
184 | # define BOOST_LOG_ASSUME(expr) __builtin_assume(expr) |
185 | # else |
186 | # define BOOST_LOG_ASSUME(expr) |
187 | # endif |
188 | #else |
189 | # define BOOST_LOG_ASSUME(expr) |
190 | #endif |
191 | |
192 | // The statement marking unreachable branches of code to avoid warnings |
193 | #if defined(BOOST_CLANG) |
194 | # if __has_builtin(__builtin_unreachable) |
195 | # define BOOST_LOG_UNREACHABLE() __builtin_unreachable() |
196 | # endif |
197 | #elif defined(__GNUC__) |
198 | # if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)) |
199 | # define BOOST_LOG_UNREACHABLE() __builtin_unreachable() |
200 | # endif |
201 | #elif defined(_MSC_VER) |
202 | # define BOOST_LOG_UNREACHABLE() __assume(0) |
203 | #endif |
204 | #if !defined(BOOST_LOG_UNREACHABLE) |
205 | # define BOOST_LOG_UNREACHABLE() |
206 | # define BOOST_LOG_UNREACHABLE_RETURN(r) return r |
207 | #else |
208 | # define BOOST_LOG_UNREACHABLE_RETURN(r) BOOST_LOG_UNREACHABLE() |
209 | #endif |
210 | |
211 | // The macro efficiently returns a local lvalue from a function. |
212 | // It employs NRVO, if supported by compiler, or uses a move constructor otherwise. |
213 | #if defined(BOOST_HAS_NRVO) |
214 | #define BOOST_LOG_NRVO_RESULT(x) x |
215 | #else |
216 | #define BOOST_LOG_NRVO_RESULT(x) boost::move(x) |
217 | #endif |
218 | |
219 | // Some compilers support a special attribute that shows that a function won't return |
220 | #if defined(__GNUC__) || (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x590) |
221 | // GCC and Sun Studio 12 support attribute syntax |
222 | # define BOOST_LOG_NORETURN __attribute__((noreturn)) |
223 | #elif defined (_MSC_VER) |
224 | // Microsoft-compatible compilers go here |
225 | # define BOOST_LOG_NORETURN __declspec(noreturn) |
226 | #else |
227 | // The rest compilers might emit bogus warnings about missing return statements |
228 | // in functions with non-void return types when throw_exception is used. |
229 | # define BOOST_LOG_NORETURN |
230 | #endif |
231 | |
232 | // Some compilers may require marking types that may alias other types |
233 | #define BOOST_LOG_MAY_ALIAS BOOST_MAY_ALIAS |
234 | |
235 | #if !defined(BOOST_LOG_BUILDING_THE_LIB) |
236 | |
237 | // Detect if we're dealing with dll |
238 | # if defined(BOOST_LOG_DYN_LINK) || defined(BOOST_ALL_DYN_LINK) |
239 | # define BOOST_LOG_DLL |
240 | # endif |
241 | |
242 | # if defined(BOOST_LOG_DLL) |
243 | # define BOOST_LOG_API BOOST_SYMBOL_IMPORT |
244 | # else |
245 | # define BOOST_LOG_API |
246 | # endif |
247 | // |
248 | // Automatically link to the correct build variant where possible. |
249 | // |
250 | # if !defined(BOOST_ALL_NO_LIB) |
251 | # if !defined(BOOST_LOG_NO_LIB) |
252 | # define BOOST_LIB_NAME boost_log |
253 | # if defined(BOOST_LOG_DLL) |
254 | # define BOOST_DYN_LINK |
255 | # endif |
256 | # include <boost/config/auto_link.hpp> |
257 | # endif |
258 | // In static-library builds compilers ignore auto-link comments from Boost.Log binary to |
259 | // other Boost libraries. We explicitly add comments here for other libraries. |
260 | // In dynamic-library builds this is not needed. |
261 | # if !defined(BOOST_LOG_DLL) |
262 | # include <boost/filesystem/config.hpp> |
263 | // Boost.Thread's config is included below, if needed |
264 | # endif |
265 | # endif // auto-linking disabled |
266 | |
267 | #else // !defined(BOOST_LOG_BUILDING_THE_LIB) |
268 | |
269 | # if defined(BOOST_LOG_DLL) |
270 | # define BOOST_LOG_API BOOST_SYMBOL_EXPORT |
271 | # else |
272 | # define BOOST_LOG_API BOOST_SYMBOL_VISIBLE |
273 | # endif |
274 | |
275 | #endif // !defined(BOOST_LOG_BUILDING_THE_LIB) |
276 | |
277 | // By default we provide support for both char and wchar_t |
278 | #if !defined(BOOST_LOG_WITHOUT_CHAR) |
279 | # define BOOST_LOG_USE_CHAR |
280 | #endif |
281 | #if !defined(BOOST_LOG_WITHOUT_WCHAR_T) |
282 | # define BOOST_LOG_USE_WCHAR_T |
283 | #endif |
284 | |
285 | #if !defined(BOOST_LOG_DOXYGEN_PASS) |
286 | // Check if multithreading is supported |
287 | # if !defined(BOOST_LOG_NO_THREADS) && !defined(BOOST_HAS_THREADS) |
288 | # define BOOST_LOG_NO_THREADS |
289 | # endif // !defined(BOOST_LOG_NO_THREADS) && !defined(BOOST_HAS_THREADS) |
290 | #endif // !defined(BOOST_LOG_DOXYGEN_PASS) |
291 | |
292 | #if !defined(BOOST_LOG_NO_THREADS) |
293 | // We need this header to (i) enable auto-linking with Boost.Thread and |
294 | // (ii) to bring in configuration macros of Boost.Thread. |
295 | # include <boost/thread/detail/config.hpp> |
296 | #endif // !defined(BOOST_LOG_NO_THREADS) |
297 | |
298 | #if !defined(BOOST_LOG_NO_THREADS) |
299 | # define BOOST_LOG_EXPR_IF_MT(expr) expr |
300 | #else |
301 | # undef BOOST_LOG_USE_COMPILER_TLS |
302 | # define BOOST_LOG_EXPR_IF_MT(expr) |
303 | #endif // !defined(BOOST_LOG_NO_THREADS) |
304 | |
305 | #if defined(BOOST_LOG_USE_COMPILER_TLS) |
306 | # if defined(__GNUC__) || defined(__SUNPRO_CC) |
307 | # define BOOST_LOG_TLS __thread |
308 | # elif defined(BOOST_MSVC) |
309 | # define BOOST_LOG_TLS __declspec(thread) |
310 | # else |
311 | # undef BOOST_LOG_USE_COMPILER_TLS |
312 | # endif |
313 | #endif // defined(BOOST_LOG_USE_COMPILER_TLS) |
314 | |
315 | #ifndef BOOST_LOG_CPU_CACHE_LINE_SIZE |
316 | //! The macro defines the CPU cache line size for the target architecture. This is mostly used for optimization. |
317 | #if defined(__s390__) || defined(__s390x__) |
318 | #define BOOST_LOG_CPU_CACHE_LINE_SIZE 256 |
319 | #elif defined(powerpc) || defined(__powerpc__) || defined(__ppc__) |
320 | #define BOOST_LOG_CPU_CACHE_LINE_SIZE 128 |
321 | #else |
322 | #define BOOST_LOG_CPU_CACHE_LINE_SIZE 64 |
323 | #endif |
324 | #endif |
325 | |
326 | namespace boost { |
327 | |
328 | // Setup namespace name |
329 | #if !defined(BOOST_LOG_DOXYGEN_PASS) |
330 | # if defined(BOOST_LOG_DLL) |
331 | # if defined(BOOST_LOG_NO_THREADS) |
332 | # define BOOST_LOG_VERSION_NAMESPACE v2_st |
333 | # else |
334 | # if defined(BOOST_THREAD_PLATFORM_PTHREAD) |
335 | # define BOOST_LOG_VERSION_NAMESPACE v2_mt_posix |
336 | # elif defined(BOOST_THREAD_PLATFORM_WIN32) |
337 | # if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN8 |
338 | # define BOOST_LOG_VERSION_NAMESPACE v2_mt_nt62 |
339 | # elif BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6 |
340 | # define BOOST_LOG_VERSION_NAMESPACE v2_mt_nt6 |
341 | # else |
342 | # define BOOST_LOG_VERSION_NAMESPACE v2_mt_nt5 |
343 | # endif |
344 | # else |
345 | # define BOOST_LOG_VERSION_NAMESPACE v2_mt |
346 | # endif |
347 | # endif // defined(BOOST_LOG_NO_THREADS) |
348 | # else |
349 | # if defined(BOOST_LOG_NO_THREADS) |
350 | # define BOOST_LOG_VERSION_NAMESPACE v2s_st |
351 | # else |
352 | # if defined(BOOST_THREAD_PLATFORM_PTHREAD) |
353 | # define BOOST_LOG_VERSION_NAMESPACE v2s_mt_posix |
354 | # elif defined(BOOST_THREAD_PLATFORM_WIN32) |
355 | # if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN8 |
356 | # define BOOST_LOG_VERSION_NAMESPACE v2s_mt_nt62 |
357 | # elif BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6 |
358 | # define BOOST_LOG_VERSION_NAMESPACE v2s_mt_nt6 |
359 | # else |
360 | # define BOOST_LOG_VERSION_NAMESPACE v2s_mt_nt5 |
361 | # endif |
362 | # else |
363 | # define BOOST_LOG_VERSION_NAMESPACE v2s_mt |
364 | # endif |
365 | # endif // defined(BOOST_LOG_NO_THREADS) |
366 | # endif // defined(BOOST_LOG_DLL) |
367 | |
368 | |
369 | namespace log { |
370 | |
371 | # if !defined(BOOST_NO_CXX11_INLINE_NAMESPACES) |
372 | |
373 | inline namespace BOOST_LOG_VERSION_NAMESPACE {} |
374 | |
375 | # define BOOST_LOG_OPEN_NAMESPACE namespace log { inline namespace BOOST_LOG_VERSION_NAMESPACE { |
376 | # define BOOST_LOG_CLOSE_NAMESPACE }} |
377 | |
378 | # elif defined(BOOST_GCC) && (BOOST_GCC >= 40400) |
379 | |
380 | // GCC 7 deprecated strong using directives but allows inline namespaces in C++03 mode since GCC 4.4. |
381 | __extension__ inline namespace BOOST_LOG_VERSION_NAMESPACE {} |
382 | |
383 | # define BOOST_LOG_OPEN_NAMESPACE namespace log { __extension__ inline namespace BOOST_LOG_VERSION_NAMESPACE { |
384 | # define BOOST_LOG_CLOSE_NAMESPACE }} |
385 | |
386 | # else |
387 | |
388 | namespace BOOST_LOG_VERSION_NAMESPACE {} |
389 | |
390 | using namespace BOOST_LOG_VERSION_NAMESPACE |
391 | # if defined(__GNUC__) && (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) && !defined(__clang__) |
392 | __attribute__((__strong__)) |
393 | # endif |
394 | ; |
395 | |
396 | # define BOOST_LOG_OPEN_NAMESPACE namespace log { namespace BOOST_LOG_VERSION_NAMESPACE { |
397 | # define BOOST_LOG_CLOSE_NAMESPACE }} |
398 | # endif |
399 | |
400 | } // namespace log |
401 | |
402 | #else // !defined(BOOST_LOG_DOXYGEN_PASS) |
403 | |
404 | namespace log {} |
405 | # define BOOST_LOG_OPEN_NAMESPACE namespace log { |
406 | # define BOOST_LOG_CLOSE_NAMESPACE } |
407 | |
408 | #endif // !defined(BOOST_LOG_DOXYGEN_PASS) |
409 | |
410 | #if defined(BOOST_LOG_HAS_PRAGMA_DETECT_MISMATCH) |
411 | #pragma detect_mismatch("boost_log_abi", BOOST_STRINGIZE(BOOST_LOG_VERSION_NAMESPACE)) |
412 | #endif |
413 | |
414 | } // namespace boost |
415 | |
416 | #endif // BOOST_LOG_DETAIL_CONFIG_HPP_INCLUDED_ |
417 | |