Lunchbox  1.14.0
Multi-threaded C++ toolbox library for all application developers creating high-performance multi-threaded programs.
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 # ifdef LUNCHBOX_USE_CXX03
26 # ifndef nullptr
27 # define nullptr 0
28 # endif
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 #elif defined (__GNUC__)
43 # define LB_ALIGN8( var ) var __attribute__ ((aligned (8)));
44 # define LB_ALIGN16( var ) var __attribute__ ((aligned (16)));
45 # define LB_UNUSED __attribute__((unused))
46 # define LB_LIKELY(x) __builtin_expect( (x), 1 )
47 # define LB_UNLIKELY(x) __builtin_expect( (x), 0 )
48 # ifdef WARN_DEPRECATED // Set CMake option COMMON_WARN_DEPRECATED
49 # define LB_DEPRECATED __attribute__((deprecated))
50 # endif
51 # if (( __GNUC__ > 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 0)) )
52 # define LB_GCC_4_0_OR_LATER
53 # endif
54 # if (( __GNUC__ > 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 1)) )
55 # define LB_GCC_4_1_OR_LATER
56 # endif
57 # if (( __GNUC__ > 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2)) )
58 # define LB_GCC_4_2_OR_LATER
59 # endif
60 # if (( __GNUC__ > 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3)) )
61 # define LB_GCC_4_3_OR_LATER
62 # endif
63 # if (( __GNUC__ > 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) )
64 # define LB_GCC_4_4_OR_LATER
65 # endif
66 # if (( __GNUC__ > 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5)) )
67 # define LB_GCC_4_5_OR_LATER
68 # endif
69 # if (( __GNUC__ > 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)) )
70 # define LB_GCC_4_6_OR_LATER
71 # endif
72 # if (( __GNUC__ > 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) )
73 # define LB_GCC_4_7_OR_LATER
74 # endif
75 # if (( __GNUC__ > 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)) )
76 # define LB_GCC_4_8_OR_LATER
77 # endif
78 # if (( __GNUC__ > 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)) )
79 # define LB_GCC_4_9_OR_LATER
80 # endif
81 # if (( __GNUC__ < 4 ) || ((__GNUC__ == 4) && (__GNUC_MINOR__ < 3)) )
82 # define LB_GCC_4_3_OR_OLDER
83 # endif
84 
85 # if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 2))
86 # define LB_GCC_4_2
87 # endif
88 # if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 3))
89 # define LB_GCC_4_3
90 # endif
91 # if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 4))
92 # define LB_GCC_4_4
93 # endif
94 # if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 5))
95 # define LB_GCC_4_5
96 # endif
97 # if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 6))
98 # define LB_GCC_4_6
99 # endif
100 # if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 7))
101 # define LB_GCC_4_7
102 # endif
103 # if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 8))
104 # define LB_GCC_4_8
105 # endif
106 # if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 9))
107 # define LB_GCC_4_9
108 # endif
109 #else
110 # warning Unknown compiler, taking guesses
111 # define LB_ALIGN8( var ) var __attribute__ ((aligned (8)));
112 # define LB_ALIGN16( var ) var __attribute__ ((aligned (16)));
113 #endif // GCC
114 
115 #ifndef LB_UNUSED
116 # define LB_UNUSED
117 #endif
118 #ifndef LB_LIKELY
119 # define LB_LIKELY(x) x
120 # define LB_UNLIKELY(x) x
121 #endif
122 #ifndef LB_PUSH_DEPRECATED
123 # ifdef LB_DEPRECATED
124 # define LB_PUSH_DEPRECATED \
125  _Pragma("clang diagnostic push") \
126  _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") \
127  _Pragma("GCC diagnostic push") \
128  _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
129 
130 # define LB_POP_DEPRECATED \
131  _Pragma("clang diagnostic pop") \
132  _Pragma("GCC diagnostic pop")
133 # else
134 # define LB_DEPRECATED
135 # define LB_PUSH_DEPRECATED
136 # define LB_POP_DEPRECATED
137 # endif
138 #endif
139 
140 #endif //LUNCHBOX_COMPILER_H