1 /**************************************************************************
2 * compiler.h -- C++ Compiler Portability Macros
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.
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.
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.
20 **************************************************************************/
23 * A set of defines to encapsulate compiler and platform differences.
24 * Please refer to the source code for full documentation on this file.
26 * Here is a summary of what this file does.
28 * (1) Defines macros for some STL includes which may be affected
29 * by file name length limitations.
31 * (2) Defines macros for some features not supported by all C++ compilers.
33 * (3) Defines 'explicit' as a null macro if the compiler doesn't support
34 * the explicit keyword.
36 * (4) Defines 'typename' as a null macro if the compiler doesn't support
37 * the typename keyword.
39 * (5) Defines bool, true and false if the compiler doesn't do so.
41 * (6) Defines SG_EXPLICIT_FUNCTION_TMPL_ARGS if the compiler
42 * supports calling a function template by providing its template
43 * arguments explicitly.
45 * (7) Defines SG_NEED_AUTO_PTR if STL doesn't provide auto_ptr<>.
47 * (8) Defines SG_NO_ARROW_OPERATOR if the compiler is unable
48 * to support operator->() for iterators.
50 * (9) Defines SG_USE_EXCEPTIONS if the compiler supports exceptions.
51 * Note: no FlightGear code uses exceptions.
53 * (10) Define SG_NAMESPACES if the compiler supports namespaces.
55 * (11) SG_MATH_FN_IN_NAMESPACE_STD -- not used??
57 * (12) Define SG_HAVE_STD if std namespace is supported.
59 * (13) Defines SG_CLASS_PARTIAL_SPECIALIZATION if the compiler
60 * supports partial specialization of class templates.
62 * (14) Defines SG_HAVE_STD_INCLUDES to use ISO C++ Standard headers.
64 * (15) Defines SG_HAVE_STREAMBUF if <streambuf> of <streambuf.h> are present.
66 * (16) Define SG_MATH_EXCEPTION_CLASH if math.h defines an exception class
67 * that clashes with the one defined in <stdexcept>.
70 #ifndef _SG_COMPILER_H
71 #define _SG_COMPILER_H
74 * Helper macro SG_STRINGIZE:
75 * Converts the parameter X to a string after macro replacement
76 * on X has been performed.
78 #define SG_STRINGIZE(X) SG_DO_STRINGIZE(X)
79 #define SG_DO_STRINGIZE(X) #X
83 # if __GNUC_MINOR__ < 8
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>
96 # define SG_NEED_AUTO_PTR
97 # define SG_NO_DEFAULT_TEMPLATE_ARGS
98 # define SG_INCOMPLETE_FUNCTIONAL
99 # define SG_NO_ARROW_OPERATOR
101 # elif __GNUC_MINOR__ >= 8
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
109 # define SG_HAVE_STREAMBUF
110 # define SG_CLASS_PARTIAL_SPECIALIZATION
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>
125 # define SG_EXPLICIT_FUNCTION_TMPL_ARGS
126 # define SG_NEED_AUTO_PTR
127 # define SG_MEMBER_TEMPLATES
128 # define SG_NAMESPACES
130 # define SG_HAVE_STREAMBUF
131 # define SG_CLASS_PARTIAL_SPECIALIZATION
132 # define SG_HAVE_STD_INCLUDES
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>
144 # error Time to upgrade. GNU compilers < 2.7 not supported
147 # define SG_COMPILER_STR "GNU C++ version " SG_STRINGIZE(__GNUC__) "." SG_STRINGIZE(__GNUC_MINOR__)
154 # define SG_NAMESPACES
156 # define SG_HAVE_STREAMBUF
157 # define SG_HAVE_TRAITS
158 # define SG_HAVE_STD_INCLUDES
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>
170 # define SG_COMPILER_STR "Kai C++ version " SG_STRINGIZE(__KCC_VERSION)
177 #if defined(__MWERKS__)
179 CodeWarrior compiler from Metrowerks, Inc.
181 # define SG_HAVE_TRAITS
182 # define SG_HAVE_STD_INCLUDES
184 # define SG_NAMESPACES
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>
196 # define bcopy(from, to, n) memcpy(to, from, n)
198 // -rp- please use FG_MEM_COPY everywhere !
199 // #define FG_MEM_COPY(to,from,n) memcpy(to, from, n)
201 // -dw- currently used glut has no game mode stuff
202 # define GLUT_WRONG_VERSION
204 # define SG_COMPILER_STR "Metrowerks CodeWarrior C++ version " SG_STRINGIZE(__MWERKS__)
209 // Microsoft compilers.
212 # define bcopy(from, to, n) memcpy(to, from, n)
213 # define FG_MEM_COPY(to,from,n) memcpy(to, from, n)
215 # if _MSC_VER >= 1200 // msvc++ 6.0 or greater
216 # define SG_NAMESPACES
218 # define SG_HAVE_STD_INCLUDES
219 # define SG_HAVE_STREAMBUF
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>
231 # define isnan _isnan
232 # define snprintf _snprintf
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) //
239 # error What version of MSVC++ is this?
242 # define SG_COMPILER_STR "Microsoft Visual C++ version " SG_STRINGIZE(_MSC_VER)
247 # if defined(HAVE_SGI_STL_PORT)
249 // Use quotes around long file names to get around Borland's include hackery
251 # define STL_ALGORITHM "algorithm"
252 # define STL_FUNCTIONAL "functional"
254 # define SG_MATH_EXCEPTION_CLASH
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>
264 # define SG_INCOMPLETE_FUNCTIONAL
266 # endif // HAVE_SGI_STL_PORT
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
276 # define SG_COMPILER_STR "Borland C++ version " SG_STRINGIZE(__BORLANDC__)
278 #endif // __BORLANDC__
281 // Native SGI compilers
284 #if defined ( sgi ) && !defined( __GNUC__ )
285 # define SG_HAVE_NATIVE_SGI_COMPILERS
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
293 # define SG_HAVE_STREAMBUF
294 # define SG_HAVE_TRAITS
295 # define SG_HAVE_STD_INCLUDES
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>
307 # define STL_STRING <string>
309 # define STL_STRSTREAM <strstream>
311 #pragma set woff 1001,1012,1014,1116,1155,1172,1174
312 #pragma set woff 1401,1460,1551,1552,1681
315 #pragma set woff 1682,3303
316 #if (_COMPILER_VERSION >= 740)
317 # pragma set woff 3624
321 # define SG_COMPILER_STR "SGI MipsPro compiler version " SG_STRINGIZE(_COMPILER_VERSION)
323 #endif // Native SGI compilers
327 # include <strings.h>
329 # if defined ( __cplusplus )
330 // typedef unsigned int size_t;
332 extern void *memmove(void *, const void *, size_t);
335 extern void *memmove(void *, const void *, size_t);
336 # endif // __cplusplus
338 # if !defined( __GNUC__ )
339 # define SG_COMPILER_STR "Sun compiler version " SG_STRINGIZE(__SUNPRO_CC)
345 // Intel C++ Compiler
347 #if defined(__ICC) || defined (__ECC)
348 # define SG_NAMESPACES
350 # define SG_HAVE_STREAMBUF
351 # define SG_HAVE_TRAITS
352 # define SG_HAVE_STD_INCLUDES
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>
364 # define SG_COMPILER_STR "Intel C++ version " SG_STRINGIZE(__ICC)
369 // Platform dependent gl.h and glut.h definitions
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>
379 inline int (isnan)(double r) { return !(r <= 0 || r >= 0); }
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>
390 // No user modifiable definitions beyond here.
393 #ifdef SG_NEED_EXPLICIT
397 #ifdef SG_NEED_TYPENAME
401 #ifdef SG_NEED_MUTABLE
411 #ifdef SG_EXPLICIT_FUNCTION_TMPL_ARGS
412 # define SG_NULL_TMPL_ARGS <>
414 # define SG_NULL_TMPL_ARGS
417 #ifdef SG_CLASS_PARTIAL_SPECIALIZATION
418 # define SG_TEMPLATE_NULL template<>
420 # define SG_TEMPLATE_NULL
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
430 # define SG_NAMESPACE(X)
431 # define SG_NAMESPACE_END
432 # define SG_USING_NAMESPACE(X)
435 /** \def SG_USING_STD(x)
436 * Expands to using std::x if SG_HAVE_STD is defined
439 # define SG_USING_STD(X) using std::X
442 # define SG_USING_STD(X)
446 // Additional <functional> implementation from SGI STL 3.11
447 // Adapter function objects: pointers to member functions
448 #ifdef SG_INCOMPLETE_FUNCTIONAL
450 template <class _Ret, class _Tp>
451 class const_mem_fun_ref_t
453 : public unary_function<_Tp,_Ret>
454 #endif // __BORLANDC__
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)(); }
460 _Ret (_Tp::*_M_f)() const;
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); }
467 #endif // SG_INCOMPLETE_FUNCTIONAL
469 #endif // _SG_COMPILER_H