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)
11 set(APPLECLANG_MIN 3.1)
12 set(APPLECLANG_WARN 3.1)
14 set(MSVC_WARN 19.00.24213.1)
16 if(DEFINED LLVM_COMPILER_CHECKED)
19 set(LLVM_COMPILER_CHECKED ON)
21 if(LLVM_FORCE_USE_OLD_TOOLCHAIN)
25 function(check_compiler_version NAME NICE_NAME MINIMUM_VERSION WARN_VERSION)
26 if(NOT CMAKE_CXX_COMPILER_ID STREQUAL NAME)
29 if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS MINIMUM_VERSION)
30 message(FATAL_ERROR "Host ${NICE_NAME} version must be at least ${MINIMUM_VERSION}, your version is ${CMAKE_CXX_COMPILER_VERSION}.")
31 elseif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS WARN_VERSION)
32 message(WARNING "Host ${NICE_NAME} version must be at least ${WARN_VERSION} due to miscompiles from earlier versions, your version is ${CMAKE_CXX_COMPILER_VERSION}.")
34 endfunction(check_compiler_version)
36 check_compiler_version("GNU" "GCC" ${GCC_MIN} ${GCC_WARN})
37 check_compiler_version("Clang" "Clang" ${CLANG_MIN} ${CLANG_WARN})
38 check_compiler_version("AppleClang" "Apple Clang" ${APPLECLANG_MIN} ${APPLECLANG_WARN})
39 check_compiler_version("MSVC" "Visual Studio" ${MSVC_MIN} ${MSVC_WARN})
41 if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
42 if (CMAKE_CXX_SIMULATE_ID MATCHES "MSVC")
43 if (CMAKE_CXX_SIMULATE_VERSION VERSION_LESS MSVC_MIN)
44 message(FATAL_ERROR "Host Clang must have at least -fms-compatibility-version=${MSVC_MIN}, your version is ${CMAKE_CXX_COMPILER_VERSION}.")
47 elseif(NOT LLVM_ENABLE_LIBCXX)
48 # Test that we aren't using too old of a version of libstdc++
49 # with the Clang compiler. This is tricky as there is no real way to
50 # check the version of libstdc++ directly. Instead we test for a known
51 # bug in libstdc++4.6 that is fixed in libstdc++4.7.
52 set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
53 set(OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
54 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++0x")
55 check_cxx_source_compiles("
57 std::atomic<float> x(0.0f);
58 int main() { return (float)x; }"
59 LLVM_NO_OLD_LIBSTDCXX)
60 if(NOT LLVM_NO_OLD_LIBSTDCXX)
61 message(FATAL_ERROR "Host Clang must be able to find libstdc++4.8 or newer!")
63 set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
64 set(CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES})