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)
175 // Microsoft compilers.
178 # define bcopy(from, to, n) memcpy(to, from, n)
179 # define FG_MEM_COPY(to,from,n) memcpy(to, from, n)
181 # if _MSC_VER >= 1200 // msvc++ 6.0 or greater
182 # define SG_NAMESPACES
184 # define SG_HAVE_STD_INCLUDES
185 # define SG_HAVE_STREAMBUF
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 # define STL_STRING <string>
195 # define STL_STRSTREAM <strstream>
197 # define isnan _isnan
198 # define snprintf _snprintf
199 # define copysign _copysign
201 # pragma warning(disable: 4786) // identifier was truncated to '255' characters
202 # pragma warning(disable: 4244) // conversion from double to float
203 # pragma warning(disable: 4305) //
206 # error What version of MSVC++ is this?
209 # define SG_COMPILER_STR "Microsoft Visual C++ version " SG_STRINGIZE(_MSC_VER)
214 # if defined(HAVE_SGI_STL_PORT)
216 // Use quotes around long file names to get around Borland's include hackery
218 # define STL_ALGORITHM "algorithm"
219 # define STL_FUNCTIONAL "functional"
221 # define SG_MATH_EXCEPTION_CLASH
225 # define STL_ALGORITHM <algorithm>
226 # define STL_FUNCTIONAL <functional>
227 # define STL_IOMANIP <iomanip>
228 # define STL_STDEXCEPT <stdexcept>
229 # define STL_STRSTREAM <strstream>
231 # define SG_INCOMPLETE_FUNCTIONAL
233 # endif // HAVE_SGI_STL_PORT
235 # define STL_IOSTREAM <iostream>
236 # define STL_ITERATOR <iterator>
237 # define STL_FSTREAM <fstream>
238 # define STL_STRING <string>
239 # define SG_NO_DEFAULT_TEMPLATE_ARGS
240 # define SG_NAMESPACES
241 // # define SG_HAVE_STD
243 # define SG_COMPILER_STR "Borland C++ version " SG_STRINGIZE(__BORLANDC__)
245 #endif // __BORLANDC__
248 // Native SGI compilers
251 #if defined ( sgi ) && !defined( __GNUC__ )
252 # define SG_HAVE_NATIVE_SGI_COMPILERS
254 # define SG_EXPLICIT_FUNCTION_TMPL_ARGS
255 # define SG_CLASS_PARTIAL_SPECIALIZATION
256 # define SG_NEED_AUTO_PTR
257 # define SG_MEMBER_TEMPLATES
258 # define SG_NAMESPACES
260 # define SG_HAVE_STREAMBUF
261 # define SG_HAVE_TRAITS
262 # define SG_HAVE_STD_INCLUDES
264 # define STL_ALGORITHM <algorithm>
265 # define STL_FUNCTIONAL <functional>
266 # define STL_IOMANIP <iomanip>
267 # define STL_IOSTREAM <iostream>
268 # define STL_ITERATOR <iterator>
269 # define STL_FSTREAM <fstream>
270 # define STL_STDEXCEPT <stdexcept>
271 #if (_COMPILER_VERSION < 740)
272 # define STL_STRING <irix_string>
274 # define STL_STRING <string>
276 # define STL_STRSTREAM <strstream>
278 #pragma set woff 1001,1012,1014,1116,1155,1172,1174
279 #pragma set woff 1401,1460,1551,1552,1681
282 #pragma set woff 1682,3303
283 #if (_COMPILER_VERSION >= 740)
284 # pragma set woff 3624
288 # define SG_COMPILER_STR "SGI MipsPro compiler version " SG_STRINGIZE(_COMPILER_VERSION)
290 #endif // Native SGI compilers
294 # include <strings.h>
296 # if defined ( __cplusplus )
297 // typedef unsigned int size_t;
299 extern void *memmove(void *, const void *, size_t);
302 extern void *memmove(void *, const void *, size_t);
303 # endif // __cplusplus
305 # if !defined( __GNUC__ )
306 # define SG_COMPILER_STR "Sun compiler version " SG_STRINGIZE(__SUNPRO_CC)
312 // Intel C++ Compiler
314 #if defined(__ICC) || defined (__ECC)
315 # define SG_NAMESPACES
317 # define SG_HAVE_STREAMBUF
318 # define SG_HAVE_TRAITS
319 # define SG_HAVE_STD_INCLUDES
321 # define STL_ALGORITHM <algorithm>
322 # define STL_FUNCTIONAL <functional>
323 # define STL_IOMANIP <iomanip>
324 # define STL_IOSTREAM <iostream>
325 # define STL_ITERATOR <iterator>
326 # define STL_FSTREAM <fstream>
327 # define STL_STDEXCEPT <stdexcept>
328 # define STL_STRING <string>
329 # define STL_STRSTREAM <strstream>
331 # define SG_COMPILER_STR "Intel C++ version " SG_STRINGIZE(__ICC)
336 // Platform dependent gl.h and glut.h definitions
340 # define SG_GL_H <OpenGL/gl.h>
341 # define SG_GLX_H <AGL/agl.h>
342 # define SG_GLU_H <OpenGL/glu.h>
343 # define SG_GLEXT_H <OpenGL/glext.h>
344 # define SG_GLUT_H <GLUT/glut.h>
346 inline int (isnan)(double r) { return !(r <= 0 || r >= 0); }
348 # define SG_GL_H <GL/gl.h>
349 # define SG_GLX_H <GL/glx.h>
350 # define SG_GLU_H <GL/glu.h>
351 # define SG_GLEXT_H <GL/glext.h>
352 # define SG_GLUT_H <GL/glut.h>
357 // No user modifiable definitions beyond here.
360 #ifdef SG_NEED_EXPLICIT
364 #ifdef SG_NEED_TYPENAME
368 #ifdef SG_NEED_MUTABLE
378 #ifdef SG_EXPLICIT_FUNCTION_TMPL_ARGS
379 # define SG_NULL_TMPL_ARGS <>
381 # define SG_NULL_TMPL_ARGS
384 #ifdef SG_CLASS_PARTIAL_SPECIALIZATION
385 # define SG_TEMPLATE_NULL template<>
387 # define SG_TEMPLATE_NULL
390 // SG_NO_NAMESPACES is a hook so that users can disable namespaces
391 // without having to edit library headers.
392 #if defined(SG_NAMESPACES) && !defined(SG_NO_NAMESPACES)
393 # define SG_NAMESPACE(X) namespace X {
394 # define SG_NAMESPACE_END }
395 # define SG_USING_NAMESPACE(X) using namespace X
397 # define SG_NAMESPACE(X)
398 # define SG_NAMESPACE_END
399 # define SG_USING_NAMESPACE(X)
402 /** \def SG_USING_STD(x)
403 * Expands to using std::x if SG_HAVE_STD is defined
406 # define SG_USING_STD(X) using std::X
409 # define SG_USING_STD(X)
413 // Additional <functional> implementation from SGI STL 3.11
414 // Adapter function objects: pointers to member functions
415 #ifdef SG_INCOMPLETE_FUNCTIONAL
417 template <class _Ret, class _Tp>
418 class const_mem_fun_ref_t
420 : public unary_function<_Tp,_Ret>
421 #endif // __BORLANDC__
424 explicit const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const) : _M_f(__pf) {}
425 _Ret operator()(const _Tp& __r) const { return (__r.*_M_f)(); }
427 _Ret (_Tp::*_M_f)() const;
430 template <class _Ret, class _Tp>
431 inline const_mem_fun_ref_t<_Ret,_Tp> mem_fun_ref(_Ret (_Tp::*__f)() const)
432 { return const_mem_fun_ref_t<_Ret,_Tp>(__f); }
434 #endif // SG_INCOMPLETE_FUNCTIONAL
436 #endif // _SG_COMPILER_H