config.hpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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) || (defined(_MSVC_STL_VERSION) && _MSVC_STL_VERSION < 142)
  85. // The compiler does not support std::codecvt<char16_t> and std::codecvt<char32_t> specializations.
  86. // The BOOST_NO_CXX11_HDR_CODECVT means there's no usable <codecvt>, which is slightly different from this macro.
  87. // But in order for <codecvt> to be implemented the std::codecvt specializations have to be implemented as well.
  88. // We need to check the C++ version as well, since <codecvt> is deprecated from C++17 onwards which may cause
  89. // BOOST_NO_CXX11_HDR_CODECVT to be set, even though std::codecvt in <locale> is just fine.
  90. # define BOOST_LOG_NO_CXX11_CODECVT_FACETS
  91. #endif
  92. #if defined(__CYGWIN__)
  93. // Boost.ASIO is broken on Cygwin
  94. # define BOOST_LOG_NO_ASIO
  95. #endif
  96. #if defined(__VXWORKS__)
  97. # define BOOST_LOG_NO_GETPGRP
  98. # define BOOST_LOG_NO_GETSID
  99. // for _WRS_CONFIG_USER_MANAGEMENT used below
  100. # include <vsbConfig.h>
  101. #endif
  102. #if (!defined(__CRYSTAX__) && defined(__ANDROID__) && (__ANDROID_API__ < 21)) \
  103. || (defined(__VXWORKS__) && !defined(_WRS_CONFIG_USER_MANAGEMENT))
  104. // Until Android API version 21 Google NDK does not provide getpwuid_r
  105. # define BOOST_LOG_NO_GETPWUID_R
  106. #endif
  107. #if !defined(BOOST_LOG_USE_NATIVE_SYSLOG) && defined(BOOST_LOG_NO_ASIO)
  108. # ifndef BOOST_LOG_WITHOUT_SYSLOG
  109. # define BOOST_LOG_WITHOUT_SYSLOG
  110. # endif
  111. #endif
  112. #if defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ <= 2)
  113. // GCC 4.1 and 4.2 have buggy anonymous namespaces support, which interferes with symbol linkage
  114. # define BOOST_LOG_ANONYMOUS_NAMESPACE namespace anonymous {} using namespace anonymous; namespace anonymous
  115. #else
  116. # define BOOST_LOG_ANONYMOUS_NAMESPACE namespace
  117. #endif
  118. #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || (defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ <= 6))
  119. // GCC up to 4.6 (inclusively) did not support expanding template argument packs into non-variadic template arguments
  120. #define BOOST_LOG_NO_CXX11_ARG_PACKS_TO_NON_VARIADIC_ARGS_EXPANSION
  121. #endif
  122. #if defined(BOOST_NO_CXX11_CONSTEXPR) || (defined(BOOST_GCC) && (BOOST_GCC / 100) <= 406)
  123. // GCC 4.6 does not support in-class brace initializers for static constexpr array members
  124. #define BOOST_LOG_NO_CXX11_CONSTEXPR_DATA_MEMBER_BRACE_INITIALIZERS
  125. #endif
  126. #if defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) || (defined(BOOST_GCC) && (BOOST_GCC / 100) <= 406)
  127. // GCC 4.6 cannot handle defaulted functions with noexcept specifier or virtual functions
  128. #define BOOST_LOG_NO_CXX11_DEFAULTED_NOEXCEPT_FUNCTIONS
  129. #define BOOST_LOG_NO_CXX11_DEFAULTED_VIRTUAL_FUNCTIONS
  130. #endif
  131. #if defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) || (defined(BOOST_CLANG) && ((__clang_major__ == 3) && (__clang_minor__ <= 1)))
  132. // Clang 3.1 cannot handle a defaulted constexpr constructor in some cases (presumably, if the class contains a member with a constexpr constructor)
  133. #define BOOST_LOG_NO_CXX11_DEFAULTED_CONSTEXPR_CONSTRUCTORS
  134. #endif
  135. // The macro indicates that the compiler does not support C++20 pack expansions in lambda init-captures.
  136. // Early gcc, clang and MSVC versions support C++20 pack expansions in lambda init-captures,
  137. // but define __cpp_init_captures to a lower value.
  138. #if (!defined(__cpp_init_captures) || (__cpp_init_captures < 201803)) && \
  139. !(\
  140. BOOST_CXX_VERSION > 201703 && \
  141. (\
  142. (defined(BOOST_GCC) && (BOOST_GCC >= 90000)) || \
  143. (defined(BOOST_CLANG) && (BOOST_CLANG_VERSION >= 90000)) || \
  144. (defined(BOOST_MSVC) && (BOOST_MSVC >= 1922))\
  145. )\
  146. )
  147. #define BOOST_LOG_NO_CXX20_PACK_EXPANSION_IN_LAMBDA_INIT_CAPTURE
  148. #endif
  149. #if defined(_MSC_VER)
  150. # define BOOST_LOG_NO_VTABLE __declspec(novtable)
  151. #else
  152. # define BOOST_LOG_NO_VTABLE
  153. #endif
  154. // An MS-like compilers' extension that allows to optimize away the needless code
  155. #if defined(_MSC_VER)
  156. # define BOOST_LOG_ASSUME(expr) __assume(expr)
  157. #elif defined(__has_builtin)
  158. // Clang 3.6 adds __builtin_assume, but enabling it causes weird compilation errors, where the compiler
  159. // doesn't see one of attachable_sstream_buf::append overloads. It works fine with Clang 3.7 and later.
  160. # if __has_builtin(__builtin_assume) && (!defined(__clang__) || (__clang_major__ * 100 + __clang_minor__) >= 307)
  161. # define BOOST_LOG_ASSUME(expr) __builtin_assume(expr)
  162. # else
  163. # define BOOST_LOG_ASSUME(expr)
  164. # endif
  165. #else
  166. # define BOOST_LOG_ASSUME(expr)
  167. #endif
  168. // The statement marking unreachable branches of code to avoid warnings
  169. #if defined(BOOST_CLANG)
  170. # if __has_builtin(__builtin_unreachable)
  171. # define BOOST_LOG_UNREACHABLE() __builtin_unreachable()
  172. # endif
  173. #elif defined(__GNUC__)
  174. # if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
  175. # define BOOST_LOG_UNREACHABLE() __builtin_unreachable()
  176. # endif
  177. #elif defined(_MSC_VER)
  178. # define BOOST_LOG_UNREACHABLE() __assume(0)
  179. #endif
  180. #if !defined(BOOST_LOG_UNREACHABLE)
  181. # define BOOST_LOG_UNREACHABLE()
  182. # define BOOST_LOG_UNREACHABLE_RETURN(r) return r
  183. #else
  184. # define BOOST_LOG_UNREACHABLE_RETURN(r) BOOST_LOG_UNREACHABLE()
  185. #endif
  186. // The macro efficiently returns a local lvalue from a function.
  187. // It employs NRVO, if supported by compiler, or uses a move constructor otherwise.
  188. #if defined(BOOST_HAS_NRVO)
  189. #define BOOST_LOG_NRVO_RESULT(x) x
  190. #else
  191. #define BOOST_LOG_NRVO_RESULT(x) boost::move(x)
  192. #endif
  193. // Some compilers support a special attribute that shows that a function won't return
  194. #if defined(__GNUC__) || (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x590)
  195. // GCC and Sun Studio 12 support attribute syntax
  196. # define BOOST_LOG_NORETURN __attribute__((noreturn))
  197. #elif defined (_MSC_VER)
  198. // Microsoft-compatible compilers go here
  199. # define BOOST_LOG_NORETURN __declspec(noreturn)
  200. #else
  201. // The rest compilers might emit bogus warnings about missing return statements
  202. // in functions with non-void return types when throw_exception is used.
  203. # define BOOST_LOG_NORETURN
  204. #endif
  205. // Some compilers may require marking types that may alias other types
  206. #define BOOST_LOG_MAY_ALIAS BOOST_MAY_ALIAS
  207. #if !defined(BOOST_LOG_BUILDING_THE_LIB)
  208. // Detect if we're dealing with dll
  209. # if defined(BOOST_LOG_DYN_LINK) || defined(BOOST_ALL_DYN_LINK)
  210. # define BOOST_LOG_DLL
  211. # endif
  212. # if defined(BOOST_LOG_DLL)
  213. # define BOOST_LOG_API BOOST_SYMBOL_IMPORT
  214. # else
  215. # define BOOST_LOG_API
  216. # endif
  217. //
  218. // Automatically link to the correct build variant where possible.
  219. //
  220. # if !defined(BOOST_ALL_NO_LIB)
  221. # if !defined(BOOST_LOG_NO_LIB)
  222. # define BOOST_LIB_NAME boost_log
  223. # if defined(BOOST_LOG_DLL)
  224. # define BOOST_DYN_LINK
  225. # endif
  226. # include <boost/config/auto_link.hpp>
  227. # endif
  228. // In static-library builds compilers ignore auto-link comments from Boost.Log binary to
  229. // other Boost libraries. We explicitly add comments here for other libraries.
  230. // In dynamic-library builds this is not needed.
  231. # if !defined(BOOST_LOG_DLL)
  232. # include <boost/filesystem/config.hpp>
  233. // Boost.Thread's config is included below, if needed
  234. # endif
  235. # endif // auto-linking disabled
  236. #else // !defined(BOOST_LOG_BUILDING_THE_LIB)
  237. # if defined(BOOST_LOG_DLL)
  238. # define BOOST_LOG_API BOOST_SYMBOL_EXPORT
  239. # else
  240. # define BOOST_LOG_API BOOST_SYMBOL_VISIBLE
  241. # endif
  242. #endif // !defined(BOOST_LOG_BUILDING_THE_LIB)
  243. // By default we provide support for both char and wchar_t
  244. #if !defined(BOOST_LOG_WITHOUT_CHAR)
  245. # define BOOST_LOG_USE_CHAR
  246. #endif
  247. #if !defined(BOOST_LOG_WITHOUT_WCHAR_T)
  248. # define BOOST_LOG_USE_WCHAR_T
  249. #endif
  250. #if !defined(BOOST_LOG_DOXYGEN_PASS)
  251. // Check if multithreading is supported
  252. # if !defined(BOOST_LOG_NO_THREADS) && !defined(BOOST_HAS_THREADS)
  253. # define BOOST_LOG_NO_THREADS
  254. # endif // !defined(BOOST_LOG_NO_THREADS) && !defined(BOOST_HAS_THREADS)
  255. #endif // !defined(BOOST_LOG_DOXYGEN_PASS)
  256. #if !defined(BOOST_LOG_NO_THREADS)
  257. // We need this header to (i) enable auto-linking with Boost.Thread and
  258. // (ii) to bring in configuration macros of Boost.Thread.
  259. # include <boost/thread/detail/config.hpp>
  260. #endif // !defined(BOOST_LOG_NO_THREADS)
  261. #if !defined(BOOST_LOG_NO_THREADS)
  262. # define BOOST_LOG_EXPR_IF_MT(expr) expr
  263. #else
  264. # undef BOOST_LOG_USE_COMPILER_TLS
  265. # define BOOST_LOG_EXPR_IF_MT(expr)
  266. #endif // !defined(BOOST_LOG_NO_THREADS)
  267. #if defined(BOOST_LOG_USE_COMPILER_TLS)
  268. # if defined(__GNUC__) || defined(__SUNPRO_CC)
  269. # define BOOST_LOG_TLS __thread
  270. # elif defined(BOOST_MSVC)
  271. # define BOOST_LOG_TLS __declspec(thread)
  272. # else
  273. # undef BOOST_LOG_USE_COMPILER_TLS
  274. # endif
  275. #endif // defined(BOOST_LOG_USE_COMPILER_TLS)
  276. #ifndef BOOST_LOG_CPU_CACHE_LINE_SIZE
  277. //! The macro defines the CPU cache line size for the target architecture. This is mostly used for optimization.
  278. #if defined(__s390__) || defined(__s390x__)
  279. #define BOOST_LOG_CPU_CACHE_LINE_SIZE 256
  280. #elif defined(powerpc) || defined(__powerpc__) || defined(__ppc__)
  281. #define BOOST_LOG_CPU_CACHE_LINE_SIZE 128
  282. #else
  283. #define BOOST_LOG_CPU_CACHE_LINE_SIZE 64
  284. #endif
  285. #endif
  286. namespace boost {
  287. // Setup namespace name
  288. #if !defined(BOOST_LOG_DOXYGEN_PASS)
  289. # if defined(BOOST_LOG_DLL)
  290. # if defined(BOOST_LOG_NO_THREADS)
  291. # define BOOST_LOG_VERSION_NAMESPACE v2_st
  292. # else
  293. # if defined(BOOST_THREAD_PLATFORM_PTHREAD)
  294. # define BOOST_LOG_VERSION_NAMESPACE v2_mt_posix
  295. # elif defined(BOOST_THREAD_PLATFORM_WIN32)
  296. # if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN8
  297. # define BOOST_LOG_VERSION_NAMESPACE v2_mt_nt62
  298. # elif BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
  299. # define BOOST_LOG_VERSION_NAMESPACE v2_mt_nt6
  300. # else
  301. # define BOOST_LOG_VERSION_NAMESPACE v2_mt_nt5
  302. # endif
  303. # else
  304. # define BOOST_LOG_VERSION_NAMESPACE v2_mt
  305. # endif
  306. # endif // defined(BOOST_LOG_NO_THREADS)
  307. # else
  308. # if defined(BOOST_LOG_NO_THREADS)
  309. # define BOOST_LOG_VERSION_NAMESPACE v2s_st
  310. # else
  311. # if defined(BOOST_THREAD_PLATFORM_PTHREAD)
  312. # define BOOST_LOG_VERSION_NAMESPACE v2s_mt_posix
  313. # elif defined(BOOST_THREAD_PLATFORM_WIN32)
  314. # if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN8
  315. # define BOOST_LOG_VERSION_NAMESPACE v2s_mt_nt62
  316. # elif BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
  317. # define BOOST_LOG_VERSION_NAMESPACE v2s_mt_nt6
  318. # else
  319. # define BOOST_LOG_VERSION_NAMESPACE v2s_mt_nt5
  320. # endif
  321. # else
  322. # define BOOST_LOG_VERSION_NAMESPACE v2s_mt
  323. # endif
  324. # endif // defined(BOOST_LOG_NO_THREADS)
  325. # endif // defined(BOOST_LOG_DLL)
  326. namespace log {
  327. # if !defined(BOOST_NO_CXX11_INLINE_NAMESPACES)
  328. inline namespace BOOST_LOG_VERSION_NAMESPACE {}
  329. # define BOOST_LOG_OPEN_NAMESPACE namespace log { inline namespace BOOST_LOG_VERSION_NAMESPACE {
  330. # define BOOST_LOG_CLOSE_NAMESPACE }}
  331. # elif defined(BOOST_GCC) && (BOOST_GCC >= 40400)
  332. // GCC 7 deprecated strong using directives but allows inline namespaces in C++03 mode since GCC 4.4.
  333. __extension__ inline namespace BOOST_LOG_VERSION_NAMESPACE {}
  334. # define BOOST_LOG_OPEN_NAMESPACE namespace log { __extension__ inline namespace BOOST_LOG_VERSION_NAMESPACE {
  335. # define BOOST_LOG_CLOSE_NAMESPACE }}
  336. # else
  337. namespace BOOST_LOG_VERSION_NAMESPACE {}
  338. using namespace BOOST_LOG_VERSION_NAMESPACE
  339. # if defined(__GNUC__) && (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) && !defined(__clang__)
  340. __attribute__((__strong__))
  341. # endif
  342. ;
  343. # define BOOST_LOG_OPEN_NAMESPACE namespace log { namespace BOOST_LOG_VERSION_NAMESPACE {
  344. # define BOOST_LOG_CLOSE_NAMESPACE }}
  345. # endif
  346. } // namespace log
  347. #else // !defined(BOOST_LOG_DOXYGEN_PASS)
  348. namespace log {}
  349. # define BOOST_LOG_OPEN_NAMESPACE namespace log {
  350. # define BOOST_LOG_CLOSE_NAMESPACE }
  351. #endif // !defined(BOOST_LOG_DOXYGEN_PASS)
  352. #if defined(BOOST_LOG_HAS_PRAGMA_DETECT_MISMATCH)
  353. #pragma detect_mismatch("boost_log_abi", BOOST_STRINGIZE(BOOST_LOG_VERSION_NAMESPACE))
  354. #endif
  355. } // namespace boost
  356. #endif // BOOST_LOG_DETAIL_CONFIG_HPP_INCLUDED_