config.hpp 16 KB

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