config.hpp 15 KB

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