1 | //===-- Compile time compiler detection -------------------------*- C++ -*-===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_COMPILER_H |
10 | #define LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_COMPILER_H |
11 | |
12 | // Example usage of compiler version checks |
13 | // #if defined(LIBC_COMPILER_CLANG_VER) |
14 | // # if LIBC_COMPILER_CLANG_VER < 1500 |
15 | // # warning "Libc only supports Clang 15 and later" |
16 | // # endif |
17 | // #elif defined(LIBC_COMPILER_GCC_VER) |
18 | // # if LIBC_COMPILER_GCC_VER < 1500 |
19 | // # warning "Libc only supports GCC 15 and later" |
20 | // # endif |
21 | // #elif defined(LIBC_COMPILER_MSC_VER) |
22 | // # if LIBC_COMPILER_MSC_VER < 1930 |
23 | // # warning "Libc only supports Visual Studio 2022 RTW (17.0) and later" |
24 | // # endif |
25 | // #endif |
26 | |
27 | #if defined(__clang__) |
28 | #define LIBC_COMPILER_IS_CLANG |
29 | #define LIBC_COMPILER_CLANG_VER (__clang_major__ * 100 + __clang_minor__) |
30 | #endif |
31 | |
32 | #if defined(__GNUC__) && !defined(__clang__) |
33 | #define LIBC_COMPILER_IS_GCC |
34 | #define LIBC_COMPILER_GCC_VER (__GNUC__ * 100 + __GNUC_MINOR__) |
35 | #endif |
36 | |
37 | #if defined(_MSC_VER) |
38 | #define LIBC_COMPILER_IS_MSC |
39 | // https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros |
40 | #define LIBC_COMPILER_MSC_VER (_MSC_VER) |
41 | #endif |
42 | |
43 | #endif // LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_COMPILER_H |
44 | |