|
1 | 1 | # This file handles building LLVM runtime sub-projects.
|
2 | 2 | cmake_minimum_required(VERSION 3.13.4)
|
3 |
| -project(Runtimes C CXX ASM) |
| 3 | + |
| 4 | +# Add path for custom and the LLVM build's modules to the CMake module path. |
| 5 | +list(INSERT CMAKE_MODULE_PATH 0 |
| 6 | + "${CMAKE_CURRENT_SOURCE_DIR}/cmake" |
| 7 | + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" |
| 8 | + "${CMAKE_CURRENT_SOURCE_DIR}/../cmake" |
| 9 | + "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Modules" |
| 10 | + "${CMAKE_CURRENT_SOURCE_DIR}/../llvm/cmake" |
| 11 | + "${CMAKE_CURRENT_SOURCE_DIR}/../llvm/cmake/modules" |
| 12 | +) |
| 13 | + |
| 14 | +# We may have an incomplete toolchain - do language support tests without |
| 15 | +# linking. |
| 16 | +include(EnableLanguageNolink) |
| 17 | +project(Runtimes LANGUAGES NONE) |
| 18 | +llvm_enable_language_nolink(C CXX ASM) |
4 | 19 |
|
5 | 20 | set(LLVM_ALL_RUNTIMES "compiler-rt;libc;libcxx;libcxxabi;libunwind;openmp")
|
6 | 21 | set(LLVM_ENABLE_RUNTIMES "" CACHE STRING
|
@@ -28,14 +43,6 @@ endfunction()
|
28 | 43 | find_package(LLVM PATHS "${LLVM_BINARY_DIR}" NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
|
29 | 44 | find_package(Clang PATHS "${LLVM_BINARY_DIR}" NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
|
30 | 45 |
|
31 |
| -# Add path for custom and the LLVM build's modules to the CMake module path. |
32 |
| -list(INSERT CMAKE_MODULE_PATH 0 |
33 |
| - "${CMAKE_CURRENT_SOURCE_DIR}/cmake" |
34 |
| - "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" |
35 |
| - "${CMAKE_CURRENT_SOURCE_DIR}/../llvm/cmake" |
36 |
| - "${CMAKE_CURRENT_SOURCE_DIR}/../llvm/cmake/modules" |
37 |
| -) |
38 |
| - |
39 | 46 | set(LLVM_THIRD_PARTY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../third-party")
|
40 | 47 |
|
41 | 48 | function(get_compiler_rt_path path)
|
@@ -88,14 +95,29 @@ if(APPLE)
|
88 | 95 | endif()
|
89 | 96 |
|
90 | 97 | include(CheckLibraryExists)
|
| 98 | +include(CheckLinkerFlag) |
91 | 99 | include(CheckCCompilerFlag)
|
92 | 100 | include(CheckCXXCompilerFlag)
|
93 | 101 |
|
| 102 | + |
| 103 | +check_c_compiler_flag("" LLVM_RUNTIMES_LINKING_WORKS) |
| 104 | +if (NOT LLVM_RUNTIMES_LINKING_WORKS) |
| 105 | + # The compiler driver may be implicitly trying to link against libunwind, which |
| 106 | + # might not work if libunwind doesn't exist yet. Try to check if |
| 107 | + # --unwindlib=none is supported, and use that if possible. |
| 108 | + # Don't add this if not necessary to fix linking, as it can break using |
| 109 | + # e.g. ASAN/TSAN. |
| 110 | + llvm_check_linker_flag("--unwindlib=none" LLVM_RUNTIMES_SUPPORT_UNWINDLIB_NONE_FLAG) |
| 111 | + if (LLVM_RUNTIMES_SUPPORT_UNWINDLIB_NONE_FLAG) |
| 112 | + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} --unwindlib=none") |
| 113 | + endif() |
| 114 | +endif() |
| 115 | + |
94 | 116 | # Disable use of the installed C++ standard library when building runtimes.
|
95 | 117 | # Check for -nostdlib++ first; if there's no C++ standard library yet,
|
96 | 118 | # all check_cxx_compiler_flag commands will fail until we add -nostdlib++
|
97 | 119 | # (or -nodefaultlibs).
|
98 |
| -check_c_compiler_flag(-nostdlib++ LLVM_RUNTIMES_SUPPORT_NOSTDLIBXX_FLAG) |
| 120 | +llvm_check_linker_flag(-nostdlib++ LLVM_RUNTIMES_SUPPORT_NOSTDLIBXX_FLAG) |
99 | 121 | if (LLVM_RUNTIMES_SUPPORT_NOSTDLIBXX_FLAG)
|
100 | 122 | set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
|
101 | 123 | endif()
|
|
0 commit comments