| 1 |
/* SPDX-License-Identifier: BSL-1.0 OR BSD-3-Clause */ |
| 2 |
|
| 3 |
#ifndef MPT_BASE_DETECT_COMPILER_HPP |
| 4 |
#define MPT_BASE_DETECT_COMPILER_HPP |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#define MPT_COMPILER_MAKE_VERSION2(version, sp) ((version)*100 + (sp)) |
| 9 |
#define MPT_COMPILER_MAKE_VERSION3(major, minor, patch) ((major)*10000 + (minor)*100 + (patch)) |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
#if defined(MPT_COMPILER_GENERIC) |
| 14 |
|
| 15 |
#undef MPT_COMPILER_GENERIC |
| 16 |
#define MPT_COMPILER_GENERIC 1 |
| 17 |
|
| 18 |
#elif defined(__clang__) && defined(_MSC_VER) && defined(__c2__) |
| 19 |
|
| 20 |
#error "Clang/C2 is not supported. Please use Clang/LLVM for Windows instead." |
| 21 |
|
| 22 |
#elif defined(__clang__) |
| 23 |
|
| 24 |
#define MPT_COMPILER_CLANG 1 |
| 25 |
#define MPT_COMPILER_CLANG_VERSION MPT_COMPILER_MAKE_VERSION3(__clang_major__, __clang_minor__, __clang_patchlevel__) |
| 26 |
#define MPT_CLANG_AT_LEAST(major, minor, patch) (MPT_COMPILER_CLANG_VERSION >= MPT_COMPILER_MAKE_VERSION3((major), (minor), (patch))) |
| 27 |
#define MPT_CLANG_BEFORE(major, minor, patch) (MPT_COMPILER_CLANG_VERSION < MPT_COMPILER_MAKE_VERSION3((major), (minor), (patch))) |
| 28 |
|
| 29 |
#if MPT_CLANG_BEFORE(6, 0, 0) |
| 30 |
#error "clang version 6 required" |
| 31 |
#endif |
| 32 |
|
| 33 |
#if defined(__clang_analyzer__) |
| 34 |
#ifndef MPT_BUILD_ANALYZED |
| 35 |
#define MPT_BUILD_ANALYZED |
| 36 |
#endif |
| 37 |
#endif |
| 38 |
|
| 39 |
#elif defined(__GNUC__) |
| 40 |
|
| 41 |
#define MPT_COMPILER_GCC 1 |
| 42 |
#define MPT_COMPILER_GCC_VERSION MPT_COMPILER_MAKE_VERSION3(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) |
| 43 |
#define MPT_GCC_AT_LEAST(major, minor, patch) (MPT_COMPILER_GCC_VERSION >= MPT_COMPILER_MAKE_VERSION3((major), (minor), (patch))) |
| 44 |
#define MPT_GCC_BEFORE(major, minor, patch) (MPT_COMPILER_GCC_VERSION < MPT_COMPILER_MAKE_VERSION3((major), (minor), (patch))) |
| 45 |
|
| 46 |
#if MPT_GCC_BEFORE(7, 1, 0) |
| 47 |
#error "GCC version 7.1 required" |
| 48 |
#endif |
| 49 |
|
| 50 |
#elif defined(_MSC_VER) |
| 51 |
|
| 52 |
#define MPT_COMPILER_MSVC 1 |
| 53 |
#if (_MSC_VER >= 1944) |
| 54 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2022, 14) |
| 55 |
#elif (_MSC_VER >= 1943) |
| 56 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2022, 13) |
| 57 |
#elif (_MSC_VER >= 1942) |
| 58 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2022, 12) |
| 59 |
#elif (_MSC_VER >= 1941) |
| 60 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2022, 11) |
| 61 |
#elif (_MSC_VER >= 1940) |
| 62 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2022, 10) |
| 63 |
#elif (_MSC_VER >= 1939) |
| 64 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2022, 9) |
| 65 |
#elif (_MSC_VER >= 1938) |
| 66 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2022, 8) |
| 67 |
#elif (_MSC_VER >= 1937) |
| 68 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2022, 7) |
| 69 |
#elif (_MSC_VER >= 1936) |
| 70 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2022, 6) |
| 71 |
#elif (_MSC_VER >= 1935) |
| 72 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2022, 5) |
| 73 |
#elif (_MSC_VER >= 1934) |
| 74 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2022, 4) |
| 75 |
#elif (_MSC_VER >= 1933) |
| 76 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2022, 3) |
| 77 |
#elif (_MSC_VER >= 1932) |
| 78 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2022, 2) |
| 79 |
#elif (_MSC_VER >= 1931) |
| 80 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2022, 1) |
| 81 |
#elif (_MSC_VER >= 1930) |
| 82 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2022, 0) |
| 83 |
#elif (_MSC_VER >= 1929) |
| 84 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2019, 10) |
| 85 |
#elif (_MSC_VER >= 1928) |
| 86 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2019, 8) |
| 87 |
#elif (_MSC_VER >= 1927) |
| 88 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2019, 7) |
| 89 |
#elif (_MSC_VER >= 1926) |
| 90 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2019, 6) |
| 91 |
#elif (_MSC_VER >= 1925) |
| 92 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2019, 5) |
| 93 |
#elif (_MSC_VER >= 1924) |
| 94 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2019, 4) |
| 95 |
#elif (_MSC_VER >= 1923) |
| 96 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2019, 3) |
| 97 |
#elif (_MSC_VER >= 1922) |
| 98 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2019, 2) |
| 99 |
#elif (_MSC_VER >= 1921) |
| 100 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2019, 1) |
| 101 |
#elif (_MSC_VER >= 1920) |
| 102 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2019, 0) |
| 103 |
#elif (_MSC_VER >= 1916) |
| 104 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2017, 9) |
| 105 |
#elif (_MSC_VER >= 1915) |
| 106 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2017, 8) |
| 107 |
#elif (_MSC_VER >= 1914) |
| 108 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2017, 7) |
| 109 |
#elif (_MSC_VER >= 1913) |
| 110 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2017, 6) |
| 111 |
#elif (_MSC_VER >= 1912) |
| 112 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2017, 5) |
| 113 |
#elif (_MSC_VER >= 1911) |
| 114 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2017, 3) |
| 115 |
#elif (_MSC_VER >= 1910) |
| 116 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2017, 0) |
| 117 |
#elif (_MSC_VER >= 1900) && defined(_MSVC_LANG) |
| 118 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2015, 3) |
| 119 |
#elif (_MSC_VER >= 1900) |
| 120 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2015, 0) |
| 121 |
#elif (_MSC_VER >= 1800) |
| 122 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2013, 0) |
| 123 |
#elif (_MSC_VER >= 1700) |
| 124 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2012, 0) |
| 125 |
#elif (_MSC_VER >= 1600) |
| 126 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2010, 0) |
| 127 |
#elif (_MSC_VER >= 1500) |
| 128 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2008, 0) |
| 129 |
#else |
| 130 |
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2005, 0) |
| 131 |
#endif |
| 132 |
#define MPT_MSVC_AT_LEAST(version, sp) (MPT_COMPILER_MSVC_VERSION >= MPT_COMPILER_MAKE_VERSION2((version), (sp))) |
| 133 |
#define MPT_MSVC_BEFORE(version, sp) (MPT_COMPILER_MSVC_VERSION < MPT_COMPILER_MAKE_VERSION2((version), (sp))) |
| 134 |
|
| 135 |
#if MPT_MSVC_BEFORE(2017, 9) |
| 136 |
#error "MSVC version 2017 15.9 required" |
| 137 |
#endif |
| 138 |
|
| 139 |
#if defined(_PREFAST_) |
| 140 |
#ifndef MPT_BUILD_ANALYZED |
| 141 |
#define MPT_BUILD_ANALYZED |
| 142 |
#endif |
| 143 |
#endif |
| 144 |
|
| 145 |
#else |
| 146 |
|
| 147 |
#define MPT_COMPILER_GENERIC 1 |
| 148 |
|
| 149 |
#endif |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
#ifndef MPT_COMPILER_GENERIC |
| 154 |
#define MPT_COMPILER_GENERIC 0 |
| 155 |
#endif |
| 156 |
#ifndef MPT_COMPILER_CLANG |
| 157 |
#define MPT_COMPILER_CLANG 0 |
| 158 |
#define MPT_CLANG_AT_LEAST(major, minor, patch) 0 |
| 159 |
#define MPT_CLANG_BEFORE(major, minor, patch) 0 |
| 160 |
#endif |
| 161 |
#ifndef MPT_COMPILER_GCC |
| 162 |
#define MPT_COMPILER_GCC 0 |
| 163 |
#define MPT_GCC_AT_LEAST(major, minor, patch) 0 |
| 164 |
#define MPT_GCC_BEFORE(major, minor, patch) 0 |
| 165 |
#endif |
| 166 |
#ifndef MPT_COMPILER_MSVC |
| 167 |
#define MPT_COMPILER_MSVC 0 |
| 168 |
#define MPT_MSVC_AT_LEAST(version, sp) 0 |
| 169 |
#define MPT_MSVC_BEFORE(version, sp) 0 |
| 170 |
#endif |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
#if MPT_COMPILER_GENERIC |
| 175 |
|
| 176 |
#if (__cplusplus >= 202302) |
| 177 |
#define MPT_CXX 23 |
| 178 |
#elif (__cplusplus >= 202002) |
| 179 |
#define MPT_CXX 20 |
| 180 |
#elif (__cplusplus >= 201703) |
| 181 |
#define MPT_CXX 17 |
| 182 |
#endif |
| 183 |
|
| 184 |
#elif MPT_COMPILER_GCC || MPT_COMPILER_CLANG |
| 185 |
|
| 186 |
#if (__cplusplus >= 202302) |
| 187 |
#define MPT_CXX 23 |
| 188 |
#elif (__cplusplus >= 202002) |
| 189 |
#if defined(__APPLE__) && MPT_CLANG_BEFORE(13, 0, 0) |
| 190 |
// XCode 12.5 has a really weird mix of Clang and libc++. Just black-list C++20 support for XCode <= 12. |
| 191 |
#define MPT_CXX 17 |
| 192 |
#else |
| 193 |
#define MPT_CXX 20 |
| 194 |
#endif |
| 195 |
#elif (__cplusplus >= 201703) |
| 196 |
#define MPT_CXX 17 |
| 197 |
#endif |
| 198 |
|
| 199 |
#elif MPT_COMPILER_MSVC |
| 200 |
|
| 201 |
#if MPT_MSVC_AT_LEAST(2015, 3) |
| 202 |
#if (_MSVC_LANG >= 202302) |
| 203 |
#define MPT_CXX 23 |
| 204 |
#elif (_MSVC_LANG >= 202002) |
| 205 |
#define MPT_CXX 20 |
| 206 |
#elif (_MSVC_LANG >= 201703) |
| 207 |
#define MPT_CXX 17 |
| 208 |
#endif |
| 209 |
#endif |
| 210 |
|
| 211 |
#endif |
| 212 |
|
| 213 |
// default to C++17 |
| 214 |
#ifndef MPT_CXX |
| 215 |
#define MPT_CXX 17 |
| 216 |
#endif |
| 217 |
|
| 218 |
// MPT_CXX is stricter than just using __cplusplus directly. |
| 219 |
// We will only claim a language version as supported IFF all core language and |
| 220 |
// library fatures that we need are actually supported AND working correctly |
| 221 |
// (to our needs). |
| 222 |
|
| 223 |
#define MPT_CXX_AT_LEAST(version) (MPT_CXX >= (version)) |
| 224 |
#define MPT_CXX_BEFORE(version) (MPT_CXX < (version)) |
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
// detect compiler quirks |
| 229 |
|
| 230 |
#if MPT_COMPILER_CLANG |
| 231 |
#if defined(__APPLE__) |
| 232 |
#define MPT_COMPILER_QUIRK_APPLE_CLANG |
| 233 |
#endif |
| 234 |
#endif |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
// detect compiler setting quirks |
| 239 |
|
| 240 |
#if MPT_COMPILER_GCC |
| 241 |
#if (MPT_GCC_AT_LEAST(14, 0, 0) && MPT_GCC_BEFORE(14, 2, 0)) || (MPT_GCC_AT_LEAST(13, 0, 0) && MPT_GCC_BEFORE(13, 4, 0)) || (MPT_GCC_AT_LEAST(12, 0, 0) && MPT_GCC_BEFORE(12, 5, 0)) || MPT_GCC_BEFORE(12, 0, 0) |
| 242 |
// GCC 14 causes severe miscompilation of inline functions on MinGW. |
| 243 |
// See <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115049>. |
| 244 |
// Current investigation suggests a general problem with -fipa-ra on non-ELF |
| 245 |
// platforms. |
| 246 |
// As far as we understand the issue, it could possibly also manifest with |
| 247 |
// other inter-procedure-optimizations and with older GCC versions. |
| 248 |
// Fixed in GCC 15 |
| 249 |
// (<https://gcc.gnu.org/git/?p=gcc.git;h=5080840d8fbf25a321dd27543a1462d393d338bc>), |
| 250 |
// GCC 14.2 |
| 251 |
// (<https://gcc.gnu.org/git/?p=gcc.git;h=747c4b58573ea00419f64293a61537eb69f43307>). |
| 252 |
// GCC 13.4 |
| 253 |
// (<https://gcc.gnu.org/git/?p=gcc.git;h=953bf37690d22de956d75c6aef7a9690ad55b9a7>). |
| 254 |
// and GCC 12.5 |
| 255 |
// (<https://gcc.gnu.org/git/?p=gcc.git;h=2c5f48a43f26223cb8603b826d7c0d52cdbcfb46>). |
| 256 |
#if !defined(__ELF__) |
| 257 |
#define MPT_COMPILER_SETTING_QUIRK_GCC_BROKEN_IPA |
| 258 |
#endif |
| 259 |
#endif |
| 260 |
#endif |
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
#endif // MPT_BASE_DETECT_COMPILER_HPP |