CMakeCCompilerId.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. #ifdef __cplusplus
  2. # error "A C++ compiler has been selected for C."
  3. #endif
  4. #if defined(__18CXX)
  5. # define ID_VOID_MAIN
  6. #endif
  7. #if defined(__INTEL_COMPILER) || defined(__ICC)
  8. # define COMPILER_ID "Intel"
  9. #elif defined(__clang__)
  10. # define COMPILER_ID "Clang"
  11. #elif defined(__BORLANDC__)
  12. # define COMPILER_ID "Borland"
  13. #elif defined(__WATCOMC__)
  14. # define COMPILER_ID "Watcom"
  15. #elif defined(__SUNPRO_C)
  16. # define COMPILER_ID "SunPro"
  17. #elif defined(__HP_cc)
  18. # define COMPILER_ID "HP"
  19. #elif defined(__DECC)
  20. # define COMPILER_ID "Compaq"
  21. #elif defined(__IBMC__)
  22. # if defined(__COMPILER_VER__)
  23. # define COMPILER_ID "zOS"
  24. # elif __IBMC__ >= 800
  25. # define COMPILER_ID "XL"
  26. # else
  27. # define COMPILER_ID "VisualAge"
  28. # endif
  29. #elif defined(__PGI)
  30. # define COMPILER_ID "PGI"
  31. #elif defined(__PATHSCALE__)
  32. # define COMPILER_ID "PathScale"
  33. #elif defined(__GNUC__)
  34. # define COMPILER_ID "GNU"
  35. #elif defined(_MSC_VER)
  36. # define COMPILER_ID "MSVC"
  37. #elif defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__)
  38. /* Analog Devices C++ compiler for Blackfin, TigerSHARC and
  39. SHARC (21000) DSPs */
  40. # define COMPILER_ID "ADSP"
  41. /* IAR Systems compiler for embedded systems.
  42. http://www.iar.com
  43. Not supported yet by CMake
  44. #elif defined(__IAR_SYSTEMS_ICC__)
  45. # define COMPILER_ID "IAR" */
  46. /* sdcc, the small devices C compiler for embedded systems,
  47. http://sdcc.sourceforge.net */
  48. #elif defined(SDCC)
  49. # define COMPILER_ID "SDCC"
  50. #elif defined(_SGI_COMPILER_VERSION) || defined(_COMPILER_VERSION)
  51. # define COMPILER_ID "MIPSpro"
  52. /* This compiler is either not known or is too old to define an
  53. identification macro. Try to identify the platform and guess that
  54. it is the native compiler. */
  55. #elif defined(__sgi)
  56. # define COMPILER_ID "MIPSpro"
  57. #elif defined(__hpux) || defined(__hpua)
  58. # define COMPILER_ID "HP"
  59. #else /* unknown compiler */
  60. # define COMPILER_ID ""
  61. #endif
  62. /* Construct the string literal in pieces to prevent the source from
  63. getting matched. Store it in a pointer rather than an array
  64. because some compilers will just produce instructions to fill the
  65. array rather than assigning a pointer to a static array. */
  66. char* info_compiler = "INFO" ":" "compiler[" COMPILER_ID "]";
  67. /* Identify known platforms by name. */
  68. #if defined(__linux) || defined(__linux__) || defined(linux)
  69. # define PLATFORM_ID "Linux"
  70. #elif defined(__CYGWIN__)
  71. # define PLATFORM_ID "Cygwin"
  72. #elif defined(__MINGW32__)
  73. # define PLATFORM_ID "MinGW"
  74. #elif defined(__APPLE__)
  75. # define PLATFORM_ID "Darwin"
  76. #elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
  77. # define PLATFORM_ID "Windows"
  78. #elif defined(__FreeBSD__) || defined(__FreeBSD)
  79. # define PLATFORM_ID "FreeBSD"
  80. #elif defined(__NetBSD__) || defined(__NetBSD)
  81. # define PLATFORM_ID "NetBSD"
  82. #elif defined(__OpenBSD__) || defined(__OPENBSD)
  83. # define PLATFORM_ID "OpenBSD"
  84. #elif defined(__sun) || defined(sun)
  85. # define PLATFORM_ID "SunOS"
  86. #elif defined(_AIX) || defined(__AIX) || defined(__AIX__) || defined(__aix) || defined(__aix__)
  87. # define PLATFORM_ID "AIX"
  88. #elif defined(__sgi) || defined(__sgi__) || defined(_SGI)
  89. # define PLATFORM_ID "IRIX"
  90. #elif defined(__hpux) || defined(__hpux__)
  91. # define PLATFORM_ID "HP-UX"
  92. #elif defined(__HAIKU) || defined(__HAIKU__) || defined(_HAIKU)
  93. # define PLATFORM_ID "Haiku"
  94. /* Haiku also defines __BEOS__ so we must
  95. put it prior to the check for __BEOS__
  96. */
  97. #elif defined(__BeOS) || defined(__BEOS__) || defined(_BEOS)
  98. # define PLATFORM_ID "BeOS"
  99. #elif defined(__QNX__) || defined(__QNXNTO__)
  100. # define PLATFORM_ID "QNX"
  101. #elif defined(__tru64) || defined(_tru64) || defined(__TRU64__)
  102. # define PLATFORM_ID "Tru64"
  103. #elif defined(__riscos) || defined(__riscos__)
  104. # define PLATFORM_ID "RISCos"
  105. #elif defined(__sinix) || defined(__sinix__) || defined(__SINIX__)
  106. # define PLATFORM_ID "SINIX"
  107. #elif defined(__UNIX_SV__)
  108. # define PLATFORM_ID "UNIX_SV"
  109. #elif defined(__bsdos__)
  110. # define PLATFORM_ID "BSDOS"
  111. #elif defined(_MPRAS) || defined(MPRAS)
  112. # define PLATFORM_ID "MP-RAS"
  113. #elif defined(__osf) || defined(__osf__)
  114. # define PLATFORM_ID "OSF1"
  115. #elif defined(_SCO_SV) || defined(SCO_SV) || defined(sco_sv)
  116. # define PLATFORM_ID "SCO_SV"
  117. #elif defined(__ultrix) || defined(__ultrix__) || defined(_ULTRIX)
  118. # define PLATFORM_ID "ULTRIX"
  119. #elif defined(__XENIX__) || defined(_XENIX) || defined(XENIX)
  120. # define PLATFORM_ID "Xenix"
  121. #else /* unknown platform */
  122. # define PLATFORM_ID ""
  123. #endif
  124. /* For windows compilers MSVC and Intel we can determine
  125. the architecture of the compiler being used. This is becase
  126. the compilers do not have flags that can change the architecture,
  127. but rather depend on which compiler is being used
  128. */
  129. #if defined(_WIN32) && defined(_MSC_VER)
  130. # if defined(_M_IA64)
  131. # define ARCHITECTURE_ID "IA64"
  132. # elif defined(_M_X64) || defined(_M_AMD64)
  133. # define ARCHITECTURE_ID "x64"
  134. # elif defined(_M_IX86)
  135. # define ARCHITECTURE_ID "X86"
  136. # else /* unknown architecture */
  137. # define ARCHITECTURE_ID ""
  138. # endif
  139. #else
  140. # define ARCHITECTURE_ID ""
  141. #endif
  142. /* Construct the string literal in pieces to prevent the source from
  143. getting matched. Store it in a pointer rather than an array
  144. because some compilers will just produce instructions to fill the
  145. array rather than assigning a pointer to a static array. */
  146. char* info_platform = "INFO" ":" "platform[" PLATFORM_ID "]";
  147. char* info_arch = "INFO" ":" "arch[" ARCHITECTURE_ID "]";
  148. /*--------------------------------------------------------------------------*/
  149. #ifdef ID_VOID_MAIN
  150. void main() {}
  151. #else
  152. int main(int argc, char* argv[])
  153. {
  154. int require = 0;
  155. require += info_compiler[argc];
  156. require += info_platform[argc];
  157. require += info_arch[argc];
  158. (void)argv;
  159. return require;
  160. }
  161. #endif