|
| 1 | +# Find the path to compiler-rt builtins library for the current target and |
| 2 | +# and return it in `variable`. |
| 3 | +function(find_compiler_rt_library variable) |
| 4 | + set(target "${CMAKE_CXX_COMPILER_TARGET}") |
| 5 | + if(NOT CMAKE_CXX_COMPILER_TARGET AND LLVM_DEFAULT_TARGET_TRIPLE) |
| 6 | + set(target "${LLVM_DEFAULT_TARGET_TRIPLE}") |
| 7 | + |
| 8 | + if(NOT DEFINED COMPILER_RT_LIBRARY_builtins_${target} OR NOT ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") |
| 9 | + # If the cache variable is not defined, invoke Clang and then |
| 10 | + # set it with cache_compiler_rt_library. |
| 11 | + set(clang_command ${CMAKE_CXX_COMPILER} "${ARG_FLAGS}") |
| 12 | + if(target) |
| 13 | + list(APPEND clang_command "--target=${target}") |
| 14 | + endif() |
| 15 | + get_property(cxx_flags CACHE CMAKE_CXX_FLAGS PROPERTY VALUE) |
| 16 | + string(REPLACE " " ";" cxx_flags "${cxx_flags}") |
| 17 | + list(APPEND clang_command ${cxx_flags}) |
| 18 | + set(cmd_prefix "") |
| 19 | + if(MSVC) |
| 20 | + set(cmd_prefix "/clang:") |
| 21 | + endif() |
| 22 | + execute_process( |
| 23 | + COMMAND ${clang_command} "${cmd_prefix}--rtlib=compiler-rt" "${cmd_prefix}-print-libgcc-file-name" |
| 24 | + RESULT_VARIABLE had_error |
| 25 | + OUTPUT_VARIABLE library_file |
| 26 | + ) |
| 27 | + string(STRIP "${library_file}" library_file) |
| 28 | + file(TO_CMAKE_PATH "${library_file}" library_file) |
| 29 | + get_filename_component(basename ${library_file} NAME) |
| 30 | + if(EXISTS "${library_file}" AND (basename MATCHES ".*clang_rt\.([a-z0-9_\-]+)\.(a|lib)")) |
| 31 | + message(STATUS "Found compiler-rt library: ${basename}") |
| 32 | + set(COMPILER_RT_LIBRARY_builtins_${target} "${basename}" CACHE INTERNAL |
| 33 | + "compiler-rt library for ${target}") |
| 34 | + else() |
| 35 | + message(STATUS "Failed to find compiler-rt library for ${target}") |
| 36 | + set(COMPILER_RT_LIBRARY_builtins_${target} "NOTFOUND" CACHE INTERNAL |
| 37 | + "compiler-rt library for ${target}") |
| 38 | + endif() |
| 39 | + endif() |
| 40 | + |
| 41 | + if(NOT COMPILER_RT_LIBRARY_builtins_${target}) |
| 42 | + set(${variable} "NOTFOUND" PARENT_SCOPE) |
| 43 | + else() |
| 44 | + set(${variable} "${COMPILER_RT_LIBRARY_builtins_${target}}" PARENT_SCOPE) |
| 45 | + endif() |
| 46 | +endfunction() |
0 commit comments