libcopp  1.1.0
features.h
Go to the documentation of this file.
1 // cmake template file
2 
3 #ifndef COPP_UTILS_FEATURES_H
4 #define COPP_UTILS_FEATURES_H
5 
6 
7 #pragma once
8 
10 
11 // ================ build options ================
13 // ---------------- build options ----------------
14 
15 // ================ select compiler ================
16 #if defined(__GCCXML__)
17 #define COPP_MACRO_COMPILER_GCCXML 1
18 #elif defined(__clang__)
19 #define COPP_MACRO_COMPILER_CLANG 1
20 #elif defined(_MSC_VER)
21 #define COPP_MACRO_COMPILER_MSVC 1
22 #elif defined(__INTEL_COMPILER) || defined(__ICL) || defined(__ICC) || defined(__ECC)
23 #define COPP_MACRO_COMPILER_INTELC 1
24 #elif defined(__GNUC__)
25 #define COPP_MACRO_COMPILER_GCC 1
26 #elif defined(__BORLANDC__)
27 #define COPP_MACRO_COMPILER_BORLANDC 1
28 #endif
29 // ---------------- select compiler ----------------
30 
31 // ================ select platform ================
32 #if (defined(linux) || defined(__linux) || defined(__linux__) || defined(__GNU__) || defined(__GLIBC__)) && !defined(_CRAYC)
33 #define COPP_MACRO_PLATFORM_LINUX
34 #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
35 #define COPP_MACRO_PLATFORM_BSD
36 #elif defined(sun) || defined(__sun)
37 #define COPP_MACRO_PLATFORM_SOLARIS
38 #elif defined(__sgi)
39 #define COPP_MACRO_PLATFORM_SGI
40 #elif defined(__hpux)
41 #define COPP_MACRO_PLATFORM_HPUNIX
42 #elif defined(__CYGWIN__)
43 #define COPP_MACRO_PLATFORM_CYGWIN
44 #elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
45 #define COPP_MACRO_PLATFORM_WIN32
46 #else
47 #if defined(unix) || defined(__unix) || defined(_XOPEN_SOURCE) || defined(_POSIX_SOURCE)
48 #define COPP_MACRO_PLATFORM_UNIX
49 #endif
50 #endif
51 // ---------------- select platform ----------------
52 
53 // ================ c extern ================
54 #if !defined(__BEGIN_DECLS) && !defined(__END_DECLS)
55 #if defined(__cplusplus)
56 #define __BEGIN_DECLS extern "C" {
57 #define __END_DECLS }
58 #else
59 #define __BEGIN_DECLS
60 #define __END_DECLS
61 #endif
62 #endif
63 
64 #if !defined(__THROW)
65 #define __THROW
66 #endif
67 // ---------------- c extern ----------------
68 #if defined(UTIL_CONFIG_NOEXCEPT)
69 #define COPP_MACRO_NOEXCEPT UTIL_CONFIG_NOEXCEPT
70 #else
71 #define COPP_MACRO_NOEXCEPT
72 #endif
73 
74 // ================ compiler abi headers ================
75 #if defined(COPP_MACRO_COMPILER_MSVC)
76 #define COPP_HAS_ABI_HEADERS 1
77 #define COPP_ABI_PREFIX "libcopp/utils/abi/msvc_prefix.hpp"
78 #define COPP_ABI_SUFFIX "libcopp/utils/abi/msvc_suffix.hpp"
79 #elif defined COPP_MACRO_COMPILER_BORLANDC
80 #define COPP_HAS_ABI_HEADERS 1
81 #define COPP_ABI_PREFIX "libcopp/utils/abi/borland_prefix.hpp"
82 #define COPP_ABI_SUFFIX "libcopp/utils/abi/borland_suffix.hpp"
83 #endif
84 // ---------------- compiler abi headers ----------------
85 
86 
87 // ================ function flags ================
88 
89 
90 #if defined(LIBCOPP_MACRO_USE_SEGMENTED_STACKS)
91 #if !((defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ > 3 && __GNUC_MINOR__ > 6))) || \
92  (defined(__clang__) && __clang_major__ > 2 && __clang_minor__ > 3))
93 #error "compiler does not support segmented_stack stacks"
94 #endif
95 #define COPP_MACRO_SEGMENTED_STACK_NUMBER 10
96 #endif
97 
98 #ifndef COPP_MACRO_CPP_STD
99 #if defined(__cplusplus) && __cplusplus >= 201103L
100 #define COPP_MACRO_CPP_STD 201103L
101 #define COPP_MACRO_ENABLE_SMART_PTR 1
102 #else
103 #define COPP_MACRO_CPP_STD 199711L
104 #endif
105 #endif
106 
107 
108 #if defined(UTIL_CONFIG_COMPILER_CXX_VARIADIC_TEMPLATES) && UTIL_CONFIG_COMPILER_CXX_VARIADIC_TEMPLATES
109 #define COPP_MACRO_ENABLE_VARIADIC_TEMPLATE 1
110 #endif
111 
113 #if defined(STD_DECLTYPE)
114 #define COPP_MACRO_TYPEOF(...) STD_DECLTYPE(__VA_ARGS__)
115 #endif
116 
117 #if defined(_POSIX_MT_) || defined(_MSC_VER)
118 #define COPP_MACRO_ENABLE_MULTI_THREAD
119 #endif
120 // ---------------- function flags ----------------
121 
122 
123 // ================ branch prediction information ================
124 #ifndef likely
125 #ifdef __GNUC__
126 #define likely(x) __builtin_expect(!!(x), 1)
127 #else
128 #define likely(x) !!(x)
129 #endif
130 #endif
131 
132 #ifndef unlikely
133 #ifdef __GNUC__
134 #define unlikely(x) __builtin_expect(!!(x), 0)
135 #else
136 #define unlikely(x) !!(x)
137 #endif
138 #endif
139 
140 #ifndef unreachable
141 #ifdef __GNUC__
142 #ifdef __clang__
143 #if __has_builtin(__builtin_unreachable)
144 #define unreachable() __builtin_unreachable()
145 #else
146 #define unreachable() abort()
147 #endif
148 #else
149 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
150 #define unreachable() __builtin_unreachable()
151 #else
152 #define unreachable() abort()
153 #endif
154 #endif
155 #else
156 #define unreachable() abort()
157 #endif
158 #endif
159 // ---------------- branch prediction information ----------------
160 
161 #include "errno.h"
162 
163 
164 #if defined(UTIL_CONFIG_COMPILER_CXX_RVALUE_REFERENCES) && UTIL_CONFIG_COMPILER_CXX_RVALUE_REFERENCES
165 
166 #if !defined(COPP_MACRO_RV_REF)
167 #define COPP_MACRO_RV_REF &&
168 #endif
169 
170 #if !defined(COPP_MACRO_STD_MOVE)
171 #define COPP_MACRO_STD_MOVE(x) std::move(x)
172 #endif
173 
174 #if !defined(COPP_MACRO_STD_FORWARD)
175 #define COPP_MACRO_STD_FORWARD(t, x) std::forward<t>(x)
176 #endif
177 
178 #else
179 
180 #if !defined(COPP_MACRO_RV_REF)
181 #define COPP_MACRO_RV_REF
182 #endif
183 
184 #if !defined(COPP_MACRO_STD_MOVE)
185 #define COPP_MACRO_STD_MOVE(x) x
186 #endif
187 
188 #if !defined(COPP_MACRO_STD_FORWARD)
189 #define COPP_MACRO_STD_FORWARD(t, x) x
190 #endif
191 
192 #endif
193 
194 #endif
decltype兼容层 Licensed under the MIT licenses.