]> git.mxchange.org Git - simgear.git/blob - simgear/compiler.h
More VS2015 fixes
[simgear.git] / simgear / compiler.h
1 /**************************************************************************
2  * compiler.h -- C++ Compiler Portability Macros
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  *
18  * $Id$
19  *
20  **************************************************************************/
21
22 /** \file compiler.h
23  * A set of defines to encapsulate compiler and platform differences.
24  * Please refer to the source code for full documentation on this file.
25  *
26  * This file is useful to set compiler-specific options in every file - for
27  * example, disabling warnings.
28  *
29  */
30
31 #ifndef _SG_COMPILER_H
32 #define _SG_COMPILER_H
33
34 /*
35  * Helper macro SG_STRINGIZE:
36  * Converts the parameter X to a string after macro replacement
37  * on X has been performed.
38  */
39 #define SG_STRINGIZE(X) SG_DO_STRINGIZE(X)
40 #define SG_DO_STRINGIZE(X) #X
41
42 #ifdef __GNUC__
43 #  if __GNUC__ < 3
44 #    error Time to upgrade. GNU compilers < 3.0 not supported
45 #  elif (__GNUC__ == 3) && (__GNUC_MINOR__ < 4)
46 #    warning GCC compilers prior to 3.4 are suspect
47 #  endif
48
49 #  define SG_GCC_VERSION (__GNUC__ * 10000 \
50                      + __GNUC_MINOR__ * 100 \
51                      + __GNUC_PATCHLEVEL__)
52 #  define SG_COMPILER_STR "GNU C++ version " SG_STRINGIZE(__GNUC__) "." SG_STRINGIZE(__GNUC_MINOR__)
53 #endif // __GNUC__
54
55 /* KAI C++ */
56 #if defined(__KCC)
57 #  define SG_COMPILER_STR "Kai C++ version " SG_STRINGIZE(__KCC_VERSION)
58 #endif // __KCC
59
60 //
61 // Microsoft compilers.
62 //
63 #ifdef _MSC_VER
64 #  define bcopy(from, to, n) memcpy(to, from, n)
65
66 #  if _MSC_VER >= 1200 // msvc++ 6.0 up to MSVC2013
67 #    if _MSC_VER < 1900
68 #      define snprintf _snprintf
69 #      define strdup _strdup
70 #    endif
71 #    if _MSC_VER < 1800
72 #      define isnan _isnan
73 #    endif
74 #    if _MSC_VER < 1500
75 #      define vsnprintf _vsnprintf
76 #    endif
77 #    define copysign _copysign
78 #    define strcasecmp stricmp
79
80 #    undef min
81 #    undef max
82
83 #    pragma warning(disable: 4786) // identifier was truncated to '255' characters
84 #    pragma warning(disable: 4244) // conversion from double to float
85 #    pragma warning(disable: 4305) // truncation from larer type to smaller
86
87 #  else
88 #    error What version of MSVC++ is this?
89 #  endif
90
91 #    define SG_COMPILER_STR "Microsoft Visual C++ version " SG_STRINGIZE(_MSC_VER)
92
93 #endif // _MSC_VER
94
95 //
96 // Native SGI compilers
97 //
98
99 #if defined ( sgi ) && !defined( __GNUC__ )
100 # if (_COMPILER_VERSION < 740)
101 #  error Need MipsPro 7.4.0 or higher now
102 # endif
103
104 #define SG_HAVE_NATIVE_SGI_COMPILERS
105
106 #pragma set woff 1001,1012,1014,1116,1155,1172,1174
107 #pragma set woff 1401,1460,1551,1552,1681
108
109 #ifdef __cplusplus
110 # pragma set woff 1682,3303
111 # pragma set woff 3624
112 #endif
113
114 #  define SG_COMPILER_STR "SGI MipsPro compiler version " SG_STRINGIZE(_COMPILER_VERSION)
115
116 #endif // Native SGI compilers
117
118
119 #if defined (__sun)
120 #  define SG_UNIX
121 #  include <strings.h>
122 #  include <memory.h>
123 #  if defined ( __cplusplus )
124      // typedef unsigned int size_t;
125      extern "C" {
126        extern void *memmove(void *, const void *, size_t);
127      }
128 #  else
129      extern void *memmove(void *, const void *, size_t);
130 #  endif // __cplusplus
131
132 #  if  !defined( __GNUC__ )
133 #   define SG_COMPILER_STR "Sun compiler version " SG_STRINGIZE(__SUNPRO_CC)
134 #  endif
135
136 #endif // sun
137
138 //
139 // Intel C++ Compiler
140 //
141 #if defined(__ICC) || defined (__ECC)
142 #  define SG_COMPILER_STR "Intel C++ version " SG_STRINGIZE(__ICC)
143 #endif // __ICC
144
145 //
146 // Platform dependent gl.h and glut.h definitions
147 //
148
149 #ifdef __APPLE__
150 #  define SG_MAC
151 #  define SG_UNIX
152 #  ifdef __GNUC__
153 #    if ( __GNUC__ > 3 ) || ( __GNUC__ == 3 && __GNUC_MINOR__ >= 3 )
154 inline int (isnan)(double r) { return !(r <= 0 || r >= 0); }
155 #    else
156     // any C++ header file undefines isinf and isnan
157     // so this should be included before <iostream>
158     // the functions are STILL in libm (libSystem on mac os x)
159 extern "C" int (isnan)(double);
160 extern "C" int (isinf)(double);
161 #    endif
162 #  else
163 inline int (isnan)(double r) { return !(r <= 0 || r >= 0); }
164 #  endif
165 #endif
166
167 #if defined (__FreeBSD__)
168 #  define SG_UNIX
169 #include <sys/param.h>
170 #  if __FreeBSD_version < 500000
171      extern "C" {
172        inline int isnan(double r) { return !(r <= 0 || r >= 0); }
173      }
174 #  endif
175 #endif
176
177 #if defined (__CYGWIN__)
178 #  define SG_WINDOWS
179 #  define SG_UNIX
180 #  include <ieeefp.h>           // isnan
181 #endif
182
183 // includes both MSVC and mingw compilers
184 #if defined(_WIN32) || defined(__WIN32__)
185 #  define SG_WINDOWS
186 #endif
187
188 #if defined(__linux__) || defined(_AIX) || defined ( sgi )
189 #  define SG_UNIX
190 #endif
191
192 #if defined( __GNUC__ )
193 #  define DEPRECATED __attribute__ ((deprecated))
194 #else
195 #  define DEPRECATED
196 #endif
197
198 #if defined(__clang__)
199 #  define SG_NO_RETURN [[noreturn]]
200 #else
201 #  define SG_NO_RETURN
202 #endif
203
204 //
205 // No user modifiable definitions beyond here.
206 //
207
208 #endif // _SG_COMPILER_H