llvm.org GIT mirror llvm / 06ff4ba
[cmake] Check the compiler version first Otherwise users get messages from CheckAtomic about missing libatomic instead of a sensible message that says "use GCC 4.7 or newer". I structured the change along the lines of HandleLLVMStdlib.cmake, so that the standalone build of Clang still gets the compiler version check. Reviewers: beanz Differential Revision: http://reviews.llvm.org/D17789 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@262491 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 4 years ago
3 changed file(s) with 52 addition(s) and 43 deletion(s). Raw diff Collapse all Expand all
1010 include(CheckCXXSourceCompiles)
1111 include(TestBigEndian)
1212
13 include(CheckCompilerVersion)
1314 include(HandleLLVMStdlib)
1415
1516 if( UNIX AND NOT (BEOS OR HAIKU) )
0 # Check if the host compiler is new enough. LLVM requires at least GCC 4.7,
1 # MSVC 2013, or Clang 3.1.
2
3 if(NOT DEFINED LLVM_COMPILER_CHECKED)
4 set(LLVM_COMPILER_CHECKED ON)
5
6 if(NOT LLVM_FORCE_USE_OLD_TOOLCHAIN)
7 if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
8 if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
9 message(FATAL_ERROR "Host GCC version must be at least 4.7!")
10 endif()
11 elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
12 if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.1)
13 message(FATAL_ERROR "Host Clang version must be at least 3.1!")
14 endif()
15
16 if (CMAKE_CXX_SIMULATE_ID MATCHES "MSVC")
17 if (CMAKE_CXX_SIMULATE_VERSION VERSION_LESS 18.0)
18 message(FATAL_ERROR "Host Clang must have at least -fms-compatibility-version=18.0")
19 endif()
20 set(CLANG_CL 1)
21 elseif(NOT LLVM_ENABLE_LIBCXX)
22 # Otherwise, test that we aren't using too old of a version of libstdc++
23 # with the Clang compiler. This is tricky as there is no real way to
24 # check the version of libstdc++ directly. Instead we test for a known
25 # bug in libstdc++4.6 that is fixed in libstdc++4.7.
26 set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
27 set(OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
28 set(CMAKE_REQUIRED_FLAGS "-std=c++0x")
29 check_cxx_source_compiles("
30 #include
31 std::atomic x(0.0f);
32 int main() { return (float)x; }"
33 LLVM_NO_OLD_LIBSTDCXX)
34 if(NOT LLVM_NO_OLD_LIBSTDCXX)
35 message(FATAL_ERROR "Host Clang must be able to find libstdc++4.7 or newer!")
36 endif()
37 set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
38 set(CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES})
39 endif()
40 elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
41 if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18.0)
42 message(FATAL_ERROR "Host Visual Studio must be at least 2013")
43 elseif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18.0.31101)
44 message(WARNING "Host Visual Studio should at least be 2013 Update 4 (MSVC 18.0.31101)"
45 " due to miscompiles from earlier versions")
46 endif()
47 endif()
48 endif()
49 endif()
55 # else.
66 string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
77
8 include(CheckCompilerVersion)
89 include(HandleLLVMStdlib)
910 include(AddLLVMDefinitions)
1011 include(CheckCCompilerFlag)
1112 include(CheckCXXCompilerFlag)
1213
13 if(NOT LLVM_FORCE_USE_OLD_TOOLCHAIN)
14 if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
15 if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
16 message(FATAL_ERROR "Host GCC version must be at least 4.7!")
17 endif()
18 elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
19 if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.1)
20 message(FATAL_ERROR "Host Clang version must be at least 3.1!")
21 endif()
22
23 if (CMAKE_CXX_SIMULATE_ID MATCHES "MSVC")
24 if (CMAKE_CXX_SIMULATE_VERSION VERSION_LESS 18.0)
25 message(FATAL_ERROR "Host Clang must have at least -fms-compatibility-version=18.0")
26 endif()
27 set(CLANG_CL 1)
28 elseif(NOT LLVM_ENABLE_LIBCXX)
29 # Otherwise, test that we aren't using too old of a version of libstdc++
30 # with the Clang compiler. This is tricky as there is no real way to
31 # check the version of libstdc++ directly. Instead we test for a known
32 # bug in libstdc++4.6 that is fixed in libstdc++4.7.
33 set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
34 set(OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
35 set(CMAKE_REQUIRED_FLAGS "-std=c++0x")
36 check_cxx_source_compiles("
37 #include
38 std::atomic x(0.0f);
39 int main() { return (float)x; }"
40 LLVM_NO_OLD_LIBSTDCXX)
41 if(NOT LLVM_NO_OLD_LIBSTDCXX)
42 message(FATAL_ERROR "Host Clang must be able to find libstdc++4.7 or newer!")
43 endif()
44 set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
45 set(CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES})
46 endif()
47 elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
48 if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18.0)
49 message(FATAL_ERROR "Host Visual Studio must be at least 2013")
50 elseif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18.0.31101)
51 message(WARNING "Host Visual Studio should at least be 2013 Update 4 (MSVC 18.0.31101)"
52 " due to miscompiles from earlier versions")
53 endif()
54 endif()
55 endif()
5614
5715 if (CMAKE_LINKER MATCHES "lld-link.exe")
5816 # Pass /MANIFEST:NO so that CMake doesn't run mt.exe on our binaries. Adding