Skip to content

Commit 1c4054c

Browse files
authored
Add find compiler-rt libs cmake module for windows (#52)
* Add find compiler-rt libs cmake module for windows This patch adds find compiler-rt libs function imported from llvm-project/cmake/modules to testsuite repository. Some tests require to link compiler-rt builtins library on windows and this function helps locate the library path from install dir.
1 parent c39b1f7 commit 1c4054c

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
241241
endif()
242242
endif()
243243

244+
include(HandleCompilerRT)
245+
244246
include(TestSuite)
245247
include(SingleMultiSource)
246248
# Needs by External/sollve_vv.

cmake/modules/HandleCompilerRT.cmake

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

0 commit comments

Comments
 (0)