1 /*
2  * This source file is part of libRocket, the HTML/CSS Interface Middleware
3  *
4  * For the latest information, see http://www.librocket.com
5  *
6  * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this software and associated documentation files (the "Software"), to deal
10  * in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12  * copies of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24  * THE SOFTWARE.
25  *
26  */
27 
28 #ifndef ROCKETCOREPLATFORM_H
29 #define ROCKETCOREPLATFORM_H
30 
31 #if defined __WIN32__ || defined _WIN32
32 	#define ROCKET_PLATFORM_WIN32
33 	#define ROCKET_PLATFORM_NAME "win32"
34 	#if !defined(__MINGW32__)
35 		#pragma warning(disable:4355)
36 	#endif
37 #elif defined __APPLE_CC__
38 	#define ROCKET_PLATFORM_UNIX
39 	#define ROCKET_PLATFORM_MACOSX
40 	#define ROCKET_PLATFORM_NAME "macosx"
41 #else
42 	#define ROCKET_PLATFORM_UNIX
43 	#define ROCKET_PLATFORM_LINUX
44 	#define ROCKET_PLATFORM_NAME "linux"
45 #endif
46 
47 #if !defined NDEBUG && !defined ROCKET_DEBUG
48 	#define ROCKET_DEBUG
49 #endif
50 
51 #if defined __LP64__ || defined _M_X64 || defined __MINGW64__ || defined _LP64
52     #define ROCKET_ARCH_64
53 #else
54     #define ROCKET_ARCH_32
55 #endif
56 
57 
58 #if defined(ROCKET_PLATFORM_WIN32) && !defined(__MINGW32__)
59 	// alignment of a member was sensitive to packing
60 	#pragma warning(disable : 4121)
61 
62 	// <type> needs to have dll-interface to be used by clients
63 	#pragma warning(disable : 4251)
64 
65 	// assignment operator could not be generated
66 	#pragma warning(disable : 4512)
67 
68 	// <function> was declared deprecated
69 	#pragma warning(disable : 4996)
70 
71 	#if !defined _CRT_SECURE_NO_DEPRECATE
72 		#define _CRT_SECURE_NO_DEPRECATE
73 	#endif
74 #endif
75 
76 // Wraps unused variables in methods or functions to avoid compiler warnings.  This should
77 // be wrapped around the name of all parameters that are wrapped with ROCKET_UNUSED_PARAMETER
78 // to cover warnings generated by non-llvm/gcc style compilers that can't be covered with
79 // ROCKET_UNUSED_PARAMETER
80 #if defined __llvm__
81 //#  define ROCKET_UNUSED(x) UNUSED_ ## x __unused
82 #  define ROCKET_UNUSED(x)
83 #elif defined __GNUC__
84 //#  define ROCKET_UNUSED(x) UNUSED_ ## x __attribute__((__unused__))
85 #  define ROCKET_UNUSED(x)
86 #else
87 #  define ROCKET_UNUSED(x) (void)(UNUSED_ ## x)
88 #endif
89 
90 // Wraps unused parameter names in method or function declarations.  When used, the first lines
91 // of the function should contain a matching ROCKET_UNUSED call with the name of the function
92 // as well to cover compilers with no-op ROCKET_UNUSED_PARAMETER macros.
93 #if defined __llvm__
94 #  define ROCKET_UNUSED_PARAMETER(x) UNUSED_ ## x __attribute__((unused))
95 #elif defined __GNUC__
96 #  define ROCKET_UNUSED_PARAMETER(x) UNUSED_ ## x __attribute__((__unused__))
97 #else
98 #  define ROCKET_UNUSED_PARAMETER(x) UNUSED_ ## x
99 #endif
100 
101 // ROCKET_UNUSED_ASSERT_PARAMETERS wraps method parameters which are not used in the method other than
102 // by a ROCKET_ASSERT check.  This safely deals with debug versus release mode configurations
103 // and will warn if the parameter starts being used when compiled with GCC
104 #ifdef ROCKET_DEBUG
105    // In this case, the parameter is used by a ROCKET_ASSERT test, so we just pass through as is
106 #  define ROCKET_UNUSED_ASSERT_PARAMETER(x) x
107 #  define ROCKET_UNUSED_ASSERT(x)
108 #else
109    // If not in DEBUG builds, this parameter is unused, mark it as such
110 #  if defined __llvm__
111 #    define ROCKET_UNUSED_ASSERT_PARAMETER(x) UNUSED_ ## x __attribute__((unused))
112 #    define ROCKET_UNUSED_ASSERT(x)
113 #  elif defined __GNUC__
114 #    define ROCKET_UNUSED_ASSERT_PARAMETER(x) UNUSED_ ## x __attribute__((__unused__))
115 #    define ROCKET_UNUSED_ASSERT(x)
116 #  else
117 #    define ROCKET_UNUSED_ASSERT_PARAMETER(x) UNUSED_ ## x
118 #    define ROCKET_UNUSED_ASSERT(x) (void)(UNUSED_ ## x)
119 #  endif
120 #endif
121 
122 // Wraps functions which are not referenced or exported to avoid compiler warnings
123 #if defined __llvm__
124 #  define ROCKET_UNUSED_FUNCTION(x) __attribute__((unused)) UNUSED_ ## x
125 #elif defined __GNUC__
126 #  define ROCKET_UNUSED_FUNCTION(x) __attribute__((__unused__)) UNUSED_ ## x
127 #else
128 #  define ROCKET_UNUSED_FUNCTION(x) UNUSED_ ## x
129 #endif
130 
131 // Squelchs warnings for unused enums in switch statements, this should only be used for special values
132 // that are known to NEVER be used.
133 #define ROCKET_UNUSED_SWITCH_ENUM(x) \
134   case x: \
135     ROCKET_ERRORMSG("Switch case for unhandled ENUM has been hit!  This shouldn't happen!  ENUM Name: " # x); \
136     break;
137 
138 #endif
139