Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 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 |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 4 | |
| 5 | include(CheckCXXSourceCompiles) |
| 6 | |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 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) |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 15 | |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 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) |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 19 | |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 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.") |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 89 | endif() |
| 90 | endif() |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 91 | set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) |
| 92 | set(CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES}) |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 93 | endif() |
| 94 | endif() |