]> git.mxchange.org Git - simgear.git/blob - simgear/compiler.h
Mark's dynamic sun color changes.
[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  *  (16) Define SG_MATH_EXCEPTION_CLASH if math.h defines an exception class
67  *       that clashes with the one defined in <stdexcept>.
68  */
69
70 #ifndef _SG_COMPILER_H
71 #define _SG_COMPILER_H
72
73 /*
74  * Helper macro SG_STRINGIZE:
75  * Converts the parameter X to a string after macro replacement
76  * on X has been performed.
77  */
78 #define SG_STRINGIZE(X) SG_DO_STRINGIZE(X)
79 #define SG_DO_STRINGIZE(X) #X
80
81 #ifdef __GNUC__
82 #  if __GNUC__ == 2 
83 #    if __GNUC_MINOR__ < 8
84
85        // g++-2.7.x
86 #      define STL_ALGORITHM  <algorithm>
87 #      define STL_FUNCTIONAL <functional>
88 #      define STL_IOMANIP    <iomanip.h>
89 #      define STL_IOSTREAM   <iostream.h>
90 #      define STL_ITERATOR   <iterator.h>
91 #      define STL_FSTREAM    <fstream.h>
92 #      define STL_STDEXCEPT  <stdexcept>
93 #      define STL_STRING     <string>
94 #      define STL_STRSTREAM  <strstream.h>
95
96 #      define SG_NEED_AUTO_PTR
97 #      define SG_NO_DEFAULT_TEMPLATE_ARGS
98 #      define SG_INCOMPLETE_FUNCTIONAL
99 #      define SG_NO_ARROW_OPERATOR
100
101 #    elif __GNUC_MINOR__ >= 8
102
103        // g++-2.8.x and egcs-1.x
104 #      define SG_EXPLICIT_FUNCTION_TMPL_ARGS
105 #      define SG_NEED_AUTO_PTR
106 #      define SG_MEMBER_TEMPLATES
107 #      define SG_NAMESPACES
108 #      define SG_HAVE_STD
109 #      define SG_HAVE_STREAMBUF
110 #      define SG_CLASS_PARTIAL_SPECIALIZATION
111
112 #      define STL_ALGORITHM  <algorithm>
113 #      define STL_FUNCTIONAL <functional>
114 #      define STL_IOMANIP    <iomanip>
115 #      define STL_IOSTREAM   <iostream>
116 #      define STL_ITERATOR   <iterator>
117 #      define STL_FSTREAM    <fstream>
118 #      define STL_STDEXCEPT  <stdexcept>
119 #      define STL_STRING     <string>
120 #      define STL_STRSTREAM  <strstream>
121
122 #    endif
123 #  elif __GNUC__ >= 3
124        // g++-3.0.x
125 #      define SG_EXPLICIT_FUNCTION_TMPL_ARGS
126 #      define SG_NEED_AUTO_PTR
127 #      define SG_MEMBER_TEMPLATES
128 #      define SG_NAMESPACES
129 #      define SG_HAVE_STD
130 #      define SG_HAVE_STREAMBUF
131 #      define SG_CLASS_PARTIAL_SPECIALIZATION
132 #      define SG_HAVE_STD_INCLUDES
133
134 #      define STL_ALGORITHM  <algorithm>
135 #      define STL_FUNCTIONAL <functional>
136 #      define STL_IOMANIP    <iomanip>
137 #      define STL_IOSTREAM   <iostream>
138 #      define STL_ITERATOR   <iterator>
139 #      define STL_FSTREAM    <fstream>
140 #      define STL_STDEXCEPT  <stdexcept>
141 #      define STL_STRING     <string>
142 #      define STL_STRSTREAM  <strstream>
143 #  else
144 #    error Time to upgrade. GNU compilers < 2.7 not supported
145 #  endif
146
147 #  define SG_COMPILER_STR "GNU C++ version " SG_STRINGIZE(__GNUC__) "." SG_STRINGIZE(__GNUC_MINOR__)
148
149 #endif // __GNUC__
150
151 /* KAI C++ */
152 #if defined(__KCC)
153
154 #  define SG_NAMESPACES
155 #  define SG_HAVE_STD
156 #  define SG_HAVE_STREAMBUF
157 #  define SG_HAVE_TRAITS
158 #  define SG_HAVE_STD_INCLUDES
159
160 #  define STL_ALGORITHM  <algorithm>
161 #  define STL_FUNCTIONAL <functional>
162 #  define STL_IOMANIP    <iomanip>
163 #  define STL_IOSTREAM   <iostream>
164 #  define STL_ITERATOR   <iterator>
165 #  define STL_FSTREAM    <fstream>
166 #  define STL_STDEXCEPT  <stdexcept>
167 #  define STL_STRING     <string>
168 #  define STL_STRSTREAM  <strstream>
169
170 #  define SG_COMPILER_STR "Kai C++ version " SG_STRINGIZE(__KCC_VERSION)
171
172 #endif // __KCC
173
174 //
175 // Metrowerks 
176 //
177 #if defined(__MWERKS__)
178 /*
179   CodeWarrior compiler from Metrowerks, Inc.
180 */
181 #  define SG_HAVE_TRAITS
182 #  define SG_HAVE_STD_INCLUDES
183 #  define SG_HAVE_STD
184 #  define SG_NAMESPACES
185
186 #  define STL_ALGORITHM  <algorithm>
187 #  define STL_FUNCTIONAL <functional>
188 #  define STL_IOMANIP    <iomanip>
189 #  define STL_IOSTREAM   <iostream>
190 #  define STL_ITERATOR   <iterator>
191 #  define STL_FSTREAM    <fstream>
192 #  define STL_STDEXCEPT  <stdexcept>
193 #  define STL_STRING     <string>
194
195 // Temp:
196 #  define bcopy(from, to, n) memcpy(to, from, n)
197
198 // -rp- please use FG_MEM_COPY everywhere !
199 // #define FG_MEM_COPY(to,from,n) memcpy(to, from, n)
200
201 // -dw- currently used glut has no game mode stuff
202 #  define GLUT_WRONG_VERSION
203
204 #  define SG_COMPILER_STR "Metrowerks CodeWarrior C++ version " SG_STRINGIZE(__MWERKS__)
205
206 #endif // __MWERKS__
207
208 //
209 // Microsoft compilers.
210 //
211 #ifdef _MSC_VER
212 #  define bcopy(from, to, n) memcpy(to, from, n)
213 #  define FG_MEM_COPY(to,from,n) memcpy(to, from, n)
214
215 #  if _MSC_VER >= 1200  // msvc++ 6.0 or greater
216 #    define SG_NAMESPACES
217 #    define SG_HAVE_STD
218 #    define SG_HAVE_STD_INCLUDES
219 #    define SG_HAVE_STREAMBUF
220
221 #    define STL_ALGORITHM  <algorithm>
222 #    define STL_FUNCTIONAL <functional>
223 #    define STL_IOMANIP    <iomanip>
224 #    define STL_IOSTREAM   <iostream>
225 #    define STL_ITERATOR   <iterator>
226 #    define STL_FSTREAM    <fstream>
227 #    define STL_STDEXCEPT  <stdexcept>
228 #    define STL_STRING     <string>
229 #    define STL_STRSTREAM  <strstream>
230
231 #    define isnan _isnan
232 #    define snprintf _snprintf
233
234 #    pragma warning(disable: 4786) // identifier was truncated to '255' characters
235 #    pragma warning(disable: 4244) // conversion from double to float
236 #    pragma warning(disable: 4305) //
237
238 #  else
239 #    error What version of MSVC++ is this?
240 #  endif
241
242 #    define SG_COMPILER_STR "Microsoft Visual C++ version " SG_STRINGIZE(_MSC_VER)
243
244 #endif // _MSC_VER
245
246 #ifdef __BORLANDC__
247 # if defined(HAVE_SGI_STL_PORT)
248
249 // Use quotes around long file names to get around Borland's include hackery
250
251 #  define STL_ALGORITHM  "algorithm"
252 #  define STL_FUNCTIONAL "functional"
253
254 #  define SG_MATH_EXCEPTION_CLASH
255
256 # else
257
258 #  define STL_ALGORITHM  <algorithm>
259 #  define STL_FUNCTIONAL <functional>
260 #  define STL_IOMANIP    <iomanip>
261 #  define STL_STDEXCEPT  <stdexcept>
262 #  define STL_STRSTREAM  <strstream>
263
264 #  define SG_INCOMPLETE_FUNCTIONAL
265
266 # endif // HAVE_SGI_STL_PORT
267
268 #  define STL_IOSTREAM   <iostream>
269 #  define STL_ITERATOR   <iterator>
270 #  define STL_FSTREAM    <fstream>
271 #  define STL_STRING     <string>
272 #  define SG_NO_DEFAULT_TEMPLATE_ARGS
273 #  define SG_NAMESPACES
274 // #  define SG_HAVE_STD
275
276 #  define SG_COMPILER_STR "Borland C++ version " SG_STRINGIZE(__BORLANDC__)
277
278 #endif // __BORLANDC__
279
280 //
281 // Native SGI compilers
282 //
283
284 #if defined ( sgi ) && !defined( __GNUC__ )
285 #  define SG_HAVE_NATIVE_SGI_COMPILERS
286
287 #  define SG_EXPLICIT_FUNCTION_TMPL_ARGS
288 #  define SG_CLASS_PARTIAL_SPECIALIZATION
289 #  define SG_NEED_AUTO_PTR
290 #  define SG_MEMBER_TEMPLATES
291 #  define SG_NAMESPACES
292 #  define SG_HAVE_STD
293 #  define SG_HAVE_STREAMBUF
294 #  define SG_HAVE_TRAITS
295 #  define SG_HAVE_STD_INCLUDES
296
297 #  define STL_ALGORITHM  <algorithm>
298 #  define STL_FUNCTIONAL <functional>
299 #  define STL_IOMANIP    <iomanip>
300 #  define STL_IOSTREAM   <iostream>
301 #  define STL_ITERATOR   <iterator>
302 #  define STL_FSTREAM    <fstream>
303 #  define STL_STDEXCEPT  <stdexcept>
304 #if (_COMPILER_VERSION < 740)
305 #  define STL_STRING     <irix_string>
306 #else
307 #  define STL_STRING     <string>
308 #endif
309 #  define STL_STRSTREAM  <strstream>
310
311 #pragma set woff 1001,1012,1014,1116,1155,1172,1174
312 #pragma set woff 1401,1460,1551,1552,1681
313
314 #ifdef __cplusplus
315 #pragma set woff 1682,3303
316 #if (_COMPILER_VERSION >= 740)
317 #  pragma set woff 3624
318 #endif
319 #endif
320
321 #  define SG_COMPILER_STR "SGI MipsPro compiler version " SG_STRINGIZE(_COMPILER_VERSION)
322
323 #endif // Native SGI compilers
324
325
326 #if defined (__sun)
327 #  include <strings.h>
328 #  include <memory.h>
329 #  if defined ( __cplusplus )
330      // typedef unsigned int size_t;
331      extern "C" {
332        extern void *memmove(void *, const void *, size_t);
333      }
334 #  else
335      extern void *memmove(void *, const void *, size_t);
336 #  endif // __cplusplus
337
338 #  if  !defined( __GNUC__ )
339 #   define SG_COMPILER_STR "Sun compiler version " SG_STRINGIZE(__SUNPRO_CC)
340 #  endif
341
342 #endif // sun
343
344 //
345 // Intel C++ Compiler
346 //
347 #if defined(__ICC) || defined (__ECC)
348 #  define SG_NAMESPACES
349 #  define SG_HAVE_STD
350 #  define SG_HAVE_STREAMBUF
351 #  define SG_HAVE_TRAITS
352 #  define SG_HAVE_STD_INCLUDES
353
354 #  define STL_ALGORITHM  <algorithm>
355 #  define STL_FUNCTIONAL <functional>
356 #  define STL_IOMANIP    <iomanip>
357 #  define STL_IOSTREAM   <iostream>
358 #  define STL_ITERATOR   <iterator>
359 #  define STL_FSTREAM    <fstream>
360 #  define STL_STDEXCEPT  <stdexcept>
361 #  define STL_STRING     <string>
362 #  define STL_STRSTREAM  <strstream>
363
364 #  define SG_COMPILER_STR "Intel C++ version " SG_STRINGIZE(__ICC)
365
366 #endif // __ICC
367
368 //
369 // Platform dependent gl.h and glut.h definitions
370 //
371
372 #ifdef __APPLE__
373 #  define SG_GL_H <OpenGL/gl.h>
374 #  define SG_GLX_H <AGL/agl.h>
375 #  define SG_GLU_H <OpenGL/glu.h>
376 #  define SG_GLEXT_H <OpenGL/glext.h>
377 #  define SG_GLUT_H <GLUT/glut.h>
378
379 inline int (isnan)(double r) { return !(r <= 0 || r >= 0); }
380 #else
381 #  define SG_GL_H <GL/gl.h>
382 #  define SG_GLX_H <GL/glx.h>
383 #  define SG_GLU_H <GL/glu.h>
384 #  define SG_GLEXT_H <GL/glext.h>
385 #  define SG_GLUT_H <GL/glut.h>
386 #endif
387
388
389 //
390 // No user modifiable definitions beyond here.
391 //
392
393 #ifdef SG_NEED_EXPLICIT
394 #  define explicit
395 #endif
396
397 #ifdef SG_NEED_TYPENAME
398 #  define typename
399 #endif
400
401 #ifdef SG_NEED_MUTABLE
402 #  define mutable
403 #endif
404
405 #ifdef SG_NEED_BOOL
406    typedef int bool;
407 #  define true 1
408 #  define false 0
409 #endif
410
411 #ifdef SG_EXPLICIT_FUNCTION_TMPL_ARGS
412 #  define SG_NULL_TMPL_ARGS <>
413 #else
414 #  define SG_NULL_TMPL_ARGS
415 #endif
416
417 #ifdef SG_CLASS_PARTIAL_SPECIALIZATION
418 # define SG_TEMPLATE_NULL template<>
419 #else
420 # define SG_TEMPLATE_NULL
421 #endif
422
423 // SG_NO_NAMESPACES is a hook so that users can disable namespaces
424 // without having to edit library headers.
425 #if defined(SG_NAMESPACES) && !defined(SG_NO_NAMESPACES)
426 #   define SG_NAMESPACE(X) namespace X {
427 #   define SG_NAMESPACE_END }
428 #   define SG_USING_NAMESPACE(X) using namespace X
429 # else
430 #   define SG_NAMESPACE(X)
431 #   define SG_NAMESPACE_END
432 #   define SG_USING_NAMESPACE(X)
433 #endif
434
435 /** \def SG_USING_STD(x)
436  *  Expands to using std::x if SG_HAVE_STD is defined 
437  */
438 # ifdef SG_HAVE_STD
439 #  define SG_USING_STD(X) using std::X
440 #  define STD std
441 # else
442 #  define SG_USING_STD(X) 
443 #  define STD
444 # endif
445
446 // Additional <functional> implementation from SGI STL 3.11
447 // Adapter function objects: pointers to member functions
448 #ifdef SG_INCOMPLETE_FUNCTIONAL
449
450 template <class _Ret, class _Tp>
451 class const_mem_fun_ref_t
452 #ifndef __BORLANDC__
453     : public unary_function<_Tp,_Ret>
454 #endif // __BORLANDC__
455 {
456 public:
457   explicit const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const) : _M_f(__pf) {}
458   _Ret operator()(const _Tp& __r) const { return (__r.*_M_f)(); }
459 private:
460   _Ret (_Tp::*_M_f)() const;
461 };
462
463 template <class _Ret, class _Tp>
464 inline const_mem_fun_ref_t<_Ret,_Tp> mem_fun_ref(_Ret (_Tp::*__f)() const)
465   { return const_mem_fun_ref_t<_Ret,_Tp>(__f); }
466
467 #endif // SG_INCOMPLETE_FUNCTIONAL
468
469 #endif // _SG_COMPILER_H
470