CMakeCCompilerId.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. #ifdef __cplusplus
  2. # error "A C++ compiler has been selected for C."
  3. #endif
  4. /* Version number components: V=Version, R=Revision, P=Patch
  5. Version date components: YYYY=Year, MM=Month, DD=Day */
  6. #if defined(__18CXX)
  7. # define ID_VOID_MAIN
  8. #endif
  9. #if defined(__INTEL_COMPILER) || defined(__ICC)
  10. # define COMPILER_ID "Intel"
  11. /* __INTEL_COMPILER = VRP */
  12. # define COMPILER_VERSION_MAJOR DEC(__INTEL_COMPILER/100)
  13. # define COMPILER_VERSION_MINOR DEC(__INTEL_COMPILER/10 % 10)
  14. # if defined(__INTEL_COMPILER_UPDATE)
  15. # define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER_UPDATE)
  16. # else
  17. # define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER % 10)
  18. # endif
  19. # if defined(__INTEL_COMPILER_BUILD_DATE)
  20. /* __INTEL_COMPILER_BUILD_DATE = YYYYMMDD */
  21. # define COMPILER_VERSION_TWEAK DEC(__INTEL_COMPILER_BUILD_DATE)
  22. # endif
  23. # if defined(_MSC_VER)
  24. # define SIMULATE_ID "MSVC"
  25. /* _MSC_VER = VVRR */
  26. # define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100)
  27. # define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100)
  28. # endif
  29. #elif defined(__PATHCC__)
  30. # define COMPILER_ID "PathScale"
  31. # define COMPILER_VERSION_MAJOR DEC(__PATHCC__)
  32. # define COMPILER_VERSION_MINOR DEC(__PATHCC_MINOR__)
  33. # if defined(__PATHCC_PATCHLEVEL__)
  34. # define COMPILER_VERSION_PATCH DEC(__PATHCC_PATCHLEVEL__)
  35. # endif
  36. #elif defined(__clang__)
  37. # if defined(__apple_build_version__)
  38. # define COMPILER_ID "AppleClang"
  39. # define COMPILER_VERSION_TWEAK DEC(__apple_build_version__)
  40. # else
  41. # define COMPILER_ID "Clang"
  42. # endif
  43. # define COMPILER_VERSION_MAJOR DEC(__clang_major__)
  44. # define COMPILER_VERSION_MINOR DEC(__clang_minor__)
  45. # define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__)
  46. # if defined(_MSC_VER)
  47. # define SIMULATE_ID "MSVC"
  48. /* _MSC_VER = VVRR */
  49. # define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100)
  50. # define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100)
  51. # endif
  52. #elif defined(__BORLANDC__) && defined(__CODEGEARC_VERSION__)
  53. # define COMPILER_ID "Embarcadero"
  54. # define COMPILER_VERSION_MAJOR HEX(__CODEGEARC_VERSION__>>24 & 0x00FF)
  55. # define COMPILER_VERSION_MINOR HEX(__CODEGEARC_VERSION__>>16 & 0x00FF)
  56. # define COMPILER_VERSION_PATCH HEX(__CODEGEARC_VERSION__ & 0xFFFF)
  57. #elif defined(__BORLANDC__)
  58. # define COMPILER_ID "Borland"
  59. /* __BORLANDC__ = 0xVRR */
  60. # define COMPILER_VERSION_MAJOR HEX(__BORLANDC__>>8)
  61. # define COMPILER_VERSION_MINOR HEX(__BORLANDC__ & 0xFF)
  62. #elif defined(__WATCOMC__)
  63. # define COMPILER_ID "Watcom"
  64. /* __WATCOMC__ = VVRR */
  65. # define COMPILER_VERSION_MAJOR DEC(__WATCOMC__ / 100)
  66. # define COMPILER_VERSION_MINOR DEC(__WATCOMC__ % 100)
  67. #elif defined(__SUNPRO_C)
  68. # define COMPILER_ID "SunPro"
  69. # if __SUNPRO_C >= 0x5100
  70. /* __SUNPRO_C = 0xVRRP */
  71. # define COMPILER_VERSION_MAJOR HEX(__SUNPRO_C>>12)
  72. # define COMPILER_VERSION_MINOR HEX(__SUNPRO_C>>4 & 0xFF)
  73. # define COMPILER_VERSION_PATCH HEX(__SUNPRO_C & 0xF)
  74. # else
  75. /* __SUNPRO_C = 0xVRP */
  76. # define COMPILER_VERSION_MAJOR HEX(__SUNPRO_C>>8)
  77. # define COMPILER_VERSION_MINOR HEX(__SUNPRO_C>>4 & 0xF)
  78. # define COMPILER_VERSION_PATCH HEX(__SUNPRO_C & 0xF)
  79. # endif
  80. #elif defined(__HP_cc)
  81. # define COMPILER_ID "HP"
  82. /* __HP_cc = VVRRPP */
  83. # define COMPILER_VERSION_MAJOR DEC(__HP_cc/10000)
  84. # define COMPILER_VERSION_MINOR DEC(__HP_cc/100 % 100)
  85. # define COMPILER_VERSION_PATCH DEC(__HP_cc % 100)
  86. #elif defined(__DECC)
  87. # define COMPILER_ID "Compaq"
  88. /* __DECC_VER = VVRRTPPPP */
  89. # define COMPILER_VERSION_MAJOR DEC(__DECC_VER/10000000)
  90. # define COMPILER_VERSION_MINOR DEC(__DECC_VER/100000 % 100)
  91. # define COMPILER_VERSION_PATCH DEC(__DECC_VER % 10000)
  92. #elif defined(__IBMC__)
  93. # if defined(__COMPILER_VER__)
  94. # define COMPILER_ID "zOS"
  95. # else
  96. # if __IBMC__ >= 800
  97. # define COMPILER_ID "XL"
  98. # else
  99. # define COMPILER_ID "VisualAge"
  100. # endif
  101. /* __IBMC__ = VRP */
  102. # define COMPILER_VERSION_MAJOR DEC(__IBMC__/100)
  103. # define COMPILER_VERSION_MINOR DEC(__IBMC__/10 % 10)
  104. # define COMPILER_VERSION_PATCH DEC(__IBMC__ % 10)
  105. # endif
  106. #elif defined(__PGI)
  107. # define COMPILER_ID "PGI"
  108. # define COMPILER_VERSION_MAJOR DEC(__PGIC__)
  109. # define COMPILER_VERSION_MINOR DEC(__PGIC_MINOR__)
  110. # if defined(__PGIC_PATCHLEVEL__)
  111. # define COMPILER_VERSION_PATCH DEC(__PGIC_PATCHLEVEL__)
  112. # endif
  113. #elif defined(_CRAYC)
  114. # define COMPILER_ID "Cray"
  115. # define COMPILER_VERSION_MAJOR DEC(_RELEASE)
  116. # define COMPILER_VERSION_MINOR DEC(_RELEASE_MINOR)
  117. #elif defined(__TI_COMPILER_VERSION__)
  118. # define COMPILER_ID "TI"
  119. /* __TI_COMPILER_VERSION__ = VVVRRRPPP */
  120. # define COMPILER_VERSION_MAJOR DEC(__TI_COMPILER_VERSION__/1000000)
  121. # define COMPILER_VERSION_MINOR DEC(__TI_COMPILER_VERSION__/1000 % 1000)
  122. # define COMPILER_VERSION_PATCH DEC(__TI_COMPILER_VERSION__ % 1000)
  123. #elif defined(__TINYC__)
  124. # define COMPILER_ID "TinyCC"
  125. #elif defined(__SCO_VERSION__)
  126. # define COMPILER_ID "SCO"
  127. #elif defined(__GNUC__)
  128. # define COMPILER_ID "GNU"
  129. # define COMPILER_VERSION_MAJOR DEC(__GNUC__)
  130. # define COMPILER_VERSION_MINOR DEC(__GNUC_MINOR__)
  131. # if defined(__GNUC_PATCHLEVEL__)
  132. # define COMPILER_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__)
  133. # endif
  134. #elif defined(_MSC_VER)
  135. # define COMPILER_ID "MSVC"
  136. /* _MSC_VER = VVRR */
  137. # define COMPILER_VERSION_MAJOR DEC(_MSC_VER / 100)
  138. # define COMPILER_VERSION_MINOR DEC(_MSC_VER % 100)
  139. # if defined(_MSC_FULL_VER)
  140. # if _MSC_VER >= 1400
  141. /* _MSC_FULL_VER = VVRRPPPPP */
  142. # define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 100000)
  143. # else
  144. /* _MSC_FULL_VER = VVRRPPPP */
  145. # define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 10000)
  146. # endif
  147. # endif
  148. # if defined(_MSC_BUILD)
  149. # define COMPILER_VERSION_TWEAK DEC(_MSC_BUILD)
  150. # endif
  151. /* Analog VisualDSP++ >= 4.5.6 */
  152. #elif defined(__VISUALDSPVERSION__)
  153. # define COMPILER_ID "ADSP"
  154. /* __VISUALDSPVERSION__ = 0xVVRRPP00 */
  155. # define COMPILER_VERSION_MAJOR HEX(__VISUALDSPVERSION__>>24)
  156. # define COMPILER_VERSION_MINOR HEX(__VISUALDSPVERSION__>>16 & 0xFF)
  157. # define COMPILER_VERSION_PATCH HEX(__VISUALDSPVERSION__>>8 & 0xFF)
  158. /* Analog VisualDSP++ < 4.5.6 */
  159. #elif defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__)
  160. # define COMPILER_ID "ADSP"
  161. /* IAR Systems compiler for embedded systems.
  162. http://www.iar.com */
  163. #elif defined(__IAR_SYSTEMS_ICC__ ) || defined(__IAR_SYSTEMS_ICC)
  164. # define COMPILER_ID "IAR"
  165. /* sdcc, the small devices C compiler for embedded systems,
  166. http://sdcc.sourceforge.net */
  167. #elif defined(SDCC)
  168. # define COMPILER_ID "SDCC"
  169. /* SDCC = VRP */
  170. # define COMPILER_VERSION_MAJOR DEC(SDCC/100)
  171. # define COMPILER_VERSION_MINOR DEC(SDCC/10 % 10)
  172. # define COMPILER_VERSION_PATCH DEC(SDCC % 10)
  173. #elif defined(_SGI_COMPILER_VERSION) || defined(_COMPILER_VERSION)
  174. # define COMPILER_ID "MIPSpro"
  175. # if defined(_SGI_COMPILER_VERSION)
  176. /* _SGI_COMPILER_VERSION = VRP */
  177. # define COMPILER_VERSION_MAJOR DEC(_SGI_COMPILER_VERSION/100)
  178. # define COMPILER_VERSION_MINOR DEC(_SGI_COMPILER_VERSION/10 % 10)
  179. # define COMPILER_VERSION_PATCH DEC(_SGI_COMPILER_VERSION % 10)
  180. # else
  181. /* _COMPILER_VERSION = VRP */
  182. # define COMPILER_VERSION_MAJOR DEC(_COMPILER_VERSION/100)
  183. # define COMPILER_VERSION_MINOR DEC(_COMPILER_VERSION/10 % 10)
  184. # define COMPILER_VERSION_PATCH DEC(_COMPILER_VERSION % 10)
  185. # endif
  186. /* This compiler is either not known or is too old to define an
  187. identification macro. Try to identify the platform and guess that
  188. it is the native compiler. */
  189. #elif defined(__sgi)
  190. # define COMPILER_ID "MIPSpro"
  191. #elif defined(__hpux) || defined(__hpua)
  192. # define COMPILER_ID "HP"
  193. #else /* unknown compiler */
  194. # define COMPILER_ID ""
  195. #endif
  196. /* Construct the string literal in pieces to prevent the source from
  197. getting matched. Store it in a pointer rather than an array
  198. because some compilers will just produce instructions to fill the
  199. array rather than assigning a pointer to a static array. */
  200. char const* info_compiler = "INFO" ":" "compiler[" COMPILER_ID "]";
  201. #ifdef SIMULATE_ID
  202. char const* info_simulate = "INFO" ":" "simulate[" SIMULATE_ID "]";
  203. #endif
  204. #ifdef __QNXNTO__
  205. char const* qnxnto = "INFO" ":" "qnxnto";
  206. #endif
  207. /* Identify known platforms by name. */
  208. #if defined(__linux) || defined(__linux__) || defined(linux)
  209. # define PLATFORM_ID "Linux"
  210. #elif defined(__CYGWIN__)
  211. # define PLATFORM_ID "Cygwin"
  212. #elif defined(__MINGW32__)
  213. # define PLATFORM_ID "MinGW"
  214. #elif defined(__APPLE__)
  215. # define PLATFORM_ID "Darwin"
  216. #elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
  217. # define PLATFORM_ID "Windows"
  218. #elif defined(__FreeBSD__) || defined(__FreeBSD)
  219. # define PLATFORM_ID "FreeBSD"
  220. #elif defined(__NetBSD__) || defined(__NetBSD)
  221. # define PLATFORM_ID "NetBSD"
  222. #elif defined(__OpenBSD__) || defined(__OPENBSD)
  223. # define PLATFORM_ID "OpenBSD"
  224. #elif defined(__sun) || defined(sun)
  225. # define PLATFORM_ID "SunOS"
  226. #elif defined(_AIX) || defined(__AIX) || defined(__AIX__) || defined(__aix) || defined(__aix__)
  227. # define PLATFORM_ID "AIX"
  228. #elif defined(__sgi) || defined(__sgi__) || defined(_SGI)
  229. # define PLATFORM_ID "IRIX"
  230. #elif defined(__hpux) || defined(__hpux__)
  231. # define PLATFORM_ID "HP-UX"
  232. #elif defined(__HAIKU__)
  233. # define PLATFORM_ID "Haiku"
  234. #elif defined(__BeOS) || defined(__BEOS__) || defined(_BEOS)
  235. # define PLATFORM_ID "BeOS"
  236. #elif defined(__QNX__) || defined(__QNXNTO__)
  237. # define PLATFORM_ID "QNX"
  238. #elif defined(__tru64) || defined(_tru64) || defined(__TRU64__)
  239. # define PLATFORM_ID "Tru64"
  240. #elif defined(__riscos) || defined(__riscos__)
  241. # define PLATFORM_ID "RISCos"
  242. #elif defined(__sinix) || defined(__sinix__) || defined(__SINIX__)
  243. # define PLATFORM_ID "SINIX"
  244. #elif defined(__UNIX_SV__)
  245. # define PLATFORM_ID "UNIX_SV"
  246. #elif defined(__bsdos__)
  247. # define PLATFORM_ID "BSDOS"
  248. #elif defined(_MPRAS) || defined(MPRAS)
  249. # define PLATFORM_ID "MP-RAS"
  250. #elif defined(__osf) || defined(__osf__)
  251. # define PLATFORM_ID "OSF1"
  252. #elif defined(_SCO_SV) || defined(SCO_SV) || defined(sco_sv)
  253. # define PLATFORM_ID "SCO_SV"
  254. #elif defined(__ultrix) || defined(__ultrix__) || defined(_ULTRIX)
  255. # define PLATFORM_ID "ULTRIX"
  256. #elif defined(__XENIX__) || defined(_XENIX) || defined(XENIX)
  257. # define PLATFORM_ID "Xenix"
  258. #else /* unknown platform */
  259. # define PLATFORM_ID ""
  260. #endif
  261. /* For windows compilers MSVC and Intel we can determine
  262. the architecture of the compiler being used. This is because
  263. the compilers do not have flags that can change the architecture,
  264. but rather depend on which compiler is being used
  265. */
  266. #if defined(_WIN32) && defined(_MSC_VER)
  267. # if defined(_M_IA64)
  268. # define ARCHITECTURE_ID "IA64"
  269. # elif defined(_M_X64) || defined(_M_AMD64)
  270. # define ARCHITECTURE_ID "x64"
  271. # elif defined(_M_IX86)
  272. # define ARCHITECTURE_ID "X86"
  273. # elif defined(_M_ARM)
  274. # define ARCHITECTURE_ID "ARM"
  275. # elif defined(_M_MIPS)
  276. # define ARCHITECTURE_ID "MIPS"
  277. # elif defined(_M_SH)
  278. # define ARCHITECTURE_ID "SHx"
  279. # else /* unknown architecture */
  280. # define ARCHITECTURE_ID ""
  281. # endif
  282. #else
  283. # define ARCHITECTURE_ID ""
  284. #endif
  285. /* Convert integer to decimal digit literals. */
  286. #define DEC(n) \
  287. ('0' + (((n) / 10000000)%10)), \
  288. ('0' + (((n) / 1000000)%10)), \
  289. ('0' + (((n) / 100000)%10)), \
  290. ('0' + (((n) / 10000)%10)), \
  291. ('0' + (((n) / 1000)%10)), \
  292. ('0' + (((n) / 100)%10)), \
  293. ('0' + (((n) / 10)%10)), \
  294. ('0' + ((n) % 10))
  295. /* Convert integer to hex digit literals. */
  296. #define HEX(n) \
  297. ('0' + ((n)>>28 & 0xF)), \
  298. ('0' + ((n)>>24 & 0xF)), \
  299. ('0' + ((n)>>20 & 0xF)), \
  300. ('0' + ((n)>>16 & 0xF)), \
  301. ('0' + ((n)>>12 & 0xF)), \
  302. ('0' + ((n)>>8 & 0xF)), \
  303. ('0' + ((n)>>4 & 0xF)), \
  304. ('0' + ((n) & 0xF))
  305. /* Construct a string literal encoding the version number components. */
  306. #ifdef COMPILER_VERSION_MAJOR
  307. char const info_version[] = {
  308. 'I', 'N', 'F', 'O', ':',
  309. 'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','[',
  310. COMPILER_VERSION_MAJOR,
  311. # ifdef COMPILER_VERSION_MINOR
  312. '.', COMPILER_VERSION_MINOR,
  313. # ifdef COMPILER_VERSION_PATCH
  314. '.', COMPILER_VERSION_PATCH,
  315. # ifdef COMPILER_VERSION_TWEAK
  316. '.', COMPILER_VERSION_TWEAK,
  317. # endif
  318. # endif
  319. # endif
  320. ']','\0'};
  321. #endif
  322. /* Construct a string literal encoding the version number components. */
  323. #ifdef SIMULATE_VERSION_MAJOR
  324. char const info_simulate_version[] = {
  325. 'I', 'N', 'F', 'O', ':',
  326. 's','i','m','u','l','a','t','e','_','v','e','r','s','i','o','n','[',
  327. SIMULATE_VERSION_MAJOR,
  328. # ifdef SIMULATE_VERSION_MINOR
  329. '.', SIMULATE_VERSION_MINOR,
  330. # ifdef SIMULATE_VERSION_PATCH
  331. '.', SIMULATE_VERSION_PATCH,
  332. # ifdef SIMULATE_VERSION_TWEAK
  333. '.', SIMULATE_VERSION_TWEAK,
  334. # endif
  335. # endif
  336. # endif
  337. ']','\0'};
  338. #endif
  339. /* Construct the string literal in pieces to prevent the source from
  340. getting matched. Store it in a pointer rather than an array
  341. because some compilers will just produce instructions to fill the
  342. array rather than assigning a pointer to a static array. */
  343. char const* info_platform = "INFO" ":" "platform[" PLATFORM_ID "]";
  344. char const* info_arch = "INFO" ":" "arch[" ARCHITECTURE_ID "]";
  345. /*--------------------------------------------------------------------------*/
  346. #ifdef ID_VOID_MAIN
  347. void main() {}
  348. #else
  349. int main(int argc, char* argv[])
  350. {
  351. int require = 0;
  352. require += info_compiler[argc];
  353. require += info_platform[argc];
  354. require += info_arch[argc];
  355. #ifdef COMPILER_VERSION_MAJOR
  356. require += info_version[argc];
  357. #endif
  358. #ifdef SIMULATE_ID
  359. require += info_simulate[argc];
  360. #endif
  361. #ifdef SIMULATE_VERSION_MAJOR
  362. require += info_simulate_version[argc];
  363. #endif
  364. (void)argv;
  365. return require;
  366. }
  367. #endif