Lunchbox  1.10.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 feature 'backported' to C++03
25 # ifndef CXX_NULLPTR_SUPPORTED
26 # define nullptr 0
27 # endif
28 
29 # ifndef CXX_FINAL_OVERRIDE_SUPPORTED
30 # define final
31 # define override
32 # endif
33 #endif
34 
35 #ifdef _MSC_VER
36 # define LB_ALIGN8( var ) __declspec (align (8)) var;
37 # define LB_ALIGN16( var ) __declspec (align (16)) var;
38 #else
39 
43 # define LB_ALIGN8( var ) var __attribute__ ((aligned (8)));
44 
48 # define LB_ALIGN16( var ) var __attribute__ ((aligned (16)));
49 #endif
50 
51 #ifdef __GNUC__
52 # define LB_UNUSED __attribute__((unused))
53 # ifdef WARN_DEPRECATED // Set CMake option ENABLE_WARN_DEPRECATED
54 # define LB_DEPRECATED __attribute__((deprecated))
55 # endif
56 # if (( __GNUC__ > 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 0)) )
57 # define LB_GCC_4_0_OR_LATER
58 # endif
59 # if (( __GNUC__ > 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 1)) )
60 # define LB_GCC_4_1_OR_LATER
61 # endif
62 # if (( __GNUC__ > 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2)) )
63 # define LB_GCC_4_2_OR_LATER
64 # endif
65 # if (( __GNUC__ > 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3)) )
66 # define LB_GCC_4_3_OR_LATER
67 # endif
68 # if (( __GNUC__ > 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) )
69 # define LB_GCC_4_4_OR_LATER
70 # endif
71 # if (( __GNUC__ > 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5)) )
72 # define LB_GCC_4_5_OR_LATER
73 # endif
74 # if (( __GNUC__ > 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)) )
75 # define LB_GCC_4_6_OR_LATER
76 # endif
77 # if (( __GNUC__ > 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) )
78 # define LB_GCC_4_7_OR_LATER
79 # endif
80 # if (( __GNUC__ > 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)) )
81 # define LB_GCC_4_8_OR_LATER
82 # endif
83 # if (( __GNUC__ > 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)) )
84 # define LB_GCC_4_9_OR_LATER
85 # endif
86 
87 # if (( __GNUC__ < 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ < 3)) )
88 # define LB_GCC_4_3_OR_OLDER
89 # endif
90 
91 # if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 2))
92 # define LB_GCC_4_2
93 # endif
94 # if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 3))
95 # define LB_GCC_4_3
96 # endif
97 # if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 4))
98 # define LB_GCC_4_4
99 # endif
100 # if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 5))
101 # define LB_GCC_4_5
102 # endif
103 # if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 6))
104 # define LB_GCC_4_6
105 # endif
106 # if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 7))
107 # define LB_GCC_4_7
108 # endif
109 # if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 8))
110 # define LB_GCC_4_8
111 # endif
112 # if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 9))
113 # define LB_GCC_4_9
114 # endif
115 #endif // GCC
116 
117 #ifndef LB_UNUSED
118 # define LB_UNUSED
119 #endif
120 
121 #ifdef LB_DEPRECATED
122 # define LB_PUSH_DEPRECATED \
123  _Pragma("clang diagnostic push") \
124  _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") \
125  _Pragma("GCC diagnostic push") \
126  _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
127 
128 # define LB_POP_DEPRECATED \
129  _Pragma("clang diagnostic pop") \
130  _Pragma("GCC diagnostic pop")
131 #else
132 # define LB_DEPRECATED
133 # define LB_PUSH_DEPRECATED
134 # define LB_POP_DEPRECATED
135 #endif
136 
137 #ifdef __GNUC__
138 # define LB_LIKELY(x) __builtin_expect( (x), 1 )
139 # define LB_UNLIKELY(x) __builtin_expect( (x), 0 )
140 #else
141 # define LB_LIKELY(x) x
142 # define LB_UNLIKELY(x) x
143 #endif
144 
145 #endif //LUNCHBOX_COMPILER_H