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