_cfg.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. // Internal header. Config for current compiler/processor/OS
  2. //
  3. // Hardware platforms (CPU):
  4. // __VIC_X86__ - Intel x86 (IA32)
  5. // __VIC_X64__ - x64 AKA x86-64 AKA AMD 64
  6. // __VIC_IA64__ - Intel IA64
  7. // __VIC_SPARC32__ - Sun SPARC 32-bit
  8. // __VIC_SPARC64__ - Sun SPARC 64-bit
  9. // __VIC_POWERPC__ - PowerPC
  10. //
  11. // Software platforms (OS):
  12. // __linux__ - Linux
  13. // __FreeBSD__ - FreeBSD
  14. // __QNX__ - QNX Neutrino
  15. // __sun - Solaris
  16. // __hpux - HP-UX
  17. // _AIX - AIX
  18. // _WIN32 - Windows
  19. //
  20. // Other defines:
  21. // __VIC_STRICT_RAM_ALIGNMENT__ - unaligned data cannot be fetched from RAM
  22. //
  23. // $Id$
  24. //
  25. // (c) __vic 2007
  26. #ifndef __VIC__CFG_H
  27. #define __VIC__CFG_H
  28. //////////////////////////////////////////////////////////////////////////////
  29. // Clang 3.4 or higher
  30. //////////////////////////////////////////////////////////////////////////////
  31. #if defined(__clang__) && (__clang_major__ > 3 || \
  32. __clang_major__ == 3 && __clang_minor__ >= 4)
  33. //////////////////////////////////////////////////////////////////////////////
  34. // GNU C++ 4.7 or higher
  35. //////////////////////////////////////////////////////////////////////////////
  36. #elif defined(__GNUC__) && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 7)
  37. #ifndef _GNU_SOURCE
  38. #define _GNU_SOURCE 1 // use all
  39. #endif
  40. #if defined(__GXX_EXPERIMENTAL_CXX0X__) && !defined(__VIC_NO_NULLPTR_DEF)
  41. #define __VIC_NO_NULLPTR_DEF 1
  42. #endif
  43. // Define SD-6 feature test macros for old versions
  44. #if __GNUC__ < 5 && __cplusplus >= 201103L
  45. // __cplusplus has been correctly defined only since 4.7
  46. #ifndef __cpp_rvalue_references
  47. #define __cpp_rvalue_references 200610
  48. #endif
  49. #ifndef __cpp_variadic_templates
  50. #define __cpp_variadic_templates 200704
  51. #endif
  52. #ifndef __cpp_initializer_lists
  53. #define __cpp_initializer_lists 200806
  54. #endif
  55. #ifndef __cpp_static_assert
  56. #define __cpp_static_assert 200410
  57. #endif
  58. #ifndef __cpp_lambdas
  59. #define __cpp_lambdas 200907
  60. #endif
  61. #ifndef __cpp_decltype
  62. #define __cpp_decltype 200707
  63. #endif
  64. #ifndef __cpp_constexpr
  65. #define __cpp_constexpr 200704
  66. #endif
  67. #ifndef __cpp_unicode_characters
  68. #define __cpp_unicode_characters 200704
  69. #endif
  70. #ifndef __cpp_unicode_literals
  71. #define __cpp_unicode_literals 200710
  72. #endif
  73. #ifndef __cpp_raw_strings
  74. #define __cpp_raw_strings 200710
  75. #endif
  76. #ifndef __cpp_range_based_for
  77. #define __cpp_range_based_for 200907
  78. #endif
  79. #ifndef __cpp_threadsafe_static_init
  80. #define __cpp_threadsafe_static_init 200806
  81. #endif
  82. #ifndef __cpp_nsdmi
  83. #define __cpp_nsdmi 200809
  84. #endif
  85. #ifndef __cpp_alias_templates
  86. #define __cpp_alias_templates 200704
  87. #endif
  88. #ifndef __cpp_delegating_constructors
  89. #define __cpp_delegating_constructors 200604
  90. #endif
  91. #ifndef __cpp_user_defined_literals
  92. #define __cpp_user_defined_literals 200809
  93. #endif
  94. #if __GNUC_MINOR__ >= 8 // 4.8
  95. #ifndef __cpp_attributes
  96. #define __cpp_attributes 200809
  97. #endif
  98. #ifndef __cpp_inheriting_constructors
  99. #define __cpp_inheriting_constructors 200802
  100. #endif
  101. #if __GNUC_PATCHLEVEL__ >= 1 // 4.8.1
  102. #ifndef __cpp_ref_qualifiers
  103. #define __cpp_ref_qualifiers 200710
  104. #endif
  105. #endif // 4.8.1
  106. #endif // 4.8
  107. #endif // SD-6
  108. // GCC bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71214
  109. #if !defined(__cpp_rvalue_references) && defined(__cpp_rvalue_reference)
  110. #define __cpp_rvalue_references __cpp_rvalue_reference
  111. #endif
  112. //////////////////////////////////////////////////////////////////////////////
  113. // Visual C++ 7.1 (Visual Studio 2003) or higher
  114. //////////////////////////////////////////////////////////////////////////////
  115. #elif defined(_MSC_VER) && _MSC_VER >= 1310
  116. // VC++ features: https://msdn.microsoft.com/en-us/library/hh567368.aspx
  117. // VC 15.8 (VS 2017) is the first version that implements feature-test macros
  118. #if _MSC_VER < 1915 && _MSC_VER >= 1600 // VC 10.0 (VS 2010)
  119. #define __VIC_NO_NULLPTR_DEF 1
  120. #ifndef __cpp_rvalue_references
  121. #define __cpp_rvalue_references 1
  122. #endif
  123. #ifndef __cpp_lambdas
  124. #define __cpp_lambdas 1
  125. #endif
  126. #ifndef __cpp_static_assert
  127. #define __cpp_static_assert 1
  128. #endif
  129. #if _MSC_VER >= 1800 // VC 12.0 (VS 2013)
  130. #ifndef __cpp_initializer_lists
  131. #define __cpp_initializer_lists 1
  132. #endif
  133. #ifndef __cpp_alias_templates
  134. #define __cpp_alias_templates 1
  135. #endif
  136. #ifndef __cpp_variadic_templates
  137. #define __cpp_variadic_templates 1
  138. #endif
  139. #if _MSC_VER >= 1900 // VC 14.0 (2015)
  140. #define __VIC_NO_NOEXCEPT_DEF 1
  141. #ifndef __cpp_constexpr
  142. #define __cpp_constexpr 1
  143. #endif
  144. #ifndef __cpp_attributes
  145. #define __cpp_attributes 1
  146. #endif
  147. #ifndef __cpp_unicode_characters
  148. #define __cpp_unicode_characters 1
  149. #endif
  150. #endif // VS 2015
  151. #endif // VS 2013
  152. #endif // VS 2010-2017
  153. //////////////////////////////////////////////////////////////////////////////
  154. // Compiler is not recognized
  155. //////////////////////////////////////////////////////////////////////////////
  156. #else
  157. #error Unsupported compiler
  158. #endif // compilers
  159. //////////////////////////////////////////////////////////////////////////////
  160. // Detect CPU type
  161. //////////////////////////////////////////////////////////////////////////////
  162. #if defined(__GNUC__) || defined(__clang__)
  163. // x64 should be checked first because sometimes x86 macros are defined too
  164. #if defined(__x86_64__) || defined(__amd64__)
  165. #define __VIC_X64__ 1
  166. #define __VIC_CPU_DEFINED 1
  167. #elif defined(__i386__)
  168. #define __VIC_X86__ 1
  169. #define __VIC_CPU_DEFINED 1
  170. #elif defined(__IA64__)
  171. #define __VIC_IA64__ 1
  172. #define __VIC_CPU_DEFINED 1
  173. #elif defined(_POWER) || defined(__PPC__)
  174. #define __VIC_POWERPC__ 1
  175. #define __VIC_CPU_DEFINED 1
  176. #endif
  177. #elif defined(_MSC_VER)
  178. #if defined(_M_X64) || defined(_M_AMD64)
  179. #define __VIC_X64__ 1
  180. #define __VIC_CPU_DEFINED 1
  181. #elif defined(_M_IX86)
  182. #define __VIC_X86__ 1
  183. #define __VIC_CPU_DEFINED 1
  184. #endif
  185. #endif // compiler
  186. #ifndef __VIC_CPU_DEFINED
  187. #error Unsupported processor
  188. #endif
  189. #undef __VIC_CPU_DEFINED
  190. //////////////////////////////////////////////////////////////////////////////
  191. #if !(defined(__VIC_X86__) || defined(__VIC_X64__))
  192. // Memory access to unaligned data will cause bus error
  193. #define __VIC_STRICT_RAM_ALIGNMENT__ 1
  194. #endif
  195. // Always use Large File Support for Linux-x86
  196. #if defined(__linux__) && defined(__VIC_X86__) && \
  197. !defined(__VIC_NO_LARGE_FILE_SUPPORT)
  198. #define _FILE_OFFSET_BITS 64
  199. #endif
  200. //////////////////////////////////////////////////////////////////////////////
  201. // C++23/20/17/14/11/98 compatibility macros
  202. //////////////////////////////////////////////////////////////////////////////
  203. #if __cplusplus < 201103L && !defined(__VIC_NO_NOEXCEPT_DEF)
  204. #define noexcept throw()
  205. #endif
  206. #if defined(_MSC_VER) && _MSC_VER < 0x1400 // VC 8.0 (VS 2005)
  207. #define __VIC_LONGLONG __int64
  208. #define __VIC_PRINTF_ll "I64"
  209. #else
  210. #define __VIC_LONGLONG long long
  211. #define __VIC_PRINTF_ll "ll"
  212. #endif
  213. #if __cplusplus >= 201103L // C++11
  214. # define __VIC_THROWS noexcept(false)
  215. # define __VIC_SWAP_HEADER <utility>
  216. # define __VIC_SCOPED_ENUM_UT_BEGIN(name,type) enum class name : type
  217. # define __VIC_SCOPED_ENUM_BEGIN(name) enum class name
  218. # define __VIC_SCOPED_ENUM_END(name) ; using name##_t = name;
  219. #else // C++98
  220. # define __VIC_THROWS
  221. # define __VIC_SWAP_HEADER <algorithm>
  222. # define __VIC_SCOPED_ENUM_UT_BEGIN(name,type) struct name { enum type_
  223. # define __VIC_SCOPED_ENUM_BEGIN(name) struct name { enum type_
  224. # define __VIC_SCOPED_ENUM_END(name) ; }; typedef name::type_ name##_t;
  225. #endif
  226. #if __cpp_rvalue_references
  227. # define __VIC_STD_MOVE(v) std::move(v)
  228. #else
  229. # define __VIC_STD_MOVE(v) (v)
  230. #endif
  231. #if __cpp_constexpr
  232. # define __VIC_CONSTEXPR_FUNC constexpr
  233. # define __VIC_CONSTEXPR_VAR constexpr
  234. # define __VIC_DEFAULT_CTR =default;
  235. #else
  236. # define __VIC_CONSTEXPR_FUNC inline
  237. # define __VIC_CONSTEXPR_VAR const
  238. # define __VIC_DEFAULT_CTR {}
  239. #endif
  240. #if __cpp_constexpr >= 201304
  241. # define __VIC_CONSTEXPR14 constexpr
  242. #else
  243. # define __VIC_CONSTEXPR14 inline
  244. #endif
  245. #if __cpp_inline_variables
  246. # define __VIC_INLINE_CONSTEXPR_VAR inline __VIC_CONSTEXPR_VAR
  247. #else
  248. # define __VIC_INLINE_CONSTEXPR_VAR __VIC_CONSTEXPR_VAR
  249. #endif
  250. #if __cpp_if_consteval
  251. # define __VIC_IF_CONSTEVAL if consteval
  252. # define __VIC_IF_NOT_CONSTEVAL if !consteval
  253. #else
  254. # define __VIC_IF_CONSTEVAL if(std::is_constant_evaluated())
  255. # define __VIC_IF_NOT_CONSTEVAL if(!std::is_constant_evaluated())
  256. #endif
  257. #ifndef __has_include
  258. # define __has_include(f) 0
  259. #endif
  260. #ifndef __has_cpp_attribute
  261. # define __has_cpp_attribute(a) 0
  262. #endif
  263. #if __cpp_attributes && __has_cpp_attribute(nodiscard) && \
  264. !defined(__clang__)
  265. // Clang 3.9+ issue - https://bugs.llvm.org/show_bug.cgi?id=33518
  266. # define __VIC_NODISCARD [[nodiscard]]
  267. #else
  268. # define __VIC_NODISCARD
  269. #endif
  270. #if __cpp_attributes
  271. # define __VIC_NORETURN [[noreturn]]
  272. #else
  273. # if defined(__GNUC__)
  274. # define __VIC_NORETURN __attribute__((noreturn))
  275. # elif defined(_MSC_VER)
  276. # define __VIC_NORETURN __declspec(noreturn)
  277. # else
  278. # define __VIC_NORETURN
  279. # endif
  280. #endif
  281. //////////////////////////////////////////////////////////////////////////////
  282. #endif // header guard