OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgrePlatform.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef __Platform_H_
29 #define __Platform_H_
30 
31 #include "OgreConfig.h"
32 
33 namespace Ogre {
34 /* Initial platform/compiler-related stuff to set.
35 */
36 #define OGRE_PLATFORM_WIN32 1
37 #define OGRE_PLATFORM_LINUX 2
38 #define OGRE_PLATFORM_APPLE 3
39 #define OGRE_PLATFORM_APPLE_IOS 4
40 #define OGRE_PLATFORM_ANDROID 5
41 #define OGRE_PLATFORM_NACL 6
42 #define OGRE_PLATFORM_WINRT 7
43 #define OGRE_PLATFORM_FLASHCC 8
44 
45 #define OGRE_COMPILER_MSVC 1
46 #define OGRE_COMPILER_GNUC 2
47 #define OGRE_COMPILER_BORL 3
48 #define OGRE_COMPILER_WINSCW 4
49 #define OGRE_COMPILER_GCCE 5
50 #define OGRE_COMPILER_CLANG 6
51 
52 #define OGRE_ENDIAN_LITTLE 1
53 #define OGRE_ENDIAN_BIG 2
54 
55 #define OGRE_ARCHITECTURE_32 1
56 #define OGRE_ARCHITECTURE_64 2
57 
58 /* Finds the compiler type and version.
59 */
60 #if (defined( __WIN32__ ) || defined( _WIN32 )) && defined(__ANDROID__) // We are using NVTegra
61 # define OGRE_COMPILER OGRE_COMPILER_GNUC
62 # define OGRE_COMP_VER 470
63 #elif defined( __GCCE__ )
64 # define OGRE_COMPILER OGRE_COMPILER_GCCE
65 # define OGRE_COMP_VER _MSC_VER
66 //# include <staticlibinit_gcce.h> // This is a GCCE toolchain workaround needed when compiling with GCCE
67 #elif defined( __WINSCW__ )
68 # define OGRE_COMPILER OGRE_COMPILER_WINSCW
69 # define OGRE_COMP_VER _MSC_VER
70 #elif defined( _MSC_VER )
71 # define OGRE_COMPILER OGRE_COMPILER_MSVC
72 # define OGRE_COMP_VER _MSC_VER
73 #elif defined( __clang__ )
74 # define OGRE_COMPILER OGRE_COMPILER_CLANG
75 # define OGRE_COMP_VER (((__clang_major__)*100) + \
76  (__clang_minor__*10) + \
77  __clang_patchlevel__)
78 #elif defined( __GNUC__ )
79 # define OGRE_COMPILER OGRE_COMPILER_GNUC
80 # define OGRE_COMP_VER (((__GNUC__)*100) + \
81  (__GNUC_MINOR__*10) + \
82  __GNUC_PATCHLEVEL__)
83 #elif defined( __BORLANDC__ )
84 # define OGRE_COMPILER OGRE_COMPILER_BORL
85 # define OGRE_COMP_VER __BCPLUSPLUS__
86 # define __FUNCTION__ __FUNC__
87 #else
88 # pragma error "No known compiler. Abort! Abort!"
89 
90 #endif
91 
92 /* See if we can use __forceinline or if we need to use __inline instead */
93 #if OGRE_COMPILER == OGRE_COMPILER_MSVC
94 # if OGRE_COMP_VER >= 1200
95 # define FORCEINLINE __forceinline
96 # endif
97 #elif defined(__MINGW32__)
98 # if !defined(FORCEINLINE)
99 # define FORCEINLINE __inline
100 # endif
101 #elif !defined(ANDROID) && (OGRE_COMPILER == OGRE_COMPILER_GNUC || OGRE_COMPILER == OGRE_COMPILER_CLANG)
102 # define FORCEINLINE inline __attribute__((always_inline))
103 #else
104 # define FORCEINLINE __inline
105 #endif
106 
107 /* Finds the current platform */
108 #if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(__ANDROID__)
109 # if defined(WINAPI_FAMILY)
110 # define __OGRE_HAVE_DIRECTXMATH 1
111 # include <winapifamily.h>
112 # if WINAPI_FAMILY == WINAPI_FAMILY_APP|| WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
113 # define DESKTOP_APP 1
114 # define PHONE 2
115 # define OGRE_PLATFORM OGRE_PLATFORM_WINRT
116 # ifndef _CRT_SECURE_NO_WARNINGS
117 # define _CRT_SECURE_NO_WARNINGS
118 # endif
119 # ifndef _SCL_SECURE_NO_WARNINGS
120 # define _SCL_SECURE_NO_WARNINGS
121 # endif
122 # if WINAPI_FAMILY == WINAPI_FAMILY_APP
123 # define OGRE_WINRT_TARGET_TYPE DESKTOP_APP
124 # endif
125 # if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
126 # define OGRE_WINRT_TARGET_TYPE PHONE
127 # endif
128 # else
129 # define OGRE_PLATFORM OGRE_PLATFORM_WIN32
130 # endif
131 # else
132 # define OGRE_PLATFORM OGRE_PLATFORM_WIN32
133 # endif
134 #elif defined(__FLASHCC__)
135 # define OGRE_PLATFORM OGRE_PLATFORM_FLASHCC
136 #elif defined( __APPLE_CC__)
137  // Device Simulator
138  // Both requiring OS version 6.0 or greater
139 # if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 60000 || __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000
140 # define OGRE_PLATFORM OGRE_PLATFORM_APPLE_IOS
141 # else
142 # define OGRE_PLATFORM OGRE_PLATFORM_APPLE
143 # endif
144 #elif defined(__ANDROID__)
145 # define OGRE_PLATFORM OGRE_PLATFORM_ANDROID
146 #elif defined( __native_client__ )
147 # define OGRE_PLATFORM OGRE_PLATFORM_NACL
148 # ifndef OGRE_STATIC_LIB
149 # error OGRE must be built as static for NaCl (OGRE_STATIC=true in CMake)
150 # endif
151 # ifdef OGRE_BUILD_RENDERSYSTEM_D3D9
152 # error D3D9 is not supported on NaCl (OGRE_BUILD_RENDERSYSTEM_D3D9 false in CMake)
153 # endif
154 # ifdef OGRE_BUILD_RENDERSYSTEM_GL
155 # error OpenGL is not supported on NaCl (OGRE_BUILD_RENDERSYSTEM_GL=false in CMake)
156 # endif
157 # ifndef OGRE_BUILD_RENDERSYSTEM_GLES2
158 # error GLES2 render system is required for NaCl (OGRE_BUILD_RENDERSYSTEM_GLES2=false in CMake)
159 # endif
160 #else
161 # define OGRE_PLATFORM OGRE_PLATFORM_LINUX
162 #endif
163 
164  /* Find the arch type */
165 #if defined(__x86_64__) || defined(_M_X64) || defined(__powerpc64__) || defined(__alpha__) || defined(__ia64__) || defined(__s390__) || defined(__s390x__) || defined(__arm64__) || defined(_aarch64_) || defined(__mips64) || defined(__mips64_)
166 # define OGRE_ARCH_TYPE OGRE_ARCHITECTURE_64
167 #else
168 # define OGRE_ARCH_TYPE OGRE_ARCHITECTURE_32
169 #endif
170 
171 // For generating compiler warnings - should work on any compiler
172 // As a side note, if you start your message with 'Warning: ', the MSVC
173 // IDE actually does catch a warning :)
174 #define OGRE_QUOTE_INPLACE(x) # x
175 #define OGRE_QUOTE(x) OGRE_QUOTE_INPLACE(x)
176 #define OGRE_WARN( x ) message( __FILE__ "(" QUOTE( __LINE__ ) ") : " x "\n" )
177 
178 // For marking functions as deprecated
179 #if OGRE_COMPILER == OGRE_COMPILER_MSVC
180 # define OGRE_DEPRECATED __declspec(deprecated)
181 #elif OGRE_COMPILER == OGRE_COMPILER_GNUC || OGRE_COMPILER == OGRE_COMPILER_CLANG
182 # define OGRE_DEPRECATED __attribute__ ((deprecated))
183 #else
184 # pragma message("WARNING: You need to implement OGRE_DEPRECATED for this compiler")
185 # define OGRE_DEPRECATED
186 #endif
187 // Disable OGRE_WCHAR_T_STRINGS until we figure out what to do about it.
188 #define OGRE_WCHAR_T_STRINGS 0
189 
190 //----------------------------------------------------------------------------
191 // Windows Settings
192 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WINRT
193 
194 // If we're not including this from a client build, specify that the stuff
195 // should get exported. Otherwise, import it.
196 # if defined( OGRE_STATIC_LIB )
197  // Linux compilers don't have symbol import/export directives.
198 # define _OgreExport
199 # define _OgrePrivate
200 # else
201 # if defined( OGRE_NONCLIENT_BUILD )
202 # define _OgreExport __declspec( dllexport )
203 # else
204 # if defined( __MINGW32__ )
205 # define _OgreExport
206 # else
207 # define _OgreExport __declspec( dllimport )
208 # endif
209 # endif
210 # define _OgrePrivate
211 # endif
212 // Win32 compilers use _DEBUG for specifying debug builds.
213 // for MinGW, we set DEBUG
214 # if defined(_DEBUG) || defined(DEBUG)
215 # define OGRE_DEBUG_MODE 1
216 # else
217 # define OGRE_DEBUG_MODE 0
218 # endif
219 
220 // Disable unicode support on MingW for GCC 3, poorly supported in stdlibc++
221 // STLPORT fixes this though so allow if found
222 // MinGW C++ Toolkit supports unicode and sets the define __MINGW32_TOOLBOX_UNICODE__ in _mingw.h
223 // GCC 4 is also fine
224 #if defined(__MINGW32__)
225 # if OGRE_COMP_VER < 400
226 # if !defined(_STLPORT_VERSION)
227 # include<_mingw.h>
228 # if defined(__MINGW32_TOOLBOX_UNICODE__) || OGRE_COMP_VER > 345
229 # define OGRE_UNICODE_SUPPORT 1
230 # else
231 # define OGRE_UNICODE_SUPPORT 0
232 # endif
233 # else
234 # define OGRE_UNICODE_SUPPORT 1
235 # endif
236 # else
237 # define OGRE_UNICODE_SUPPORT 1
238 # endif
239 #else
240 # define OGRE_UNICODE_SUPPORT 1
241 #endif
242 
243 #endif // OGRE_PLATFORM == OGRE_PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WINRT
244 
245 //----------------------------------------------------------------------------
246 // Linux/Apple/iOS/Android/NaCl Settings
247 #if OGRE_PLATFORM == OGRE_PLATFORM_LINUX || OGRE_PLATFORM == OGRE_PLATFORM_APPLE || OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS || \
248  OGRE_PLATFORM == OGRE_PLATFORM_ANDROID || OGRE_PLATFORM == OGRE_PLATFORM_NACL || OGRE_PLATFORM == OGRE_PLATFORM_FLASHCC
249 
250 // Enable GCC symbol visibility
251 # if defined( OGRE_GCC_VISIBILITY )
252 # define _OgreExport __attribute__ ((visibility("default")))
253 # define _OgrePrivate __attribute__ ((visibility("hidden")))
254 # else
255 # define _OgreExport
256 # define _OgrePrivate
257 # endif
258 
259 // A quick define to overcome different names for the same function
260 # define stricmp strcasecmp
261 
262 # ifdef DEBUG
263 # define OGRE_DEBUG_MODE 1
264 # else
265 # define OGRE_DEBUG_MODE 0
266 # endif
267 
268 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
269  #define OGRE_PLATFORM_LIB "OgrePlatform.bundle"
270 #elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS
271  #define OGRE_PLATFORM_LIB "OgrePlatform.a"
272 #else //OGRE_PLATFORM_LINUX
273  #define OGRE_PLATFORM_LIB "libOgrePlatform.so"
274 #endif
275 
276 // Always enable unicode support for the moment
277 // Perhaps disable in old versions of gcc if necessary
278 #define OGRE_UNICODE_SUPPORT 1
279 
280 #endif
281 
282 //----------------------------------------------------------------------------
283 // Android Settings
284 #if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
285 # ifdef OGRE_UNICODE_SUPPORT
286 # undef OGRE_UNICODE_SUPPORT
287 # endif
288 # define OGRE_UNICODE_SUPPORT 1
289  // A quick define to overcome different names for the same function
290 # define stricmp strcasecmp
291 # ifdef DEBUG
292 # define OGRE_DEBUG_MODE 1
293 # else
294 # define OGRE_DEBUG_MODE 0
295 # endif
296 # ifndef CLOCKS_PER_SEC
297 # define CLOCKS_PER_SEC 1000
298 # endif
299 #endif
300 
301 //----------------------------------------------------------------------------
302 // FlashCC Settings
303 #if OGRE_PLATFORM == OGRE_PLATFORM_FLASHCC
304 # ifdef OGRE_UNICODE_SUPPORT
305 # undef OGRE_UNICODE_SUPPORT
306 # endif
307 # define OGRE_UNICODE_SUPPORT 0
308 # ifdef DEBUG
309 # define OGRE_DEBUG_MODE 1
310 # else
311 # define OGRE_DEBUG_MODE 0
312 # endif
313 #endif
314 
315 #ifndef __OGRE_HAVE_DIRECTXMATH
316 # define __OGRE_HAVE_DIRECTXMATH 0
317 #endif
318 
319 //----------------------------------------------------------------------------
320 // Endian Settings
321 // check for BIG_ENDIAN config flag, set OGRE_ENDIAN correctly
322 #ifdef OGRE_CONFIG_BIG_ENDIAN
323 # define OGRE_ENDIAN OGRE_ENDIAN_BIG
324 #else
325 # define OGRE_ENDIAN OGRE_ENDIAN_LITTLE
326 #endif
327 
328 //----------------------------------------------------------------------------
329 // Set the default locale for strings
330 #if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
331 // Locales are not supported by the C lib you have to go through JNI.
332 # define OGRE_DEFAULT_LOCALE ""
333 #elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS
334 # define OGRE_DEFAULT_LOCALE "C"
335 #elif defined(__MINGW32__)
336 # define OGRE_DEFAULT_LOCALE "C"
337 #else
338 # if OGRE_COMPILER == OGRE_COMPILER_MSVC
339 # if _MSC_VER >= 1700
340 # define OGRE_DEFAULT_LOCALE "en-GB"
341 # else
342 // http://msdn.microsoft.com/en-us/library/39cwe7zf%28v=vs.90%29.aspx
343 # define OGRE_DEFAULT_LOCALE "uk"
344 # endif
345 # elif OGRE_COMPILER == OGRE_COMPILER_GCCE
346 // http://gcc.gnu.org/onlinedocs/libstdc++/manual/localization.html
347 # define OGRE_DEFAULT_LOCALE "en_GB.UTF8"
348 # else
349 # define OGRE_DEFAULT_LOCALE "en_GB.UTF-8"
350 # endif
351 #endif
352 
353 //----------------------------------------------------------------------------
354 // Library suffixes
355 // "_d" for debug builds, nothing otherwise
356 #if OGRE_DEBUG_MODE
357 # define OGRE_BUILD_SUFFIX "_d"
358 #else
359 # define OGRE_BUILD_SUFFIX ""
360 #endif
361 
362 #ifndef OGRE_FLEXIBILITY_LEVEL
363 # define OGRE_FLEXIBILITY_LEVEL 0
364 #endif
365 
366 #if OGRE_FLEXIBILITY_LEVEL >= 0
367  #define virtual_l0 virtual
368 #else
369  #define virtual_l0
370 #endif
371 #if OGRE_FLEXIBILITY_LEVEL > 1
372  #define virtual_l1 virtual
373 #else
374  #define virtual_l1
375 #endif
376 #if OGRE_FLEXIBILITY_LEVEL > 2
377  #define virtual_l2 virtual
378 #else
379  #define virtual_l2
380 #endif
381 
382 #if OGRE_COMPILER == OGRE_COMPILER_MSVC
383  #define DECL_MALLOC __declspec(restrict) __declspec(noalias)
384 #else
385  #define DECL_MALLOC __attribute__ ((malloc))
386 #endif
387 
388 // Stack-alignment hackery.
389 //
390 // If macro __OGRE_SIMD_ALIGN_STACK defined, means there requests
391 // special code to ensure stack align to a 16-bytes boundary.
392 //
393 // Note:
394 // This macro can only guarantee callee stack pointer (esp) align
395 // to a 16-bytes boundary, but not that for frame pointer (ebp).
396 // Because most compiler might use frame pointer to access to stack
397 // variables, so you need to wrap those alignment required functions
398 // with extra function call.
399 //
400 #if defined(__INTEL_COMPILER)
401 // For intel's compiler, simply calling alloca seems to do the right
402 // thing. The size of the allocated block seems to be irrelevant.
403 #define _OGRE_SIMD_ALIGN_STACK() _alloca(16)
404 #define _OGRE_SIMD_ALIGN_ATTRIBUTE
405 
406 #elif OGRE_CPU == OGRE_CPU_X86 && (OGRE_COMPILER == OGRE_COMPILER_GNUC || OGRE_COMPILER == OGRE_COMPILER_CLANG) && (OGRE_ARCH_TYPE != OGRE_ARCHITECTURE_64)
407 // mark functions with GCC attribute to force stack alignment to 16 bytes
408 #define _OGRE_SIMD_ALIGN_ATTRIBUTE __attribute__((force_align_arg_pointer))
409 
410 #elif defined(_MSC_VER)
411 // Fortunately, MSVC will align the stack automatically
412 #define _OGRE_SIMD_ALIGN_ATTRIBUTE
413 
414 #else
415 #define _OGRE_SIMD_ALIGN_ATTRIBUTE
416 
417 #endif
418 
419 // Integer formats of fixed bit width
420 typedef unsigned int uint32;
421 typedef unsigned short uint16;
422 typedef unsigned char uint8;
423 typedef int int32;
424 typedef short int16;
425 typedef signed char int8;
426 // define uint64 type
427 #if OGRE_COMPILER == OGRE_COMPILER_MSVC
428  typedef unsigned __int64 uint64;
429  typedef __int64 int64;
430 #else
431  typedef unsigned long long uint64;
432  typedef long long int64;
433 #endif
434 
435 #ifndef OGRE_RESTRICT_ALIASING
436  #define OGRE_RESTRICT_ALIASING 0
437 #endif
438 
439 #if OGRE_RESTRICT_ALIASING != 0
440  #if OGRE_COMPILER == OGRE_COMPILER_MSVC
441  #define RESTRICT_ALIAS __restrict //MSVC
442  #define RESTRICT_ALIAS_RETURN __restrict
443  #else
444  #define RESTRICT_ALIAS __restrict__ //GCC... and others?
445  #define RESTRICT_ALIAS_RETURN
446  #endif
447 #else
448  #define RESTRICT_ALIAS
449  #define RESTRICT_ALIAS_RETURN
450 #endif
451 
452 // Disable these warnings (too much noise)
453 #if OGRE_COMPILER == OGRE_COMPILER_MSVC
454 #ifndef _CRT_SECURE_NO_WARNINGS
455 # define _CRT_SECURE_NO_WARNINGS
456 #endif
457 #ifndef _SCL_SECURE_NO_WARNINGS
458 # define _SCL_SECURE_NO_WARNINGS
459 #endif
460 // Turn off warnings generated by long std templates
461 // This warns about truncation to 255 characters in debug/browse info
462 # pragma warning (disable : 4786)
463 // Turn off warnings generated by long std templates
464 // This warns about truncation to 255 characters in debug/browse info
465 # pragma warning (disable : 4503)
466 // disable: "<type> needs to have dll-interface to be used by clients'
467 // Happens on STL member variables which are not public therefore is ok
468 # pragma warning (disable : 4251)
469 // disable: "non dll-interface class used as base for dll-interface class"
470 // Happens when deriving from Singleton because bug in compiler ignores
471 // template export
472 # pragma warning (disable : 4275)
473 // disable: "C++ Exception Specification ignored"
474 // This is because MSVC 6 did not implement all the C++ exception
475 // specifications in the ANSI C++ draft.
476 # pragma warning( disable : 4290 )
477 // disable: "no suitable definition provided for explicit template
478 // instantiation request" Occurs in VC7 for no justifiable reason on all
479 // #includes of Singleton
480 # pragma warning( disable: 4661)
481 // disable: deprecation warnings when using CRT calls in VC8
482 // These show up on all C runtime lib code in VC8, disable since they clutter
483 // the warnings with things we may not be able to do anything about (e.g.
484 // generated code from nvparse etc). I doubt very much that these calls
485 // will ever be actually removed from VC anyway, it would break too much code.
486 # pragma warning( disable: 4996)
487 // disable: "conditional expression constant", always occurs on
488 // OGRE_MUTEX_CONDITIONAL when no threading enabled
489 # pragma warning (disable : 201)
490 // disable: "unreferenced formal parameter"
491 // Many versions of VC have bugs which generate this error in cases where they shouldn't
492 # pragma warning (disable : 4100)
493 // disable: "behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized"
494 // We have this issue in OgreMemorySTLAlloc.h - so we see it over and over
495 # pragma warning (disable : 4345)
496 #endif
497 
498 }
499 
500 #endif
unsigned char uint8
Definition: OgrePlatform.h:422
unsigned int uint32
Definition: OgrePlatform.h:420
long long int64
Definition: OgrePlatform.h:432
short int16
Definition: OgrePlatform.h:424
unsigned long long uint64
Definition: OgrePlatform.h:431
signed char int8
Definition: OgrePlatform.h:425
int int32
Definition: OgrePlatform.h:423
unsigned short uint16
Definition: OgrePlatform.h:421