CMakeCXXCompilerId.cpp 13 KB

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