@@ -60,6 +60,27 @@ function(add_flangrt_unittest_offload_properties target)
60
60
endif ()
61
61
endfunction ()
62
62
63
+ # flang-rt on Windows requires compiler-rt for some symbols. For binaries built
64
+ # with flang this dependency is added by the flang driver, but since the unit
65
+ # tests are built with clang we need to add the dependency manually.
66
+ function (add_flangrt_dependent_libs target )
67
+ if (MSVC AND CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
68
+ if (FLANG_RT_BUILTINS_LIBRARY )
69
+ target_compile_options (${target} PRIVATE "$<$<COMPILE_LANGUAGE:CXX,C>:-Xclang>" "$<$<COMPILE_LANGUAGE:CXX,C>:--dependent-lib=${FLANG_RT_BUILTINS_LIBRARY} >" )
70
+ endif ()
71
+ endif ()
72
+ if (MSVC AND CMAKE_Fortran_COMPILER_ID STREQUAL "LLVMFlang" )
73
+ if (FLANG_RT_BUILTINS_LIBRARY )
74
+ target_compile_options (${target} PRIVATE "$<$<COMPILE_LANGUAGE:Fortran>:-Xflang>" "$<$<COMPILE_LANGUAGE:Fortran>:--dependent-lib=${FLANG_RT_BUILTINS_LIBRARY} >" )
75
+ else ()
76
+ message (WARNING "Did not find libclang_rt.builtins.lib.
77
+ LLVM may emit builtins that are not implemented in msvcrt/ucrt and
78
+ instead falls back to builtins from Compiler-RT. Linking with ${tgtname}
79
+ may result in a linker error." )
80
+ endif ()
81
+ endif ()
82
+ endfunction ()
83
+
63
84
64
85
function (add_flangrt_unittest test_dirname )
65
86
cmake_parse_arguments (ARG
@@ -72,6 +93,7 @@ function(add_flangrt_unittest test_dirname)
72
93
73
94
target_link_libraries (${test_dirname} PRIVATE ${ARG_LINK_LIBS} )
74
95
add_flangrt_unittest_offload_properties (${test_dirname} )
96
+ add_flangrt_dependent_libs (${test_dirname} )
75
97
76
98
# Required because LLVMSupport is compiled with this option.
77
99
# FIXME: According to CMake documentation, this is the default. Why is it
@@ -99,6 +121,7 @@ function(add_flangrt_nongtest_unittest test_name)
99
121
set_target_properties (${test_name}${suffix} PROPERTIES FOLDER "Flang-RT/Tests/Unit" )
100
122
101
123
target_link_libraries (${test_name}${suffix} PRIVATE NonGTestTesting ${ARG_LINK_LIBS} )
124
+ add_flangrt_dependent_libs (${test_name}${suffix} )
102
125
103
126
if (NOT ARG_SLOW_TEST )
104
127
add_dependencies (FlangRTUnitTests ${test_name}${suffix} )
0 commit comments