• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Check if the host compiler is new enough. LLVM requires at least GCC 4.7,
2# MSVC 2013, or Clang 3.1.
3
4include(CheckCXXSourceCompiles)
5
6if(NOT DEFINED LLVM_COMPILER_CHECKED)
7  set(LLVM_COMPILER_CHECKED ON)
8
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.7)
12        message(FATAL_ERROR "Host GCC version must be at least 4.7!")
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()
18
19      if (CMAKE_CXX_SIMULATE_ID MATCHES "MSVC")
20        if (CMAKE_CXX_SIMULATE_VERSION VERSION_LESS 18.0)
21          message(FATAL_ERROR "Host Clang must have at least -fms-compatibility-version=18.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 "-std=c++0x")
32        check_cxx_source_compiles("
33#include <atomic>
34std::atomic<float> x(0.0f);
35int 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.7 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 18.0)
45        message(FATAL_ERROR "Host Visual Studio must be at least 2013")
46      elseif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18.0.31101)
47        message(WARNING "Host Visual Studio should at least be 2013 Update 4 (MSVC 18.0.31101)"
48          "  due to miscompiles from earlier versions")
49      endif()
50    endif()
51  endif()
52endif()
53