TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
platform.h
Go to the documentation of this file.
1 
15 #ifndef G3D_platform_h
16 #define G3D_platform_h
17 
23 #define G3D_VER 90000
24 
25 // fatal error for unsupported architectures
26 #if defined(__powerpc__)
27 # error PowerPC is not supported by G3D!
28 #endif
29 
30 #if defined(G3D_RELEASEDEBUG)
31 # define G3D_DEBUGRELEASE
32 #endif
33 
34 #if defined(G3D_DEBUGRELEASE) && defined(_DEBUG)
35 # undef _DEBUG
36 #endif
37 
40 #if !defined(G3D_DEBUG) && (defined(_DEBUG) || defined(G3D_DEBUGRELEASE))
41 # define G3D_DEBUG
42 #endif
43 
50 #define G3D_WINSOCK_MAJOR_VERSION 2
51 #define G3D_WINSOCK_MINOR_VERSION 0
52 
53 #ifndef _MSC_VER
54 #define __fastcall
56 #endif
57 
63 #ifdef _MSC_VER
64 # define G3D_WINDOWS
65 #elif defined(__MINGW32__)
66  #define G3D_WINDOWS
67  #undef __MSVCRT_VERSION__
68  #define __MSVCRT_VERSION__ 0x0601
69  #include <windows.h>
70 #elif defined(__FreeBSD__) || defined(__OpenBSD__)
71  #define G3D_FREEBSD
72  #define G3D_LINUX
73 #elif defined(__linux__)
74  #define G3D_LINUX
75 #elif defined(__APPLE__)
76  #define G3D_LINUX
77 
78  // Prevent OS X fp.h header from being included; it defines
79  // pi as a constant, which creates a conflict with G3D
80 #define __FP__
81 #else
82  #error Unknown platform
83 #endif
84 
91 #if defined(_MSC_VER)
92 # define __thread __declspec(thread)
93 #endif
94 
95 // Detect 64-bit under various compilers
96 #if (defined(_M_X64) || defined(_WIN64) || defined(__LP64__) || defined(_LP64))
97 # define G3D_64BIT
98 #else
99 # define G3D_32BIT
100 #endif
101 
102 // Verify that the supported compilers are being used and that this is a known
103 // processor.
104 
105 #ifdef G3D_LINUX
106 # ifndef __GNUC__
107 # error G3D only supports the gcc compiler on Linux.
108 # endif
109 # define G3D_NO_FFMPEG
110 #endif
111 
112 #ifdef G3D_OSX
113 # ifndef __GNUC__
114 # error G3D only supports the gcc compiler on OS X.
115 # endif
116 
117 # if defined(__i386__)
118 # define G3D_OSX_INTEL
119 # elif defined(__PPC__)
120 # define G3D_OSX_PPC
121 # else
122 # define G3D_OSX_UNKNOWN
123 # endif
124 
125 #endif
126 
127 
128 #ifdef _MSC_VER
129 // Microsoft Visual C++ 10.0 = 1600
130 // Microsoft Visual C++ 9.0 = 1500
131 // Microsoft Visual C++ 8.0 ("Express") = 1400
132 // Microsoft Visual C++ 7.1 ("2003") _MSC_VER = 1310
133 // Microsoft Visual C++ 7.0 ("2002") _MSC_VER = 1300
134 // Microsoft Visual C++ 6.0 _MSC_VER = 1200
135 // Microsoft Visual C++ 5.0 _MSC_VER = 1100
136 
137 // Turn off warnings about deprecated C routines
138 # pragma warning (disable : 4996)
139 
140 // Turn off "conditional expression is constant" warning; MSVC generates this
141 // for debug assertions in inlined methods.
142 # pragma warning (disable : 4127)
143 
154 # define G3D_DEPRECATED __declspec(deprecated)
155 
156 // Prevent Winsock conflicts by hiding the winsock API
157 # ifndef _WINSOCKAPI_
158 # define _G3D_INTERNAL_HIDE_WINSOCK_
159 # define _WINSOCKAPI_
160 # endif
161 
162 // Disable 'name too long for browse information' warning
163 # pragma warning (disable : 4786)
164 
165 # define restrict
166 
169 # define G3D_CHECK_PRINTF_ARGS
170 
173 # define G3D_CHECK_VPRINTF_ARGS
174 
177 # define G3D_CHECK_PRINTF_METHOD_ARGS
178 
181 # define G3D_CHECK_VPRINTF_METHOD_ARGS
182 
183  // On MSVC, we need to link against the multithreaded DLL version of
184  // the C++ runtime because that is what SDL and ZLIB are compiled
185  // against. This is not the default for MSVC, so we set the following
186  // defines to force correct linking.
187  //
188  // For documentation on compiler options, see:
189  // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_.2f.md.2c_2f.ml.2c_2f.mt.2c_2f.ld.asp
190  // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HTML/_core_Compiler_Reference.asp
191  //
192 
193  // DLL runtime
194  #ifndef _DLL
195  #define _DLL
196  #endif
197 
198  // Multithreaded runtime
199  #ifndef _MT
200  #define _MT 1
201  #endif
202 
203  // Ensure that we aren't forced into the static lib
204  #ifdef _STATIC_CPPLIB
205  #undef _STATIC_CPPLIB
206  #endif
207 
208 #ifdef _DEBUG
209  // Some of the support libraries are always built in Release.
210  // Make sure the debug runtime library is linked in
211  #pragma comment(linker, "/NODEFAULTLIB:MSVCRT.LIB")
212  #pragma comment(linker, "/NODEFAULTLIB:MSVCPRT.LIB")
213 #endif
214 
215 
216 # ifndef WIN32_LEAN_AND_MEAN
217 # define WIN32_LEAN_AND_MEAN 1
218 # endif
219 
220 # ifndef NOMINMAX
221 # define NOMINMAX 1
222 # endif
223 # ifndef _WIN32_WINNT
224 # define _WIN32_WINNT 0x0500
225 # endif
226 # include <windows.h>
227 # undef WIN32_LEAN_AND_MEAN
228 # undef NOMINMAX
229 
230 # ifdef _G3D_INTERNAL_HIDE_WINSOCK_
231 # undef _G3D_INTERNAL_HIDE_WINSOCK_
232 # undef _WINSOCKAPI_
233 # endif
234 
235 
239 # define G3D_START_AT_MAIN()\
240 int WINAPI G3D_WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw);\
241 int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw) {\
242  return G3D_WinMain(hInst, hPrev, szCmdLine, sw);\
243 }
244 
245 #else
246 
249 # define G3D_START_AT_MAIN()
250 
251 #endif // win32
252 
253 #ifdef __GNUC__
254 
255 # include <stdint.h>
256 
257 # if __STDC_VERSION__ < 199901
258 # define restrict __restrict__
259 # endif
260 
263 # define G3D_DEPRECATED __attribute__((__deprecated__))
264 
265 // setup function calling conventions
266 # if defined(__i386__) && ! defined(__x86_64__)
267 
268 # ifndef __cdecl
269 # define __cdecl __attribute__((cdecl))
270 # endif
271 
272 # ifndef __stdcall
273 # define __stdcall __attribute__((stdcall))
274 # endif
275 
276 # elif defined(__x86_64__)
277 
278 # ifndef __cdecl
279 # define __cdecl
280 # endif
281 
282 # ifndef __stdcall
283 # define __stdcall
284 # endif
285 # endif // calling conventions
286 
289 # define G3D_CHECK_PRINTF_METHOD_ARGS __attribute__((__format__(__printf__, 2, 3)))
290 
293 # define G3D_CHECK_VPRINTF_METHOD_ARGS __attribute__((__format__(__printf__, 2, 0)))
294 
297 # define G3D_CHECK_PRINTF_ARGS __attribute__((__format__(__printf__, 1, 2)))
298 
301 # define G3D_CHECK_VPRINTF_ARGS __attribute__((__format__(__printf__, 1, 0)))
302 #endif
303 
304 
313 #define STR(x) #x
314 
318 #ifdef _MSC_VER
319 // Microsoft's version http://msdn.microsoft.com/en-us/library/d9x1s805.aspx
320 # define PRAGMA(x) __pragma(x)
321 #else
322 // C99 standard http://www.delorie.com/gnu/docs/gcc/cpp_45.html
323 # define PRAGMA(x) _Pragma(#x)
324 #endif
325 
340 #ifdef __GNUC__
341 # define G3D_BEGIN_PACKED_CLASS(byteAlign) class __attribute((__packed__))
342 #elif defined(_MSC_VER)
343 # define G3D_BEGIN_PACKED_CLASS(byteAlign) PRAGMA( pack(push, byteAlign) ) class
344 #else
345 # define G3D_BEGIN_PACKED_CLASS(byteAlign) class
346 #endif
347 
352 #ifdef __GNUC__
353 # define G3D_END_PACKED_CLASS(byteAlign) __attribute((aligned(byteAlign))) ;
354 #elif defined(_MSC_VER)
355 # define G3D_END_PACKED_CLASS(byteAlign) ; PRAGMA( pack(pop) )
356 #else
357 # define G3D_END_PACKED_CLASS(byteAlign) ;
358 #endif
359 
360 
361 // Bring in shared_ptr and weak_ptr
362 #if (defined(__GNUC__) && defined(__APPLE__)) || defined(__linux__)
363 #include <ciso646> // Defines _LIBCC_VERSION if linking against libc++ or does nothing
364 #endif
365 #if (!defined(_LIBCPP_VERSION) && defined(__APPLE__)) || (!defined(_LIBCPP_VERSION) && defined(__linux__))
366 # include <tr1/memory>
367 #else
368 # include <memory>
369 #endif
370 
371 namespace G3D {
372 #if (!defined(_LIBCPP_VERSION) && defined(__APPLE__)) || (!defined(_LIBCPP_VERSION) && defined(__linux__))
373  using std::tr1::shared_ptr;
374  using std::tr1::weak_ptr;
375  using std::tr1::dynamic_pointer_cast;
376  using std::tr1::static_pointer_cast;
377  using std::tr1::enable_shared_from_this;
378 #else
379  using std::shared_ptr;
380  using std::weak_ptr;
381  using std::dynamic_pointer_cast;
382  using std::static_pointer_cast;
383  using std::enable_shared_from_this;
384 #endif
385 
388  public:
403 
404  G3DSpecification() : threadedNetworking(true) {}
405 
406  virtual ~G3DSpecification() {}
407  };
408 
409 
410  namespace _internal {
412  G3DSpecification& g3dInitializationSpecification();
413  }
414 }
415 
416 // See http://stackoverflow.com/questions/2670816/how-can-i-use-the-compile-time-constant-line-in-a-string
417 // For use primarily with NUMBER_TO_STRING(__LINE__)
418 #define NUMBER_TO_STRING(x) NUMBER_TO_STRING2(x)
419 #define NUMBER_TO_STRING2(x) #x
420 #define __LINE_AS_STRING__ NUMBER_TO_STRING(__LINE__)
421 
422 #endif // Header guard
Definition: platform.h:387
Definition: AABox.h:25
#define true
Definition: CascPort.h:17
bool threadedNetworking
Should G3D spawn its own network thread?
Definition: platform.h:402
G3DSpecification()
Definition: platform.h:404
virtual ~G3DSpecification()
Definition: platform.h:406
G3DSpecification & g3dInitializationSpecification()