]> git.mxchange.org Git - simgear.git/blob - simgear/compiler.h
Attached patches remove BORLANDC, and hence SG_MATH_EXCEPTION_CLASH and SG_INCOM
[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  * Here is a summary of what this file does.
27  *
28  *  (1)  Defines macros for some STL includes which may be affected
29  *       by file name length limitations.
30  *
31  *  (2)  Defines macros for some features not supported by all C++ compilers.
32  *
33  *  (3)  Defines 'explicit' as a null macro if the compiler doesn't support
34  *       the explicit keyword.
35  *
36  *  (4)  Defines 'typename' as a null macro if the compiler doesn't support
37  *       the typename keyword.
38  *
39  *  (5)  Defines bool, true and false if the compiler doesn't do so.
40  *
41  *  (6)  Defines SG_EXPLICIT_FUNCTION_TMPL_ARGS if the compiler
42  *       supports calling a function template by providing its template
43  *       arguments explicitly.
44  *
45  *  (7)  Defines SG_NEED_AUTO_PTR if STL doesn't provide auto_ptr<>.
46  *
47  *  (8)  Defines SG_NO_ARROW_OPERATOR if the compiler is unable
48  *       to support operator->() for iterators.
49  *
50  *  (9)  Defines SG_USE_EXCEPTIONS if the compiler supports exceptions.
51  *       Note: no FlightGear code uses exceptions.
52  *
53  *  (10) Define SG_NAMESPACES if the compiler supports namespaces.
54  *
55  *  (11) SG_MATH_FN_IN_NAMESPACE_STD -- not used??
56  *
57  *  (12) Define SG_HAVE_STD if std namespace is supported.
58  *
59  *  (13) Defines SG_CLASS_PARTIAL_SPECIALIZATION if the compiler 
60  *       supports partial specialization of class templates.
61  *
62  *  (14) Defines SG_HAVE_STD_INCLUDES to use ISO C++ Standard headers.
63  *
64  *  (15) Defines SG_HAVE_STREAMBUF if <streambuf> of <streambuf.h> are present.
65  *
66  */
67
68 #ifndef _SG_COMPILER_H
69 #define _SG_COMPILER_H
70
71 /*
72  * Helper macro SG_STRINGIZE:
73  * Converts the parameter X to a string after macro replacement
74  * on X has been performed.
75  */
76 #define SG_STRINGIZE(X) SG_DO_STRINGIZE(X)
77 #define SG_DO_STRINGIZE(X) #X
78
79 #ifdef __GNUC__
80 #  if __GNUC__ >= 3
81        // g++-3.0.x
82 #      define SG_EXPLICIT_FUNCTION_TMPL_ARGS
83 #      define SG_NEED_AUTO_PTR
84 #      define SG_MEMBER_TEMPLATES
85 #      define SG_NAMESPACES
86 #      define SG_HAVE_STD
87 #      define SG_HAVE_STREAMBUF
88 #      define SG_CLASS_PARTIAL_SPECIALIZATION
89 #      define SG_HAVE_STD_INCLUDES
90
91 #      define STL_ALGORITHM  <algorithm>
92 #      define STL_FUNCTIONAL <functional>
93 #      define STL_IOMANIP    <iomanip>
94 #      define STL_IOSTREAM   <iostream>
95 #      define STL_ITERATOR   <iterator>
96 #      define STL_FSTREAM    <fstream>
97 #      define STL_STDEXCEPT  <stdexcept>
98 #      define STL_STRING     <string>
99 #      define STL_STRSTREAM  <strstream>
100 #  else
101 #    error Time to upgrade. GNU compilers < 3.0 not supported
102 #  endif
103
104 #  define SG_COMPILER_STR "GNU C++ version " SG_STRINGIZE(__GNUC__) "." SG_STRINGIZE(__GNUC_MINOR__)
105
106 #endif // __GNUC__
107
108 /* KAI C++ */
109 #if defined(__KCC)
110
111 #  define SG_NAMESPACES
112 #  define SG_HAVE_STD
113 #  define SG_HAVE_STREAMBUF
114 #  define SG_HAVE_TRAITS
115 #  define SG_HAVE_STD_INCLUDES
116
117 #  define STL_ALGORITHM  <algorithm>
118 #  define STL_FUNCTIONAL <functional>
119 #  define STL_IOMANIP    <iomanip>
120 #  define STL_IOSTREAM   <iostream>
121 #  define STL_ITERATOR   <iterator>
122 #  define STL_FSTREAM    <fstream>
123 #  define STL_STDEXCEPT  <stdexcept>
124 #  define STL_STRING     <string>
125 #  define STL_STRSTREAM  <strstream>
126
127 #  define SG_COMPILER_STR "Kai C++ version " SG_STRINGIZE(__KCC_VERSION)
128
129 #endif // __KCC
130
131 //
132 // Microsoft compilers.
133 //
134 #ifdef _MSC_VER
135 #  define bcopy(from, to, n) memcpy(to, from, n)
136 #  define FG_MEM_COPY(to,from,n) memcpy(to, from, n)
137
138 #  if _MSC_VER >= 1200  // msvc++ 6.0 or greater
139 #    define SG_NAMESPACES
140 #    define SG_HAVE_STD
141 #    define SG_HAVE_STD_INCLUDES
142 #    define SG_HAVE_STREAMBUF
143
144 #    define STL_ALGORITHM  <algorithm>
145 #    define STL_FUNCTIONAL <functional>
146 #    define STL_IOMANIP    <iomanip>
147 #    define STL_IOSTREAM   <iostream>
148 #    define STL_ITERATOR   <iterator>
149 #    define STL_FSTREAM    <fstream>
150 #    define STL_STDEXCEPT  <stdexcept>
151 #    define STL_STRING     <string>
152 #    define STL_STRSTREAM  <strstream>
153
154 #    define isnan _isnan
155 #    define snprintf _snprintf
156 #    define copysign _copysign
157
158 #    pragma warning(disable: 4786) // identifier was truncated to '255' characters
159 #    pragma warning(disable: 4244) // conversion from double to float
160 #    pragma warning(disable: 4305) //
161
162 #  else
163 #    error What version of MSVC++ is this?
164 #  endif
165
166 #    define SG_COMPILER_STR "Microsoft Visual C++ version " SG_STRINGIZE(_MSC_VER)
167
168 #endif // _MSC_VER
169
170 //
171 // Native SGI compilers
172 //
173
174 #if defined ( sgi ) && !defined( __GNUC__ )
175 #  define SG_HAVE_NATIVE_SGI_COMPILERS
176
177 #  define SG_EXPLICIT_FUNCTION_TMPL_ARGS
178 #  define SG_CLASS_PARTIAL_SPECIALIZATION
179 #  define SG_NEED_AUTO_PTR
180 #  define SG_MEMBER_TEMPLATES
181 #  define SG_NAMESPACES
182 #  define SG_HAVE_STD
183 #  define SG_HAVE_STREAMBUF
184 #  define SG_HAVE_TRAITS
185 #  define SG_HAVE_STD_INCLUDES
186
187 #  define STL_ALGORITHM  <algorithm>
188 #  define STL_FUNCTIONAL <functional>
189 #  define STL_IOMANIP    <iomanip>
190 #  define STL_IOSTREAM   <iostream>
191 #  define STL_ITERATOR   <iterator>
192 #  define STL_FSTREAM    <fstream>
193 #  define STL_STDEXCEPT  <stdexcept>
194 #if (_COMPILER_VERSION < 740)
195 #  define STL_STRING     <irix_string>
196 #else
197 #  define STL_STRING     <string>
198 #endif
199 #  define STL_STRSTREAM  <strstream>
200
201 #pragma set woff 1001,1012,1014,1116,1155,1172,1174
202 #pragma set woff 1401,1460,1551,1552,1681
203
204 #ifdef __cplusplus
205 #pragma set woff 1682,3303
206 #if (_COMPILER_VERSION >= 740)
207 #  pragma set woff 3624
208 #endif
209 #endif
210
211 #  define SG_COMPILER_STR "SGI MipsPro compiler version " SG_STRINGIZE(_COMPILER_VERSION)
212
213 #endif // Native SGI compilers
214
215
216 #if defined (__sun)
217 #  include <strings.h>
218 #  include <memory.h>
219 #  if defined ( __cplusplus )
220      // typedef unsigned int size_t;
221      extern "C" {
222        extern void *memmove(void *, const void *, size_t);
223      }
224 #  else
225      extern void *memmove(void *, const void *, size_t);
226 #  endif // __cplusplus
227
228 #  if  !defined( __GNUC__ )
229 #   define SG_COMPILER_STR "Sun compiler version " SG_STRINGIZE(__SUNPRO_CC)
230 #  endif
231
232 #endif // sun
233
234 //
235 // Intel C++ Compiler
236 //
237 #if defined(__ICC) || defined (__ECC)
238 #  define SG_NAMESPACES
239 #  define SG_HAVE_STD
240 #  define SG_HAVE_STREAMBUF
241 #  define SG_HAVE_TRAITS
242 #  define SG_HAVE_STD_INCLUDES
243
244 #  define STL_ALGORITHM  <algorithm>
245 #  define STL_FUNCTIONAL <functional>
246 #  define STL_IOMANIP    <iomanip>
247 #  define STL_IOSTREAM   <iostream>
248 #  define STL_ITERATOR   <iterator>
249 #  define STL_FSTREAM    <fstream>
250 #  define STL_STDEXCEPT  <stdexcept>
251 #  define STL_STRING     <string>
252 #  define STL_STRSTREAM  <strstream>
253
254 #  define SG_COMPILER_STR "Intel C++ version " SG_STRINGIZE(__ICC)
255
256 #endif // __ICC
257
258 //
259 // Platform dependent gl.h and glut.h definitions
260 //
261
262 #ifdef __APPLE__
263 #  define SG_GL_H <OpenGL/gl.h>
264 #  define SG_GLX_H <AGL/agl.h>
265 #  define SG_GLU_H <OpenGL/glu.h>
266 #  define SG_GLEXT_H <OpenGL/glext.h>
267 #  define SG_GLUT_H <GLUT/glut.h>
268
269
270 inline int (isnan)(double r) { return !(r <= 0 || r >= 0); }
271 #else
272 #  define SG_GL_H <GL/gl.h>
273 #  define SG_GLX_H <GL/glx.h>
274 #  define SG_GLU_H <GL/glu.h>
275 #  define SG_GLEXT_H <GL/glext.h>
276 #  define SG_GLUT_H <GL/glut.h>
277 #endif
278
279
280 //
281 // No user modifiable definitions beyond here.
282 //
283
284 #ifdef SG_NEED_EXPLICIT
285 #  define explicit
286 #endif
287
288 #ifdef SG_NEED_TYPENAME
289 #  define typename
290 #endif
291
292 #ifdef SG_NEED_MUTABLE
293 #  define mutable
294 #endif
295
296 #ifdef SG_NEED_BOOL
297    typedef int bool;
298 #  define true 1
299 #  define false 0
300 #endif
301
302 #ifdef SG_EXPLICIT_FUNCTION_TMPL_ARGS
303 #  define SG_NULL_TMPL_ARGS <>
304 #else
305 #  define SG_NULL_TMPL_ARGS
306 #endif
307
308 #ifdef SG_CLASS_PARTIAL_SPECIALIZATION
309 # define SG_TEMPLATE_NULL template<>
310 #else
311 # define SG_TEMPLATE_NULL
312 #endif
313
314 // SG_NO_NAMESPACES is a hook so that users can disable namespaces
315 // without having to edit library headers.
316 #if defined(SG_NAMESPACES) && !defined(SG_NO_NAMESPACES)
317 #   define SG_NAMESPACE(X) namespace X {
318 #   define SG_NAMESPACE_END }
319 #   define SG_USING_NAMESPACE(X) using namespace X
320 # else
321 #   define SG_NAMESPACE(X)
322 #   define SG_NAMESPACE_END
323 #   define SG_USING_NAMESPACE(X)
324 #endif
325
326 /** \def SG_USING_STD(x)
327  *  Expands to using std::x if SG_HAVE_STD is defined 
328  */
329 # ifdef SG_HAVE_STD
330 #  define SG_USING_STD(X) using std::X
331 #  define STD std
332 # else
333 #  define SG_USING_STD(X) 
334 #  define STD
335 # endif
336
337 #endif // _SG_COMPILER_H
338