|
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 | function(get_compiler_rt_path path)
|
40 | 47 | foreach(entry ${runtimes})
|
41 | 48 | get_filename_component(projName ${entry} NAME)
|
@@ -82,14 +89,29 @@ set(LLVM_CMAKE_DIR ${LLVM_MAIN_SRC_DIR}/cmake/modules)
|
82 | 89 | set(LLVM_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../llvm)
|
83 | 90 |
|
84 | 91 | include(CheckLibraryExists)
|
| 92 | +include(CheckLinkerFlag) |
85 | 93 | include(CheckCCompilerFlag)
|
86 | 94 | include(CheckCXXCompilerFlag)
|
87 | 95 |
|
| 96 | + |
| 97 | +check_c_compiler_flag("" LLVM_RUNTIMES_LINKING_WORKS) |
| 98 | +if (NOT LLVM_RUNTIMES_LINKING_WORKS) |
| 99 | + # The compiler driver may be implicitly trying to link against libunwind, which |
| 100 | + # might not work if libunwind doesn't exist yet. Try to check if |
| 101 | + # --unwindlib=none is supported, and use that if possible. |
| 102 | + # Don't add this if not necessary to fix linking, as it can break using |
| 103 | + # e.g. ASAN/TSAN. |
| 104 | + llvm_check_linker_flag("--unwindlib=none" LLVM_RUNTIMES_SUPPORT_UNWINDLIB_NONE_FLAG) |
| 105 | + if (LLVM_RUNTIMES_SUPPORT_UNWINDLIB_NONE_FLAG) |
| 106 | + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} --unwindlib=none") |
| 107 | + endif() |
| 108 | +endif() |
| 109 | + |
88 | 110 | # Disable use of the installed C++ standard library when building runtimes.
|
89 | 111 | # Check for -nostdlib++ first; if there's no C++ standard library yet,
|
90 | 112 | # all check_cxx_compiler_flag commands will fail until we add -nostdlib++
|
91 | 113 | # (or -nodefaultlibs).
|
92 |
| -check_c_compiler_flag(-nostdlib++ LLVM_RUNTIMES_SUPPORT_NOSTDLIBXX_FLAG) |
| 114 | +llvm_check_linker_flag(-nostdlib++ LLVM_RUNTIMES_SUPPORT_NOSTDLIBXX_FLAG) |
93 | 115 | if (LLVM_RUNTIMES_SUPPORT_NOSTDLIBXX_FLAG)
|
94 | 116 | set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
|
95 | 117 | endif()
|
|
0 commit comments