Skip to content

Commit 90078f3

Browse files
committed
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 77418e0 commit 90078f3

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
237237
endif()
238238
endif()
239239

240+
include(HandleCompilerRT)
241+
240242
include(TestSuite)
241243
include(SingleMultiSource)
242244
# Needs by External/sollve_vv.

cmake/modules/HandleCompilerRT.cmake

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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

Comments
 (0)