CmPlatformDefines.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #pragma once
  2. // Initial platform/compiler-related stuff to set.
  3. #define CM_PLATFORM_WIN32 1
  4. #define CM_PLATFORM_LINUX 2
  5. #define CM_PLATFORM_APPLE 3
  6. #define CM_COMPILER_MSVC 1
  7. #define CM_COMPILER_GNUC 2
  8. #define CM_COMPILER_INTEL 3
  9. #define CM_COMPILER_CLANG 4
  10. #define CM_ARCHITECTURE_x86_32 1
  11. #define CM_ARCHITECTURE_x86_64 2
  12. #define CM_ENDIAN_LITTLE 1
  13. #define CM_ENDIAN_BIG 2
  14. #define CM_ENDIAN CM_ENDIAN_LITTLE
  15. // Finds the compiler type and version.
  16. #if defined( _MSC_VER )
  17. # define CM_COMPILER CM_COMPILER_MSVC
  18. # define CM_COMP_VER _MSC_VER
  19. # define CM_THREADLOCAL __declspec(thread)
  20. #elif defined( __GNUC__ )
  21. # define CM_COMPILER CM_COMPILER_GNUC
  22. # define CM_COMP_VER (((__GNUC__)*100) + \
  23. (__GNUC_MINOR__*10) + \
  24. __GNUC_PATCHLEVEL__)
  25. # define CM_THREADLOCAL __thread
  26. #elif defined ( __INTEL_COMPILER )
  27. # define CM_COMPILER CM_COMPILER_INTEL
  28. # define CM_COMP_VER __INTEL_COMPILER
  29. // CM_THREADLOCAL define is down below because Intel compiler defines it differently based on platform
  30. #elif defined ( __clang__ )
  31. # define CM_COMPILER CM_COMPILER_CLANG
  32. # define CM_COMP_VER __clang_major__
  33. # define CM_THREADLOCAL __thread
  34. #else
  35. # pragma error "No known compiler. "
  36. #endif
  37. // See if we can use __forceinline or if we need to use __inline instead
  38. #if CM_COMPILER == CM_COMPILER_MSVC
  39. # if CM_COMP_VER >= 1200
  40. # define FORCEINLINE __forceinline
  41. # endif
  42. #elif defined(__MINGW32__)
  43. # if !defined(FORCEINLINE)
  44. # define FORCEINLINE __inline
  45. # endif
  46. #else
  47. # define FORCEINLINE __inline
  48. #endif
  49. // Finds the current platform
  50. #if defined( __WIN32__ ) || defined( _WIN32 )
  51. # define CM_PLATFORM CM_PLATFORM_WIN32
  52. #elif defined( __APPLE_CC__)
  53. # define CM_PLATFORM CM_PLATFORM_APPLE
  54. #else
  55. # define CM_PLATFORM CM_PLATFORM_LINUX
  56. #endif
  57. // Find the architecture type
  58. #if defined(__x86_64__) || defined(_M_X64)
  59. # define CM_ARCH_TYPE CM_ARCHITECTURE_x86_64
  60. #else
  61. # define CM_ARCH_TYPE CM_ARCHITECTURE_x86_32
  62. #endif
  63. // Windows Settings
  64. #if CM_PLATFORM == CM_PLATFORM_WIN32
  65. // If we're not including this from a client build, specify that the stuff
  66. // should get exported. Otherwise, import it.
  67. # if defined( CM_STATIC_LIB )
  68. // Linux compilers don't have symbol import/export directives.
  69. # define CM_UTILITY_EXPORT
  70. # else
  71. # if defined( CM_UTILITY_EXPORTS )
  72. # define CM_UTILITY_EXPORT __declspec( dllexport )
  73. # else
  74. # if defined( __MINGW32__ )
  75. # define CM_UTILITY_EXPORT
  76. # else
  77. # define CM_UTILITY_EXPORT __declspec( dllimport )
  78. # endif
  79. # endif
  80. # endif
  81. // Win32 compilers use _DEBUG for specifying debug builds.
  82. // for MinGW, we set DEBUG
  83. # if defined(_DEBUG) || defined(DEBUG)
  84. # define CM_DEBUG_MODE 1
  85. # else
  86. # define CM_DEBUG_MODE 0
  87. # endif
  88. # if CM_COMPILER == CM_COMPILER_INTEL
  89. # define CM_THREADLOCAL __declspec(thread)
  90. # endif
  91. #endif // CM_PLATFORM == CM_PLATFORM_WIN32
  92. // Linux/Apple Settings
  93. #if CM_PLATFORM == CM_PLATFORM_LINUX || CM_PLATFORM == CM_PLATFORM_APPLE
  94. // Enable GCC symbol visibility
  95. # if defined( CM_GCC_VISIBILITY )
  96. # define CM_UTILITY_EXPORT __attribute__ ((visibility("default")))
  97. # else
  98. # define CM_UTILITY_EXPORT
  99. # endif
  100. # ifdef DEBUG
  101. # define CM_DEBUG_MODE 1
  102. # else
  103. # define CM_DEBUG_MODE 0
  104. # endif
  105. # if CM_COMPILER == CM_COMPILER_INTEL
  106. # define CM_THREADLOCAL __thread
  107. # endif
  108. #if CM_PLATFORM == CM_PLATFORM_APPLE
  109. #define CM_PLATFORM_LIB "CmPlatform.bundle"
  110. #else //CM_PLATFORM_LINUX
  111. #define CM_PLATFORM_LIB "libCmPlatform.so"
  112. #endif
  113. #endif