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