]> git.mxchange.org Git - simgear.git/blob - simgear/compiler.h
e29a20e37b38724a556283e6188b44a316b97c3b
[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_COMPILER_STR "GNU C++ version " SG_STRINGIZE(__GNUC__) "." SG_STRINGIZE(__GNUC_MINOR__)
50 #endif // __GNUC__
51
52 /* KAI C++ */
53 #if defined(__KCC)
54 #  define SG_COMPILER_STR "Kai C++ version " SG_STRINGIZE(__KCC_VERSION)
55 #endif // __KCC
56
57 //
58 // Microsoft compilers.
59 //
60 #ifdef _MSC_VER
61 #  define bcopy(from, to, n) memcpy(to, from, n)
62
63 #  if _MSC_VER >= 1200  // msvc++ 6.0 or greater
64 #    define isnan _isnan
65 #    define snprintf _snprintf
66 #    if _MSC_VER < 1500
67 #      define vsnprintf _vsnprintf
68 #    endif
69 #    define copysign _copysign
70 #    define strcasecmp stricmp
71
72 #    pragma warning(disable: 4786) // identifier was truncated to '255' characters
73 #    pragma warning(disable: 4244) // conversion from double to float
74 #    pragma warning(disable: 4305) //
75
76 #  else
77 #    error What version of MSVC++ is this?
78 #  endif
79
80 #    define SG_COMPILER_STR "Microsoft Visual C++ version " SG_STRINGIZE(_MSC_VER)
81
82 #endif // _MSC_VER
83
84 //
85 // Native SGI compilers
86 //
87
88 #if defined ( sgi ) && !defined( __GNUC__ )
89 # if (_COMPILER_VERSION < 740)
90 #  error Need MipsPro 7.4.0 or higher now
91 # endif
92
93 #define SG_HAVE_NATIVE_SGI_COMPILERS
94
95 #pragma set woff 1001,1012,1014,1116,1155,1172,1174
96 #pragma set woff 1401,1460,1551,1552,1681
97
98 #ifdef __cplusplus
99 # pragma set woff 1682,3303
100 # pragma set woff 3624
101 #endif
102
103 #  define SG_COMPILER_STR "SGI MipsPro compiler version " SG_STRINGIZE(_COMPILER_VERSION)
104
105 #endif // Native SGI compilers
106
107
108 #if defined (__sun)
109 #  include <strings.h>
110 #  include <memory.h>
111 #  if defined ( __cplusplus )
112      // typedef unsigned int size_t;
113      extern "C" {
114        extern void *memmove(void *, const void *, size_t);
115      }
116 #  else
117      extern void *memmove(void *, const void *, size_t);
118 #  endif // __cplusplus
119
120 #  if  !defined( __GNUC__ )
121 #   define SG_COMPILER_STR "Sun compiler version " SG_STRINGIZE(__SUNPRO_CC)
122 #  endif
123
124 #endif // sun
125
126 //
127 // Intel C++ Compiler
128 //
129 #if defined(__ICC) || defined (__ECC)
130 #  define SG_COMPILER_STR "Intel C++ version " SG_STRINGIZE(__ICC)
131 #endif // __ICC
132
133 //
134 // Platform dependent gl.h and glut.h definitions
135 //
136
137 #ifdef __APPLE__
138 #  ifdef __GNUC__
139 #    if ( __GNUC__ > 3 ) || ( __GNUC__ == 3 && __GNUC_MINOR__ >= 3 )
140 inline int (isnan)(double r) { return !(r <= 0 || r >= 0); }
141 #    else
142     // any C++ header file undefines isinf and isnan
143     // so this should be included before <iostream>
144     // the functions are STILL in libm (libSystem on mac os x)
145 extern "C" int (isnan)(double);
146 extern "C" int (isinf)(double);
147 #    endif
148 #  else
149 inline int (isnan)(double r) { return !(r <= 0 || r >= 0); }
150 #  endif
151 #endif
152
153 #if defined (__FreeBSD__)
154 #  if __FreeBSD_version < 500000
155      extern "C" {
156        inline int isnan(double r) { return !(r <= 0 || r >= 0); }
157      }
158 #  endif
159 #endif
160
161 #if defined (__CYGWIN__)
162 #  include <ieeefp.h>           // isnan
163 #endif
164
165
166 //
167 // No user modifiable definitions beyond here.
168 //
169
170 #endif // _SG_COMPILER_H
171