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
5 include(CheckCXXSourceCompiles)
8 set(GCC_SOFT_ERROR 5.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)
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)
21 if(DEFINED LLVM_COMPILER_CHECKED)
24 set(LLVM_COMPILER_CHECKED ON)
26 if(LLVM_FORCE_USE_OLD_TOOLCHAIN)
30 function(check_compiler_version NAME NICE_NAME MINIMUM_VERSION SOFT_ERROR_VERSION)
31 if(NOT CMAKE_CXX_COMPILER_ID STREQUAL NAME)
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.")
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.")
43 endfunction(check_compiler_version)
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})
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}.")
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 # Test for libstdc++ version of at least 4.8 by checking for _ZNKSt17bad_function_call4whatEv.
62 # Note: We should check _GLIBCXX_RELEASE when possible (i.e., for GCC 7.1 and up).
63 check_cxx_source_compiles("
65 #if defined(__GLIBCXX__)
66 #if __GLIBCXX__ < ${GCC_MIN_DATE}
67 #error Unsupported libstdc++ version
70 #if defined(__GLIBCXX__)
71 extern const char _ZNKSt17bad_function_call4whatEv[];
72 const char *chk = _ZNKSt17bad_function_call4whatEv;
74 const char *chk = \"\";
76 int main() { ++chk; return 0; }
79 if(NOT LLVM_LIBSTDCXX_MIN)
80 message(FATAL_ERROR "libstdc++ version must be at least ${GCC_MIN}.")
82 # Test for libstdc++ version of at least 5.1 by checking for std::iostream_category().
83 # Note: We should check _GLIBCXX_RELEASE when possible (i.e., for GCC 7.1 and up).
84 check_cxx_source_compiles("
86 #if defined(__GLIBCXX__)
87 #if __GLIBCXX__ < ${GCC_SOFT_ERROR_DATE}
88 #error Unsupported libstdc++ version
91 #if defined(__GLIBCXX__)
93 void foo(void) { (void) std::iostream_category(); }
95 int main() { return 0; }
97 LLVM_LIBSTDCXX_SOFT_ERROR)
98 if(NOT LLVM_LIBSTDCXX_SOFT_ERROR)
99 if(LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN)
100 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.")
102 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.")
105 set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
106 set(CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES})