Lunchbox  1.11.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
compiler.h
1 
2 /* Copyright (c) 2010-2014, Stefan Eilemann <eile@eyescale.ch>
3  *
4  * This library is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU Lesser General Public License version 2.1 as published
6  * by the Free Software Foundation.
7  *
8  * This library is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11  * details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this library; if not, write to the Free Software Foundation, Inc.,
15  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16  */
17 
18 #ifndef LUNCHBOX_COMPILER_H
19 #define LUNCHBOX_COMPILER_H
20 
21 #ifdef __cplusplus
22 # include <boost/config.hpp>
23 
24 // C++11 features 'backported' to C++03
25 # if !defined(CXX_NULLPTR_SUPPORTED) && !defined(nullptr)
26 # define nullptr 0
27 # endif
28 # ifndef CXX_FINAL_OVERRIDE_SUPPORTED
29 # ifndef final
30 # define final
31 # endif
32 # ifndef override
33 # define override
34 # endif
35 # endif
36 #endif
37 
38 // align macros
39 #ifdef _MSC_VER
40 # define LB_ALIGN8( var ) __declspec (align (8)) var;
41 # define LB_ALIGN16( var ) __declspec (align (16)) var;
42 # if defined(_M_PPC)
43 # define LB_BIGEENDIAN
44 # else
45 # define LB_LITTLEENDIAN
46 # endif
47 #elif defined (__GNUC__)
48 # define LB_ALIGN8( var ) var __attribute__ ((aligned (8)));
49 # define LB_ALIGN16( var ) var __attribute__ ((aligned (16)));
50 # define LB_UNUSED __attribute__((unused))
51 # define LB_LIKELY(x) __builtin_expect( (x), 1 )
52 # define LB_UNLIKELY(x) __builtin_expect( (x), 0 )
53 # ifdef WARN_DEPRECATED // Set CMake option ENABLE_WARN_DEPRECATED
54 # define LB_DEPRECATED __attribute__((deprecated))
55 # endif
56 # ifdef __BIG_ENDIAN__
57 # define LB_BIGEENDIAN
58 # else
59 # define LB_LITTLEENDIAN
60 # endif
61 # if (( __GNUC__ > 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 0)) )
62 # define LB_GCC_4_0_OR_LATER
63 # endif
64 # if (( __GNUC__ > 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 1)) )
65 # define LB_GCC_4_1_OR_LATER
66 # endif
67 # if (( __GNUC__ > 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2)) )
68 # define LB_GCC_4_2_OR_LATER
69 # endif
70 # if (( __GNUC__ > 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3)) )
71 # define LB_GCC_4_3_OR_LATER
72 # endif
73 # if (( __GNUC__ > 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) )
74 # define LB_GCC_4_4_OR_LATER
75 # endif
76 # if (( __GNUC__ > 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5)) )
77 # define LB_GCC_4_5_OR_LATER
78 # endif
79 # if (( __GNUC__ > 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)) )
80 # define LB_GCC_4_6_OR_LATER
81 # endif
82 # if (( __GNUC__ > 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) )
83 # define LB_GCC_4_7_OR_LATER
84 # endif
85 # if (( __GNUC__ > 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)) )
86 # define LB_GCC_4_8_OR_LATER
87 # endif
88 # if (( __GNUC__ > 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)) )
89 # define LB_GCC_4_9_OR_LATER
90 # endif
91 # if (( __GNUC__ < 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ < 3)) )
92 # define LB_GCC_4_3_OR_OLDER
93 # endif
94 
95 # if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 2))
96 # define LB_GCC_4_2
97 # endif
98 # if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 3))
99 # define LB_GCC_4_3
100 # endif
101 # if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 4))
102 # define LB_GCC_4_4
103 # endif
104 # if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 5))
105 # define LB_GCC_4_5
106 # endif
107 # if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 6))
108 # define LB_GCC_4_6
109 # endif
110 # if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 7))
111 # define LB_GCC_4_7
112 # endif
113 # if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 8))
114 # define LB_GCC_4_8
115 # endif
116 # if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 9))
117 # define LB_GCC_4_9
118 # endif
119 #else
120 # warning Unknown compiler, taking guesses
121 # define LB_ALIGN8( var ) var __attribute__ ((aligned (8)));
122 # define LB_ALIGN16( var ) var __attribute__ ((aligned (16)));
123 # ifdef __BIG_ENDIAN__
124 # define LB_BIGEENDIAN
125 # else
126 # define LB_LITTLEENDIAN
127 # endif
128 #endif // GCC
129 
130 #ifndef LB_UNUSED
131 # define LB_UNUSED
132 #endif
133 #ifndef LB_LIKELY
134 # define LB_LIKELY(x) x
135 # define LB_UNLIKELY(x) x
136 #endif
137 #ifdef LB_DEPRECATED
138 # define LB_PUSH_DEPRECATED \
139  _Pragma("clang diagnostic push") \
140  _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") \
141  _Pragma("GCC diagnostic push") \
142  _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
143 
144 # define LB_POP_DEPRECATED \
145  _Pragma("clang diagnostic pop") \
146  _Pragma("GCC diagnostic pop")
147 #else
148 # define LB_DEPRECATED
149 # define LB_PUSH_DEPRECATED
150 # define LB_POP_DEPRECATED
151 #endif
152 
153 #endif //LUNCHBOX_COMPILER_H