CmPlatform.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. -----------------------------------------------------------------------------
  3. This source file is part of OGRE
  4. (Object-oriented Graphics Rendering Engine)
  5. For the latest info, see http://www.ogre3d.org/
  6. Copyright (c) 2000-2011 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. -----------------------------------------------------------------------------
  23. */
  24. #pragma once
  25. namespace CamelotFramework {
  26. /* Initial platform/compiler-related stuff to set.
  27. */
  28. #define CM_PLATFORM_WIN32 1
  29. #define CM_PLATFORM_LINUX 2
  30. #define CM_PLATFORM_APPLE 3
  31. #define CM_COMPILER_MSVC 1
  32. #define CM_COMPILER_GNUC 2
  33. #define CM_COMPILER_BORL 3
  34. #define CM_COMPILER_WINSCW 4
  35. #define CM_COMPILER_GCCE 5
  36. #define CM_ARCHITECTURE_32 1
  37. #define CM_ARCHITECTURE_64 2
  38. #define CM_ENDIAN_LITTLE 1
  39. #define CM_ENDIAN_BIG 2
  40. #define CM_ENDIAN CM_ENDIAN_LITTLE
  41. /* Finds the compiler type and version.
  42. */
  43. #if defined( __GCCE__ )
  44. # define CM_COMPILER CM_COMPILER_GCCE
  45. # define CM_COMP_VER _MSC_VER
  46. //# include <staticlibinit_gcce.h> // This is a GCCE toolchain workaround needed when compiling with GCCE
  47. #elif defined( __WINSCW__ )
  48. # define CM_COMPILER CM_COMPILER_WINSCW
  49. # define CM_COMP_VER _MSC_VER
  50. #elif defined( _MSC_VER )
  51. # define CM_COMPILER CM_COMPILER_MSVC
  52. # define CM_COMP_VER _MSC_VER
  53. #elif defined( __GNUC__ )
  54. # define CM_COMPILER CM_COMPILER_GNUC
  55. # define CM_COMP_VER (((__GNUC__)*100) + \
  56. (__GNUC_MINOR__*10) + \
  57. __GNUC_PATCHLEVEL__)
  58. #elif defined( __BORLANDC__ )
  59. # define CM_COMPILER CM_COMPILER_BORL
  60. # define CM_COMP_VER __BCPLUSPLUS__
  61. # define __FUNCTION__ __FUNC__
  62. #else
  63. # pragma error "No known compiler. Abort! Abort!"
  64. #endif
  65. /* See if we can use __forceinline or if we need to use __inline instead */
  66. #if CM_COMPILER == CM_COMPILER_MSVC
  67. # if CM_COMP_VER >= 1200
  68. # define FORCEINLINE __forceinline
  69. # endif
  70. #elif defined(__MINGW32__)
  71. # if !defined(FORCEINLINE)
  72. # define FORCEINLINE __inline
  73. # endif
  74. #else
  75. # define FORCEINLINE __inline
  76. #endif
  77. /* Finds the current platform */
  78. #if defined( __WIN32__ ) || defined( _WIN32 )
  79. # define CM_PLATFORM CM_PLATFORM_WIN32
  80. #elif defined( __APPLE_CC__)
  81. # define CM_PLATFORM CM_PLATFORM_APPLE
  82. #else
  83. # define CM_PLATFORM CM_PLATFORM_LINUX
  84. #endif
  85. /* Find the arch type */
  86. #if defined(__x86_64__) || defined(_M_X64) || defined(__powerpc64__) || defined(__alpha__) || defined(__ia64__) || defined(__s390__) || defined(__s390x__)
  87. # define CM_ARCH_TYPE CM_ARCHITECTURE_64
  88. #else
  89. # define CM_ARCH_TYPE CM_ARCHITECTURE_32
  90. #endif
  91. //----------------------------------------------------------------------------
  92. // Windows Settings
  93. #if CM_PLATFORM == CM_PLATFORM_WIN32
  94. // If we're not including this from a client build, specify that the stuff
  95. // should get exported. Otherwise, import it.
  96. # if defined( CM_STATIC_LIB )
  97. // Linux compilers don't have symbol import/export directives.
  98. # define CM_UTILITY_EXPORT
  99. # else
  100. # if defined( CM_UTILITY_EXPORTS )
  101. # define CM_UTILITY_EXPORT __declspec( dllexport )
  102. # else
  103. # if defined( __MINGW32__ )
  104. # define CM_UTILITY_EXPORT
  105. # else
  106. # define CM_UTILITY_EXPORT __declspec( dllimport )
  107. # endif
  108. # endif
  109. # endif
  110. // Win32 compilers use _DEBUG for specifying debug builds.
  111. // for MinGW, we set DEBUG
  112. # if defined(_DEBUG) || defined(DEBUG)
  113. # define CM_DEBUG_MODE 1
  114. # else
  115. # define CM_DEBUG_MODE 0
  116. # endif
  117. #endif // CM_PLATFORM == CM_PLATFORM_WIN32
  118. //----------------------------------------------------------------------------
  119. // Linux/Apple/Symbian Settings
  120. #if CM_PLATFORM == CM_PLATFORM_LINUX || CM_PLATFORM == CM_PLATFORM_APPLE
  121. // Enable GCC symbol visibility
  122. # if defined( CM_GCC_VISIBILITY )
  123. # define CM_UTILITY_EXPORT __attribute__ ((visibility("default")))
  124. # else
  125. # define CM_UTILITY_EXPORT
  126. # endif
  127. // A quick define to overcome different names for the same function
  128. # define stricmp strcasecmp
  129. // Unlike the Win32 compilers, Linux compilers seem to use DEBUG for when
  130. // specifying a debug build.
  131. // (??? this is wrong, on Linux debug builds aren't marked in any way unless
  132. // you mark it yourself any way you like it -- zap ???)
  133. # ifdef DEBUG
  134. # define CM_DEBUG_MODE 1
  135. # else
  136. # define CM_DEBUG_MODE 0
  137. # endif
  138. #if CM_PLATFORM == CM_PLATFORM_APPLE
  139. #define CM_PLATFORM_LIB "CmPlatform.bundle"
  140. #else //CM_PLATFORM_LINUX
  141. #define CM_PLATFORM_LIB "libCmPlatform.so"
  142. #endif
  143. #endif
  144. //----------------------------------------------------------------------------
  145. /* Initial CPU stuff to set.
  146. */
  147. #define CM_CPU_UNKNOWN 0
  148. #define CM_CPU_X86 1
  149. #define CM_CPU_PPC 2
  150. /* Find CPU type
  151. */
  152. #if (defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))) || \
  153. (defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)))
  154. # define CM_CPU CM_CPU_X86
  155. #elif CM_PLATFORM == CM_PLATFORM_APPLE && defined(__BIG_ENDIAN__)
  156. # define CM_CPU CM_CPU_PPC
  157. #elif CM_PLATFORM == CM_PLATFORM_APPLE
  158. # define CM_CPU CM_CPU_X86
  159. #else
  160. # define CM_CPU CM_CPU_UNKNOWN
  161. #endif
  162. /* Find how to declare aligned variable.
  163. */
  164. #if CM_COMPILER == CM_COMPILER_MSVC
  165. # define CM_ALIGNED_DECL(type, var, alignment) __declspec(align(alignment)) type var
  166. #elif CM_COMPILER == CM_COMPILER_GNUC
  167. # define CM_ALIGNED_DECL(type, var, alignment) type var __attribute__((__aligned__(alignment)))
  168. #else
  169. # define CM_ALIGNED_DECL(type, var, alignment) type var
  170. #endif
  171. /** Find perfect alignment (should supports SIMD alignment if SIMD available)
  172. */
  173. #if CM_CPU == CM_CPU_X86
  174. # define CM_SIMD_ALIGNMENT 16
  175. #else
  176. # define CM_SIMD_ALIGNMENT 16
  177. #endif
  178. /* Declare variable aligned to SIMD alignment.
  179. */
  180. #define CM_SIMD_ALIGNED_DECL(type, var) CM_ALIGNED_DECL(type, var, CM_SIMD_ALIGNMENT)
  181. }