|
1 |
| -# Check if the host compiler is new enough. LLVM requires at least GCC 4.8, |
2 |
| -# MSVC 2015 (Update 3), or Clang 3.1. |
| 1 | +# Check if the host compiler is new enough. |
| 2 | +# These versions are updated based on the following policy: |
| 3 | +# llvm.org/docs/DeveloperPolicy.html#toolchain |
3 | 4 |
|
4 | 5 | include(CheckCXXSourceCompiles)
|
5 | 6 |
|
6 |
| -if(NOT DEFINED LLVM_COMPILER_CHECKED) |
7 |
| - set(LLVM_COMPILER_CHECKED ON) |
| 7 | +set(GCC_MIN 4.8) |
| 8 | +set(GCC_SOFT_ERROR 5.1) |
| 9 | +set(CLANG_MIN 3.1) |
| 10 | +set(CLANG_SOFT_ERROR 3.5) |
| 11 | +set(APPLECLANG_MIN 3.1) |
| 12 | +set(APPLECLANG_SOFT_ERROR 6.0) |
| 13 | +set(MSVC_MIN 19.00.24213.1) |
| 14 | +set(MSVC_SOFT_ERROR 19.1) |
8 | 15 |
|
9 |
| - if(NOT LLVM_FORCE_USE_OLD_TOOLCHAIN) |
10 |
| - if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
11 |
| - if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8) |
12 |
| - message(FATAL_ERROR "Host GCC version must be at least 4.8!") |
13 |
| - endif() |
14 |
| - elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") |
15 |
| - if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.1) |
16 |
| - message(FATAL_ERROR "Host Clang version must be at least 3.1!") |
17 |
| - endif() |
| 16 | +# Map the above GCC versions to dates: https://gcc.gnu.org/develop.html#timeline |
| 17 | +set(GCC_MIN_DATE 20130322) |
| 18 | +set(GCC_SOFT_ERROR_DATE 20150422) |
18 | 19 |
|
19 |
| - if (CMAKE_CXX_SIMULATE_ID MATCHES "MSVC") |
20 |
| - if (CMAKE_CXX_SIMULATE_VERSION VERSION_LESS 19.0) |
21 |
| - message(FATAL_ERROR "Host Clang must have at least -fms-compatibility-version=19.0") |
22 |
| - endif() |
23 |
| - set(CLANG_CL 1) |
24 |
| - elseif(NOT LLVM_ENABLE_LIBCXX) |
25 |
| - # Otherwise, test that we aren't using too old of a version of libstdc++ |
26 |
| - # with the Clang compiler. This is tricky as there is no real way to |
27 |
| - # check the version of libstdc++ directly. Instead we test for a known |
28 |
| - # bug in libstdc++4.6 that is fixed in libstdc++4.7. |
29 |
| - set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) |
30 |
| - set(OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) |
31 |
| - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++0x") |
32 |
| - check_cxx_source_compiles(" |
33 |
| -#include <atomic> |
34 |
| -std::atomic<float> x(0.0f); |
35 |
| -int main() { return (float)x; }" |
36 |
| - LLVM_NO_OLD_LIBSTDCXX) |
37 |
| - if(NOT LLVM_NO_OLD_LIBSTDCXX) |
38 |
| - message(FATAL_ERROR "Host Clang must be able to find libstdc++4.8 or newer!") |
39 |
| - endif() |
40 |
| - set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) |
41 |
| - set(CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES}) |
42 |
| - endif() |
43 |
| - elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") |
44 |
| - if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.0) |
45 |
| - message(FATAL_ERROR "Host Visual Studio must be at least 2015") |
46 |
| - elseif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.00.24213.1) |
47 |
| - message(WARNING "Host Visual Studio should at least be 2015 Update 3 (MSVC 19.00.24213.1)" |
48 |
| - " due to miscompiles from earlier versions") |
| 20 | + |
| 21 | +if(DEFINED LLVM_COMPILER_CHECKED) |
| 22 | + return() |
| 23 | +endif() |
| 24 | +set(LLVM_COMPILER_CHECKED ON) |
| 25 | + |
| 26 | +if(LLVM_FORCE_USE_OLD_TOOLCHAIN) |
| 27 | + return() |
| 28 | +endif() |
| 29 | + |
| 30 | +function(check_compiler_version NAME NICE_NAME MINIMUM_VERSION SOFT_ERROR_VERSION) |
| 31 | + if(NOT CMAKE_CXX_COMPILER_ID STREQUAL NAME) |
| 32 | + return() |
| 33 | + endif() |
| 34 | + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS MINIMUM_VERSION) |
| 35 | + message(FATAL_ERROR "Host ${NICE_NAME} version must be at least ${MINIMUM_VERSION}, your version is ${CMAKE_CXX_COMPILER_VERSION}.") |
| 36 | + elseif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS SOFT_ERROR_VERSION) |
| 37 | + if(LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN) |
| 38 | + message(WARNING "Host ${NICE_NAME} version should be at least ${SOFT_ERROR_VERSION} because LLVM will soon use new C++ features which your toolchain version doesn't support. Your version is ${CMAKE_CXX_COMPILER_VERSION}. Ignoring because you've set LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN, but very soon your toolchain won't be supported.") |
| 39 | + else() |
| 40 | + message(FATAL_ERROR "Host ${NICE_NAME} version should be at least ${SOFT_ERROR_VERSION} because LLVM will soon use new C++ features which your toolchain version doesn't support. Your version is ${CMAKE_CXX_COMPILER_VERSION}. You can temporarily opt out using LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN, but very soon your toolchain won't be supported.") |
| 41 | + endif() |
| 42 | + endif() |
| 43 | +endfunction(check_compiler_version) |
| 44 | + |
| 45 | +check_compiler_version("GNU" "GCC" ${GCC_MIN} ${GCC_SOFT_ERROR}) |
| 46 | +check_compiler_version("Clang" "Clang" ${CLANG_MIN} ${CLANG_SOFT_ERROR}) |
| 47 | +check_compiler_version("AppleClang" "Apple Clang" ${APPLECLANG_MIN} ${APPLECLANG_SOFT_ERROR}) |
| 48 | +check_compiler_version("MSVC" "Visual Studio" ${MSVC_MIN} ${MSVC_SOFT_ERROR}) |
| 49 | + |
| 50 | +if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") |
| 51 | + if (CMAKE_CXX_SIMULATE_ID MATCHES "MSVC") |
| 52 | + if (CMAKE_CXX_SIMULATE_VERSION VERSION_LESS MSVC_MIN) |
| 53 | + message(FATAL_ERROR "Host Clang must have at least -fms-compatibility-version=${MSVC_MIN}, your version is ${CMAKE_CXX_COMPILER_VERSION}.") |
| 54 | + endif() |
| 55 | + set(CLANG_CL 1) |
| 56 | + elseif(NOT LLVM_ENABLE_LIBCXX) |
| 57 | + # Test that we aren't using too old of a version of libstdc++. |
| 58 | + set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) |
| 59 | + set(OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) |
| 60 | + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++0x") |
| 61 | + check_cxx_source_compiles(" |
| 62 | +#include <iosfwd> |
| 63 | +#if defined(__GLIBCXX__) |
| 64 | +#if __GLIBCXX__ < ${GCC_MIN_DATE} |
| 65 | +#error Unsupported libstdc++ version |
| 66 | +#endif |
| 67 | +#endif |
| 68 | +int main() { return 0; } |
| 69 | +" |
| 70 | + LLVM_LIBSTDCXX_MIN) |
| 71 | + if(NOT LLVM_LIBSTDCXX_MIN) |
| 72 | + message(FATAL_ERROR "libstdc++ version must be at least ${GCC_MIN}.") |
| 73 | + endif() |
| 74 | + check_cxx_source_compiles(" |
| 75 | +#include <iosfwd> |
| 76 | +#if defined(__GLIBCXX__) |
| 77 | +#if __GLIBCXX__ < ${GCC_SOFT_ERROR_DATE} |
| 78 | +#error Unsupported libstdc++ version |
| 79 | +#endif |
| 80 | +#endif |
| 81 | +int main() { return 0; } |
| 82 | +" |
| 83 | + LLVM_LIBSTDCXX_SOFT_ERROR) |
| 84 | + if(NOT LLVM_LIBSTDCXX_SOFT_ERROR) |
| 85 | + if(LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN) |
| 86 | + message(WARNING "libstdc++ version should be at least ${GCC_SOFT_ERROR} because LLVM will soon use new C++ features which your toolchain version doesn't support. Ignoring because you've set LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN, but very soon your toolchain won't be supported.") |
| 87 | + else() |
| 88 | + message(FATAL_ERROR "libstdc++ version should be at least ${GCC_SOFT_ERROR} because LLVM will soon use new C++ features which your toolchain version doesn't support. You can temporarily opt out using LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN, but very soon your toolchain won't be supported.") |
49 | 89 | endif()
|
50 | 90 | endif()
|
| 91 | + set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) |
| 92 | + set(CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES}) |
51 | 93 | endif()
|
52 | 94 | endif()
|
0 commit comments