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