-
Notifications
You must be signed in to change notification settings - Fork 333
/
Copy pathHandleCompilerRT.cmake
51 lines (47 loc) · 1.93 KB
/
HandleCompilerRT.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Find the path to compiler-rt builtins library for the target compiler
# and return it in `output_variable`.
function(find_compiler_rt_library variable)
set(clang_command ${CMAKE_CXX_COMPILER})
set(cmd_prefix "")
if(MSVC)
set(cmd_prefix "/clang:")
endif()
# If the C++ compiler is Clang, run it with -dumpmachine to find
# the target triple
set(target "")
if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
execute_process(
COMMAND "${clang_command}" ${cmd_prefix}-dumpmachine
OUTPUT_VARIABLE target
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
endif()
# If target is set and COMPILER_RT_LIBRARY_builtins_${target}
# cache variable is not defined, then set it by invoking Clang for the target triple.
if(NOT ${target} STREQUAL "" AND NOT DEFINED COMPILER_RT_LIBRARY_builtins_${target})
list(APPEND clang_command "${cmd_prefix}--target=${target}")
execute_process(
COMMAND ${clang_command} "${cmd_prefix}--rtlib=compiler-rt" "${cmd_prefix}-print-libgcc-file-name"
RESULT_VARIABLE had_error
OUTPUT_VARIABLE library_file
)
string(STRIP "${library_file}" library_file)
file(TO_CMAKE_PATH "${library_file}" library_file)
get_filename_component(basename ${library_file} NAME)
if(basename MATCHES ".*clang_rt\.([a-z0-9_\-]+)\.(a|lib)" AND EXISTS ${library_file})
message(STATUS "Found compiler-rt builtin library: ${basename}")
set(COMPILER_RT_LIBRARY_builtins_${target} "${basename}" CACHE INTERNAL
"compiler-rt library for ${target}")
else()
message(STATUS "Failed to find compiler-rt library for ${target}")
set(COMPILER_RT_LIBRARY_builtins_${target} "" CACHE INTERNAL
"compiler-rt library for ${target}")
endif()
endif()
if(DEFINED COMPILER_RT_LIBRARY_builtins_${target})
set(${variable} "${COMPILER_RT_LIBRARY_builtins_${target}}" PARENT_SCOPE)
else()
set(${variable} "" PARENT_SCOPE)
endif()
endfunction()