JF Bastien | 4675d21 | 2019-01-16 22:22:38 +0000 | [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/GettingStarted.html#host-c-toolchain-both-compiler-and-standard-library |
Reid Kleckner | 9fac19f | 2016-03-02 16:42:56 +0000 | [diff] [blame] | 4 | |
Saleem Abdulrasool | 2d5e95c | 2016-03-08 18:56:00 +0000 | [diff] [blame] | 5 | include(CheckCXXSourceCompiles) |
| 6 | |
JF Bastien | 4675d21 | 2019-01-16 22:22:38 +0000 | [diff] [blame^] | 7 | set(GCC_MIN 4.8) |
| 8 | set(GCC_WARN 4.8) |
| 9 | set(CLANG_MIN 3.1) |
| 10 | set(CLANG_WARN 3.1) |
| 11 | set(APPLECLANG_MIN 3.1) |
| 12 | set(APPLECLANG_WARN 3.1) |
| 13 | set(MSVC_MIN 19.0) |
| 14 | set(MSVC_WARN 19.00.24213.1) |
Reid Kleckner | 9fac19f | 2016-03-02 16:42:56 +0000 | [diff] [blame] | 15 | |
JF Bastien | 4675d21 | 2019-01-16 22:22:38 +0000 | [diff] [blame^] | 16 | if(DEFINED LLVM_COMPILER_CHECKED) |
| 17 | return() |
| 18 | endif() |
| 19 | set(LLVM_COMPILER_CHECKED ON) |
Reid Kleckner | 9fac19f | 2016-03-02 16:42:56 +0000 | [diff] [blame] | 20 | |
JF Bastien | 4675d21 | 2019-01-16 22:22:38 +0000 | [diff] [blame^] | 21 | if(LLVM_FORCE_USE_OLD_TOOLCHAIN) |
| 22 | return() |
| 23 | endif() |
| 24 | |
| 25 | function(check_compiler_version NAME NICE_NAME MINIMUM_VERSION WARN_VERSION) |
| 26 | if(NOT CMAKE_CXX_COMPILER_ID STREQUAL NAME) |
| 27 | return() |
| 28 | endif() |
| 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}.") |
| 33 | endif() |
| 34 | endfunction(check_compiler_version) |
| 35 | |
| 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}) |
| 40 | |
| 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}.") |
| 45 | endif() |
| 46 | set(CLANG_CL 1) |
| 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(" |
Reid Kleckner | 9fac19f | 2016-03-02 16:42:56 +0000 | [diff] [blame] | 56 | #include <atomic> |
| 57 | std::atomic<float> x(0.0f); |
| 58 | int main() { return (float)x; }" |
JF Bastien | 4675d21 | 2019-01-16 22:22:38 +0000 | [diff] [blame^] | 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!") |
Reid Kleckner | 9fac19f | 2016-03-02 16:42:56 +0000 | [diff] [blame] | 62 | endif() |
JF Bastien | 4675d21 | 2019-01-16 22:22:38 +0000 | [diff] [blame^] | 63 | set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) |
| 64 | set(CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES}) |
Reid Kleckner | 9fac19f | 2016-03-02 16:42:56 +0000 | [diff] [blame] | 65 | endif() |
| 66 | endif() |