Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
compiler.h
Go to the documentation of this file.
1 /* Copyright (c) 2010 Wildfire Games
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining
4  * a copy of this software and associated documentation files (the
5  * "Software"), to deal in the Software without restriction, including
6  * without limitation the rights to use, copy, modify, merge, publish,
7  * distribute, sublicense, and/or sell copies of the Software, and to
8  * permit persons to whom the Software is furnished to do so, subject to
9  * the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
23 /*
24  * compiler-specific macros and fixes
25  */
26 
27 #ifndef INCLUDED_COMPILER
28 #define INCLUDED_COMPILER
29 
30 // detect compiler and its version (0 if not present, otherwise
31 // major*100 + minor). note that more than one *_VERSION may be
32 // non-zero due to interoperability (e.g. ICC with MSC).
33 // .. VC
34 #ifdef _MSC_VER
35 # define MSC_VERSION _MSC_VER
36 #else
37 # define MSC_VERSION 0
38 #endif
39 // .. ICC (VC-compatible, GCC-compatible)
40 #if defined(__INTEL_COMPILER)
41 # define ICC_VERSION __INTEL_COMPILER
42 #else
43 # define ICC_VERSION 0
44 #endif
45 // .. LCC (VC-compatible)
46 #if defined(__LCC__)
47 # define LCC_VERSION __LCC__
48 #else
49 # define LCC_VERSION 0
50 #endif
51 // .. GCC
52 #ifdef __GNUC__
53 # define GCC_VERSION (__GNUC__*100 + __GNUC_MINOR__)
54 #else
55 # define GCC_VERSION 0
56 #endif
57 // .. Clang/LLVM (GCC-compatible)
58 // use Clang's feature checking macros to check for availability of features
59 // http://clang.llvm.org/docs/LanguageExtensions.html#feature-checking-macros
60 #ifdef __clang__
61 # define CLANG_VERSION (__clang_major__*100 + __clang_minor__)
62 #else
63 # define CLANG_VERSION 0
64 #endif
65 
66 
67 // are PreCompiled Headers supported?
68 #if MSC_VERSION
69 # define HAVE_PCH 1
70 #elif defined(USING_PCH)
71 # define HAVE_PCH 1
72 #else
73 # define HAVE_PCH 0
74 #endif
75 
76 
77 // check if compiling in pure C mode (not C++) with support for C99.
78 // (this is more convenient than testing __STDC_VERSION__ directly)
79 //
80 // note: C99 provides several useful but disjunct bits of functionality.
81 // unfortunately, most C++ compilers do not offer a complete implementation.
82 // however, many of these features are likely to be added to C++, and/or are
83 // already available as extensions. what we'll do is add a HAVE_ macro for
84 // each feature and test those instead. they are set if HAVE_C99, or also if
85 // the compiler happens to support something compatible.
86 //
87 // rationale: lying about __STDC_VERSION__ via Premake so as to enable support
88 // for some C99 functions doesn't work. Mac OS X headers would then use the
89 // restrict keyword, which is never supported by g++ (because that might
90 // end up breaking valid C++98 programs).
91 #define HAVE_C99 0
92 #ifdef __STDC_VERSION__
93 # if __STDC_VERSION__ >= 199901L
94 # undef HAVE_C99
95 # define HAVE_C99 1
96 # endif
97 #endif
98 
99 
100 // do we have (at least rudimentary) support for C++0x?
101 #ifndef HAVE_CPP0X
102 # if defined(__GXX_EXPERIMENTAL_CPP0X__) || MSC_VERSION >= 1600 || ICC_VERSION >= 1200
103 # define HAVE_CPP0X 1
104 # else
105 # define HAVE_CPP0X 0
106 # endif
107 #endif
108 
109 
110 // Streaming SIMD Extensions (not supported by all GCC)
111 // this only ascertains compiler support; use x86_x64::Cap to
112 // check whether the instructions are supported by the CPU.
113 #ifndef HAVE_SSE
114 # if GCC_VERSION && defined(__SSE__)
115 # define HAVE_SSE 1
116 # elif MSC_VERSION // also includes ICC
117 # define HAVE_SSE 1
118 # else
119 # define HAVE_SSE 0
120 # endif
121 #endif
122 
123 #ifndef HAVE_SSE2
124 # if GCC_VERSION && defined(__SSE2__)
125 # define HAVE_SSE2 1
126 # elif MSC_VERSION // also includes ICC
127 # define HAVE_SSE2 1
128 # else
129 # define HAVE_SSE2 0
130 # endif
131 #endif
132 
133 #endif // #ifndef INCLUDED_COMPILER