Pyrogenesis  trunk
compiler.h
Go to the documentation of this file.
1 /* Copyright (c) 2015 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 // Clang/LLVM feature check macro compatibility
67 #ifndef __has_feature
68 # define __has_feature(x) 0
69 #endif
70 
71 
72 // are PreCompiled Headers supported?
73 #if MSC_VERSION
74 # define HAVE_PCH 1
75 #elif defined(USING_PCH)
76 # define HAVE_PCH 1
77 #else
78 # define HAVE_PCH 0
79 #endif
80 
81 
82 // check if compiling in pure C mode (not C++) with support for C99.
83 // (this is more convenient than testing __STDC_VERSION__ directly)
84 //
85 // note: C99 provides several useful but disjunct bits of functionality.
86 // unfortunately, most C++ compilers do not offer a complete implementation.
87 // however, many of these features are likely to be added to C++, and/or are
88 // already available as extensions. what we'll do is add a HAVE_ macro for
89 // each feature and test those instead. they are set if HAVE_C99, or also if
90 // the compiler happens to support something compatible.
91 //
92 // rationale: lying about __STDC_VERSION__ via Premake so as to enable support
93 // for some C99 functions doesn't work. Mac OS X headers would then use the
94 // restrict keyword, which is never supported by g++ (because that might
95 // end up breaking valid C++98 programs).
96 #define HAVE_C99 0
97 #ifdef __STDC_VERSION__
98 # if __STDC_VERSION__ >= 199901L
99 # undef HAVE_C99
100 # define HAVE_C99 1
101 # endif
102 #endif
103 
104 // Streaming SIMD Extensions (not supported by all GCC)
105 // this only ascertains compiler support; use x86_x64::Cap to
106 // check whether the instructions are supported by the CPU.
107 #ifndef HAVE_SSE
108 # if GCC_VERSION && defined(__SSE__)
109 # define HAVE_SSE 1
110 # elif MSC_VERSION // also includes ICC
111 # define HAVE_SSE 1
112 # else
113 # define HAVE_SSE 0
114 # endif
115 #endif
116 
117 #ifndef HAVE_SSE2
118 # if GCC_VERSION && defined(__SSE2__)
119 # define HAVE_SSE2 1
120 # elif MSC_VERSION // also includes ICC
121 # define HAVE_SSE2 1
122 # else
123 # define HAVE_SSE2 0
124 # endif
125 #endif
126 
127 #endif // #ifndef INCLUDED_COMPILER