xref: /aosp_15_r20/external/llvm/cmake/modules/CheckCompilerVersion.cmake (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker# Check if the host compiler is new enough. LLVM requires at least GCC 4.7,
2*9880d681SAndroid Build Coastguard Worker# MSVC 2013, or Clang 3.1.
3*9880d681SAndroid Build Coastguard Worker
4*9880d681SAndroid Build Coastguard Workerinclude(CheckCXXSourceCompiles)
5*9880d681SAndroid Build Coastguard Worker
6*9880d681SAndroid Build Coastguard Workerif(NOT DEFINED LLVM_COMPILER_CHECKED)
7*9880d681SAndroid Build Coastguard Worker  set(LLVM_COMPILER_CHECKED ON)
8*9880d681SAndroid Build Coastguard Worker
9*9880d681SAndroid Build Coastguard Worker  if(NOT LLVM_FORCE_USE_OLD_TOOLCHAIN)
10*9880d681SAndroid Build Coastguard Worker    if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
11*9880d681SAndroid Build Coastguard Worker      if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
12*9880d681SAndroid Build Coastguard Worker        message(FATAL_ERROR "Host GCC version must be at least 4.7!")
13*9880d681SAndroid Build Coastguard Worker      endif()
14*9880d681SAndroid Build Coastguard Worker    elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
15*9880d681SAndroid Build Coastguard Worker      if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.1)
16*9880d681SAndroid Build Coastguard Worker        message(FATAL_ERROR "Host Clang version must be at least 3.1!")
17*9880d681SAndroid Build Coastguard Worker      endif()
18*9880d681SAndroid Build Coastguard Worker
19*9880d681SAndroid Build Coastguard Worker      if (CMAKE_CXX_SIMULATE_ID MATCHES "MSVC")
20*9880d681SAndroid Build Coastguard Worker        if (CMAKE_CXX_SIMULATE_VERSION VERSION_LESS 18.0)
21*9880d681SAndroid Build Coastguard Worker          message(FATAL_ERROR "Host Clang must have at least -fms-compatibility-version=18.0")
22*9880d681SAndroid Build Coastguard Worker        endif()
23*9880d681SAndroid Build Coastguard Worker        set(CLANG_CL 1)
24*9880d681SAndroid Build Coastguard Worker      elseif(NOT LLVM_ENABLE_LIBCXX)
25*9880d681SAndroid Build Coastguard Worker        # Otherwise, test that we aren't using too old of a version of libstdc++
26*9880d681SAndroid Build Coastguard Worker        # with the Clang compiler. This is tricky as there is no real way to
27*9880d681SAndroid Build Coastguard Worker        # check the version of libstdc++ directly. Instead we test for a known
28*9880d681SAndroid Build Coastguard Worker        # bug in libstdc++4.6 that is fixed in libstdc++4.7.
29*9880d681SAndroid Build Coastguard Worker        set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
30*9880d681SAndroid Build Coastguard Worker        set(OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
31*9880d681SAndroid Build Coastguard Worker        set(CMAKE_REQUIRED_FLAGS "-std=c++0x")
32*9880d681SAndroid Build Coastguard Worker        check_cxx_source_compiles("
33*9880d681SAndroid Build Coastguard Worker#include <atomic>
34*9880d681SAndroid Build Coastguard Workerstd::atomic<float> x(0.0f);
35*9880d681SAndroid Build Coastguard Workerint main() { return (float)x; }"
36*9880d681SAndroid Build Coastguard Worker          LLVM_NO_OLD_LIBSTDCXX)
37*9880d681SAndroid Build Coastguard Worker        if(NOT LLVM_NO_OLD_LIBSTDCXX)
38*9880d681SAndroid Build Coastguard Worker          message(FATAL_ERROR "Host Clang must be able to find libstdc++4.7 or newer!")
39*9880d681SAndroid Build Coastguard Worker        endif()
40*9880d681SAndroid Build Coastguard Worker        set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
41*9880d681SAndroid Build Coastguard Worker        set(CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES})
42*9880d681SAndroid Build Coastguard Worker      endif()
43*9880d681SAndroid Build Coastguard Worker    elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
44*9880d681SAndroid Build Coastguard Worker      if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18.0)
45*9880d681SAndroid Build Coastguard Worker        message(FATAL_ERROR "Host Visual Studio must be at least 2013")
46*9880d681SAndroid Build Coastguard Worker      elseif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18.0.31101)
47*9880d681SAndroid Build Coastguard Worker        message(WARNING "Host Visual Studio should at least be 2013 Update 4 (MSVC 18.0.31101)"
48*9880d681SAndroid Build Coastguard Worker          "  due to miscompiles from earlier versions")
49*9880d681SAndroid Build Coastguard Worker      endif()
50*9880d681SAndroid Build Coastguard Worker    endif()
51*9880d681SAndroid Build Coastguard Worker  endif()
52*9880d681SAndroid Build Coastguard Workerendif()
53