CmPlatform.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 CamelotEngine {
  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. /* Finds the compiler type and version.
  39. */
  40. #if defined( __GCCE__ )
  41. # define CM_COMPILER CM_COMPILER_GCCE
  42. # define CM_COMP_VER _MSC_VER
  43. //# include <staticlibinit_gcce.h> // This is a GCCE toolchain workaround needed when compiling with GCCE
  44. #elif defined( __WINSCW__ )
  45. # define CM_COMPILER CM_COMPILER_WINSCW
  46. # define CM_COMP_VER _MSC_VER
  47. #elif defined( _MSC_VER )
  48. # define CM_COMPILER CM_COMPILER_MSVC
  49. # define CM_COMP_VER _MSC_VER
  50. #elif defined( __GNUC__ )
  51. # define CM_COMPILER CM_COMPILER_GNUC
  52. # define CM_COMP_VER (((__GNUC__)*100) + \
  53. (__GNUC_MINOR__*10) + \
  54. __GNUC_PATCHLEVEL__)
  55. #elif defined( __BORLANDC__ )
  56. # define CM_COMPILER CM_COMPILER_BORL
  57. # define CM_COMP_VER __BCPLUSPLUS__
  58. # define __FUNCTION__ __FUNC__
  59. #else
  60. # pragma error "No known compiler. Abort! Abort!"
  61. #endif
  62. /* See if we can use __forceinline or if we need to use __inline instead */
  63. #if CM_COMPILER == CM_COMPILER_MSVC
  64. # if CM_COMP_VER >= 1200
  65. # define FORCEINLINE __forceinline
  66. # endif
  67. #elif defined(__MINGW32__)
  68. # if !defined(FORCEINLINE)
  69. # define FORCEINLINE __inline
  70. # endif
  71. #else
  72. # define FORCEINLINE __inline
  73. #endif
  74. /* Finds the current platform */
  75. #if defined( __WIN32__ ) || defined( _WIN32 )
  76. # define CM_PLATFORM CM_PLATFORM_WIN32
  77. #elif defined( __APPLE_CC__)
  78. # define CM_PLATFORM CM_PLATFORM_APPLE
  79. #else
  80. # define CM_PLATFORM CM_PLATFORM_LINUX
  81. #endif
  82. /* Find the arch type */
  83. #if defined(__x86_64__) || defined(_M_X64) || defined(__powerpc64__) || defined(__alpha__) || defined(__ia64__) || defined(__s390__) || defined(__s390x__)
  84. # define CM_ARCH_TYPE CM_ARCHITECTURE_64
  85. #else
  86. # define CM_ARCH_TYPE CM_ARCHITECTURE_32
  87. #endif
  88. //----------------------------------------------------------------------------
  89. // Windows Settings
  90. #if CM_PLATFORM == CM_PLATFORM_WIN32
  91. // If we're not including this from a client build, specify that the stuff
  92. // should get exported. Otherwise, import it.
  93. # if defined( CM_STATIC_LIB )
  94. // Linux compilers don't have symbol import/export directives.
  95. # define CM_EXPORT
  96. # else
  97. # if defined( CM_DLL )
  98. # define CM_EXPORT __declspec( dllexport )
  99. # else
  100. # if defined( __MINGW32__ )
  101. # define CM_EXPORT
  102. # else
  103. # define CM_EXPORT __declspec( dllimport )
  104. # endif
  105. # endif
  106. # endif
  107. // Win32 compilers use _DEBUG for specifying debug builds.
  108. // for MinGW, we set DEBUG
  109. # if defined(_DEBUG) || defined(DEBUG)
  110. # define CM_DEBUG_MODE 1
  111. # else
  112. # define CM_DEBUG_MODE 0
  113. # endif
  114. #endif // CM_PLATFORM == CM_PLATFORM_WIN32
  115. //----------------------------------------------------------------------------
  116. // Linux/Apple/Symbian Settings
  117. #if CM_PLATFORM == CM_PLATFORM_LINUX || CM_PLATFORM == CM_PLATFORM_APPLE
  118. // Enable GCC symbol visibility
  119. # if defined( CM_GCC_VISIBILITY )
  120. # define CM_EXPORT __attribute__ ((visibility("default")))
  121. # else
  122. # define CM_EXPORT
  123. # endif
  124. // A quick define to overcome different names for the same function
  125. # define stricmp strcasecmp
  126. // Unlike the Win32 compilers, Linux compilers seem to use DEBUG for when
  127. // specifying a debug build.
  128. // (??? this is wrong, on Linux debug builds aren't marked in any way unless
  129. // you mark it yourself any way you like it -- zap ???)
  130. # ifdef DEBUG
  131. # define CM_DEBUG_MODE 1
  132. # else
  133. # define CM_DEBUG_MODE 0
  134. # endif
  135. #if CM_PLATFORM == CM_PLATFORM_APPLE
  136. #define CM_PLATFORM_LIB "CmPlatform.bundle"
  137. #else //CM_PLATFORM_LINUX
  138. #define CM_PLATFORM_LIB "libCmPlatform.so"
  139. #endif
  140. #endif
  141. //----------------------------------------------------------------------------
  142. /* Initial CPU stuff to set.
  143. */
  144. #define CM_CPU_UNKNOWN 0
  145. #define CM_CPU_X86 1
  146. #define CM_CPU_PPC 2
  147. /* Find CPU type
  148. */
  149. #if (defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))) || \
  150. (defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)))
  151. # define CM_CPU CM_CPU_X86
  152. #elif CM_PLATFORM == CM_PLATFORM_APPLE && defined(__BIG_ENDIAN__)
  153. # define CM_CPU CM_CPU_PPC
  154. #elif CM_PLATFORM == CM_PLATFORM_APPLE
  155. # define CM_CPU CM_CPU_X86
  156. #else
  157. # define CM_CPU CM_CPU_UNKNOWN
  158. #endif
  159. /* Find how to declare aligned variable.
  160. */
  161. #if CM_COMPILER == CM_COMPILER_MSVC
  162. # define CM_ALIGNED_DECL(type, var, alignment) __declspec(align(alignment)) type var
  163. #elif CM_COMPILER == CM_COMPILER_GNUC
  164. # define CM_ALIGNED_DECL(type, var, alignment) type var __attribute__((__aligned__(alignment)))
  165. #else
  166. # define CM_ALIGNED_DECL(type, var, alignment) type var
  167. #endif
  168. /** Find perfect alignment (should supports SIMD alignment if SIMD available)
  169. */
  170. #if CM_CPU == CM_CPU_X86
  171. # define CM_SIMD_ALIGNMENT 16
  172. #else
  173. # define CM_SIMD_ALIGNMENT 16
  174. #endif
  175. /* Declare variable aligned to SIMD alignment.
  176. */
  177. #define CM_SIMD_ALIGNED_DECL(type, var) CM_ALIGNED_DECL(type, var, CM_SIMD_ALIGNMENT)
  178. }