Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

177 строки
4.5 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
  5. //
  6. // This library 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. * System, CPU and compiler features.
  19. */
  20. #define LOL_FEATURE_THREADS 1
  21. #define LOL_FEATURE_CHEAP_BRANCHES 1
  22. #define LOL_FEATURE_VERY_CHEAP_BRANCHES 0
  23. #define LOL_FEATURE_VISUAL_STUDIO_THAT_FUCKING_PIECE_OF_SHIT_COMPILER 0
  24. #if defined EMSCRIPTEN
  25. # undef LOL_FEATURE_THREADS
  26. # define LOL_FEATURE_THREADS 0
  27. #endif
  28. /* Use this to disable code that causes compiler crashes. */
  29. #if defined _MSC_VER
  30. # undef LOL_FEATURE_VISUAL_STUDIO_THAT_FUCKING_PIECE_OF_SHIT_COMPILER
  31. # define LOL_FEATURE_VISUAL_STUDIO_THAT_FUCKING_PIECE_OF_SHIT_COMPILER 1
  32. #endif
  33. /*
  34. * Check for C++11 features.
  35. */
  36. /* These features aren't necessarily supported by all compilers */
  37. #undef LOL_FEATURE_CXX11_UNRESTRICTED_UNIONS
  38. #undef LOL_FEATURE_CXX11_INHERIT_CONSTRUCTORS
  39. #undef LOL_FEATURE_CXX11_ARRAY_INITIALIZERS
  40. #undef LOL_FEATURE_CXX11_CONSTEXPR
  41. #undef LOL_FEATURE_CXX11_ISNAN /* FIXME: is this the right place? */
  42. #undef LOL_FEATURE_CXX11_NULLPTR
  43. #undef LOL_FEATURE_CXX11_TEMPLATE_ALIASES
  44. #undef LOL_FEATURE_CXX11_SFINAE_FOR_CTORS
  45. /* Features supported by GCC */
  46. #if defined __GNUC__
  47. # define LOL_FEATURE_CXX11_UNRESTRICTED_UNIONS 1
  48. # define LOL_FEATURE_CXX11_INHERIT_CONSTRUCTORS 1
  49. # if defined(__GXX_EXPERIMENTAL_CXX0X) || __cplusplus >= 201103L
  50. # define LOL_FEATURE_CXX11_CONSTEXPR 1
  51. # define LOL_FEATURE_CXX11_ISNAN 1
  52. # define LOL_FEATURE_CXX11_ARRAY_INITIALIZERS 1
  53. # define LOL_FEATURE_CXX11_NULLPTR 1
  54. # define LOL_FEATURE_CXX11_SFINAE_FOR_CTORS 1
  55. # endif
  56. # if (__GNUC__ * 100 + __GNUC_MINOR__) >= 470
  57. # define LOL_FEATURE_CXX11_TEMPLATE_ALIASES 1
  58. # endif
  59. #endif
  60. /* Features supported by Clang */
  61. #if !defined __GNUC__ && defined __has_feature
  62. # define LOL_FEATURE_CXX11_UNRESTRICTED_UNIONS 1
  63. # define LOL_FEATURE_CXX11_INHERIT_CONSTRUCTORS 1
  64. # define LOL_FEATURE_CXX11_ARRAY_INITIALIZERS 1
  65. # if __has_feature(cxx_constexpr)
  66. # define LOL_FEATURE_CXX11_CONSTEXPR 1
  67. # endif
  68. # define LOL_FEATURE_CXX11_ISNAN 1
  69. # if __has_feature(cxx_nullptr)
  70. # define LOL_FEATURE_CXX11_NULLPTR 1
  71. # endif
  72. # define LOL_FEATURE_CXX11_TEMPLATE_ALIASES 1
  73. # define LOL_FEATURE_CXX11_SFINAE_FOR_CTORS 1
  74. #endif
  75. /* Features supported by Visual Studio */
  76. #if defined _MSC_VER
  77. # define LOL_FEATURE_CXX11_TEMPLATE_ALIASES 1
  78. # define LOL_FEATURE_CXX11_ISNAN 1
  79. # if _MSC_VER >= 1900 /* 2015 CTP (not too bad) */
  80. # define LOL_FEATURE_CXX11_NULLPTR 1
  81. # define LOL_FEATURE_CXX11_SFINAE_FOR_CTORS 1
  82. # define LOL_FEATURE_CXX11_INHERIT_CONSTRUCTORS 1
  83. # endif
  84. # if _MSC_VER < 1800 /* 2012 or older (ugly piece of shit) */
  85. # error "sorry, Visual Studio 2013 or later is needed"
  86. # endif
  87. /* Supported in VS 2015 but causes massive warning output */
  88. # undef LOL_FEATURE_CXX11_UNRESTRICTED_UNIONS
  89. /* Still unsupported as of VS 2015 */
  90. # undef LOL_FEATURE_CXX11_ARRAY_INITIALIZERS
  91. # undef LOL_FEATURE_CXX11_CONSTEXPR
  92. #endif
  93. /*
  94. * Ensure we have ptrdiff_t.
  95. */
  96. #include <cstddef>
  97. /*
  98. * Ensure we have nullptr.
  99. */
  100. #if !LOL_FEATURE_CXX11_NULLPTR
  101. # if defined nullptr
  102. /* do nothing */
  103. # elif defined __GNUC__
  104. # define nullptr __null
  105. # else
  106. # include <cstddef>
  107. # define nullptr NULL
  108. # endif
  109. #endif
  110. /*
  111. * Ensure isnan() is present even on systems that don't define it, or
  112. * when -ffast-math is being used.
  113. */
  114. #include <cmath>
  115. #if defined __FAST_MATH__
  116. # undef isnan
  117. #endif
  118. #if !defined isnan && !LOL_FEATURE_CXX11_ISNAN
  119. # define isnan isnan
  120. # include <stdint.h>
  121. static inline int isnan(float f)
  122. {
  123. union { float f; uint32_t x; } u = { f };
  124. return (u.x << 1) > 0xff000000u;
  125. }
  126. #endif
  127. /*
  128. * A handy endianness test function
  129. */
  130. namespace lol
  131. {
  132. static inline bool is_big_endian()
  133. {
  134. union { int i; char c; } u;
  135. u.i = 1;
  136. return u.c == 0;
  137. }
  138. }
  139. /* XXX: workaround for a compilation bug in NaCl headers */
  140. #if defined __native_client__
  141. # define typeid(x) (*(type_info*)nullptr)
  142. #endif
  143. /* XXX: workaround for X11 headers that try to #define these */
  144. #undef Always
  145. #define Always Always
  146. #undef None
  147. #define None None