您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

192 行
4.4 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net>
  5. //
  6. // Lol Engine is free software. It comes without any warranty, to
  7. // the extent permitted by applicable law. You can redistribute it
  8. // and/or modify it under the terms of the Do What the Fuck You Want
  9. // to Public License, Version 2, as published by the WTFPL Task Force.
  10. // See http://www.wtfpl.net/ for more details.
  11. //
  12. #pragma once
  13. //
  14. // The build-time features
  15. // -----------------------
  16. //
  17. /*
  18. * Check for C++11 and later features.
  19. */
  20. /* These features aren't necessarily supported by all compilers */
  21. #undef LOL_FEATURE_CXX11_INHERIT_CONSTRUCTORS
  22. #undef LOL_FEATURE_CXX11_ISNAN /* FIXME: is this the right place? */
  23. #undef LOL_FEATURE_CXX11_NULLPTR
  24. #undef LOL_FEATURE_CXX11_TEMPLATE_ALIASES
  25. #undef LOL_FEATURE_CXX11_SFINAE_FOR_CTORS
  26. #undef LOL_FEATURE_CXX17_ATTRIBUTE_NODISCARD
  27. #undef LOL_FEATURE_CXX17_ATTRIBUTE_FALLTHROUGH
  28. /* Features detected through __has_cpp_attribute */
  29. #ifdef __has_cpp_attribute
  30. # if __has_cpp_attribute(nodiscard)
  31. # define LOL_FEATURE_CXX17_ATTRIBUTE_NODISCARD 1
  32. # endif
  33. # if __has_cpp_attribute(fallthrough)
  34. # define LOL_FEATURE_CXX17_ATTRIBUTE_FALLTHROUGH 1
  35. # endif
  36. #endif
  37. /* Features supported by GCC */
  38. #if defined __GNUC__
  39. # if !defined(__GXX_EXPERIMENTAL_CXX0X) && __cplusplus < 201103L
  40. # error "sorry, this version of GCC does not support constexpr"
  41. # endif
  42. # define LOL_FEATURE_CXX11_INHERIT_CONSTRUCTORS 1
  43. # define LOL_FEATURE_CXX11_ISNAN 1
  44. # define LOL_FEATURE_CXX11_NULLPTR 1
  45. # define LOL_FEATURE_CXX11_SFINAE_FOR_CTORS 1
  46. # if (__GNUC__ * 100 + __GNUC_MINOR__) >= 470
  47. # define LOL_FEATURE_CXX11_TEMPLATE_ALIASES 1
  48. # endif
  49. #endif
  50. /* Features supported by Clang */
  51. #if !defined __GNUC__ && defined __has_feature
  52. # define LOL_FEATURE_CXX11_INHERIT_CONSTRUCTORS 1
  53. # if !__has_feature(cxx_constexpr)
  54. # error "sorry, this version of clang does not support constexpr"
  55. # endif
  56. # define LOL_FEATURE_CXX11_ISNAN 1
  57. # if __has_feature(cxx_nullptr)
  58. # define LOL_FEATURE_CXX11_NULLPTR 1
  59. # endif
  60. # define LOL_FEATURE_CXX11_TEMPLATE_ALIASES 1
  61. # define LOL_FEATURE_CXX11_SFINAE_FOR_CTORS 1
  62. #endif
  63. /* Features supported by Visual Studio */
  64. #if defined _MSC_VER
  65. # if _MSC_VER < 1910
  66. # error "sorry, Visual Studio 2017 or later is needed"
  67. # endif
  68. # define LOL_FEATURE_CXX11_TEMPLATE_ALIASES 1
  69. # define LOL_FEATURE_CXX11_ISNAN 1
  70. # define LOL_FEATURE_CXX11_NULLPTR 1
  71. # define LOL_FEATURE_CXX11_SFINAE_FOR_CTORS 1
  72. # define LOL_FEATURE_CXX11_INHERIT_CONSTRUCTORS 1
  73. #endif
  74. /*
  75. * Define some attribute macros.
  76. */
  77. #ifdef __GNUC__
  78. # define LOL_ATTR_FORMAT(n, p) __attribute__((format(printf, n, p)))
  79. #else
  80. # define LOL_ATTR_FORMAT(n, p)
  81. #endif
  82. #if defined(_WIN32)
  83. # define LOL_ATTR_STDCALL __stdcall
  84. #else
  85. # define LOL_ATTR_STDCALL /* */
  86. #endif
  87. #ifdef LOL_FEATURE_CXX17_ATTRIBUTE_NODISCARD
  88. # define LOL_ATTR_NODISCARD [[nodiscard]]
  89. #else
  90. # define LOL_ATTR_NODISCARD /* */
  91. #endif
  92. #ifdef LOL_FEATURE_CXX17_ATTRIBUTE_FALLTHROUGH
  93. # define LOL_ATTR_FALLTHROUGH [[fallthrough]];
  94. #else
  95. # define LOL_ATTR_FALLTHROUGH /* */
  96. #endif
  97. /*
  98. * Ensure we have ptrdiff_t.
  99. */
  100. #include <cstddef>
  101. /*
  102. * Ensure we have nullptr.
  103. */
  104. #if !LOL_FEATURE_CXX11_NULLPTR
  105. # if defined nullptr
  106. /* do nothing */
  107. # elif defined __GNUC__
  108. # define nullptr __null
  109. # else
  110. # include <cstddef>
  111. # define nullptr NULL
  112. # endif
  113. #endif
  114. /*
  115. * Ensure isnan() is present even on systems that don't define it, or
  116. * when -ffast-math is being used.
  117. */
  118. #include <cmath>
  119. #if defined __FAST_MATH__
  120. # undef isnan
  121. #endif
  122. #if !defined isnan && !LOL_FEATURE_CXX11_ISNAN
  123. # define isnan isnan
  124. # include <stdint.h>
  125. static inline int isnan(float f)
  126. {
  127. union { float f; uint32_t x; } u = { f };
  128. return (u.x << 1) > 0xff000000u;
  129. }
  130. #endif
  131. //
  132. // Some feature test functions
  133. //
  134. namespace lol
  135. {
  136. extern bool has_threads();
  137. // A handy endianness test function
  138. static inline bool is_big_endian()
  139. {
  140. union { int i; char c; } u;
  141. u.i = 1;
  142. return u.c == 0;
  143. }
  144. }
  145. //
  146. // Ensure CreateFile2() is available on Mingw
  147. //
  148. #if defined _WIN32 && !defined _MSC_VER && \
  149. (!defined _WIN32_WINNT || _WIN32_WINNT < 0x0602)
  150. # undef _WIN32_WINNT
  151. # define _WIN32_WINNT 0x0602
  152. #endif
  153. /* XXX: workaround for X11 headers that try to #define these */
  154. #undef Always
  155. #define Always Always
  156. #undef None
  157. #define None None