Skip to content

Commit f73a302

Browse files
authored
[flang-rt] Use correct flang-rt build for flang-rt unit tests on Windows (#152318)
Currrently flang-rt assumes that LLVM was always built with the dynamic MSVC runtime. This may not be the case, if the user has specified a different runtime with -DCMAKE_MSVC_RUNTIME_LIBRARY. Since this flag is implied by -DLLVM_ENABLE_RPMALLOC=On, which is used by the Windows release script, this is causing that script to fail. Fixes #151920
1 parent ceda56b commit f73a302

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

flang-rt/lib/runtime/CMakeLists.txt

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -251,19 +251,33 @@ else()
251251
add_win_flangrt_runtime(STATIC dynamic MultiThreadedDLL INSTALL_WITH_TOOLCHAIN)
252252
add_win_flangrt_runtime(STATIC dynamic_dbg MultiThreadedDebugDLL INSTALL_WITH_TOOLCHAIN)
253253

254-
# Unittests link against LLVMSupport which is using CMake's default runtime
255-
# library selection, which is either MultiThreadedDLL or MultiThreadedDebugDLL
256-
# depending on the configuration. They have to match or linking will fail.
254+
# Unittests link against LLVMSupport. If CMAKE_MSVC_RUNTIME_LIBRARY is set,
255+
# that will have been used for LLVMSupport so it must also be used here.
256+
# Otherwise this will use CMake's default runtime library selection, which
257+
# is either MultiThreadedDLL or MultiThreadedDebugDLL depending on the configuration.
258+
# They have to match or linking will fail.
257259
if (GENERATOR_IS_MULTI_CONFIG)
258260
# We cannot select an ALIAS library because it may be different
259261
# per configuration. Fallback to CMake's default.
260262
add_win_flangrt_runtime(STATIC unittest "" EXCLUDE_FROM_ALL)
261263
else ()
262-
string(TOLOWER ${CMAKE_BUILD_TYPE} build_type)
263-
if (build_type STREQUAL "debug")
264-
add_library(flang_rt.runtime.unittest ALIAS flang_rt.runtime.dynamic_dbg)
265-
else ()
266-
add_library(flang_rt.runtime.unittest ALIAS flang_rt.runtime.dynamic)
267-
endif ()
264+
# Check if CMAKE_MSVC_RUNTIME_LIBRARY was set.
265+
if (CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL "MultiThreaded")
266+
add_library(flang_rt.runtime.unittest ALIAS flang_rt.runtime.static)
267+
elseif (CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL "MultiThreadedDLL")
268+
add_library(flang_rt.runtime.unittest ALIAS flang_rt.runtime.dynamic)
269+
elseif (CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL "MultiThreadedDebug")
270+
add_library(flang_rt.runtime.unittest ALIAS flang_rt.runtime.static_dbg)
271+
elseif (CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL "MultiThreadedDebugDLL")
272+
add_library(flang_rt.runtime.unittest ALIAS flang_rt.runtime.dynamic_dbg)
273+
else()
274+
# Default based on the build type.
275+
string(TOLOWER ${CMAKE_BUILD_TYPE} build_type)
276+
if (build_type STREQUAL "debug")
277+
add_library(flang_rt.runtime.unittest ALIAS flang_rt.runtime.dynamic_dbg)
278+
else ()
279+
add_library(flang_rt.runtime.unittest ALIAS flang_rt.runtime.dynamic)
280+
endif ()
281+
endif()
268282
endif ()
269283
endif()

flang-rt/unittests/CMakeLists.txt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,6 @@ function(add_flangrt_unittest test_dirname)
9494
target_link_libraries(${test_dirname} PRIVATE ${ARG_LINK_LIBS})
9595
add_flangrt_unittest_offload_properties(${test_dirname})
9696
add_flangrt_dependent_libs(${test_dirname})
97-
98-
# Required because LLVMSupport is compiled with this option.
99-
# FIXME: According to CMake documentation, this is the default. Why is it
100-
# needed? LLVM's add_unittest doesn't set it either.
101-
set_target_properties(${test_dirname}
102-
PROPERTIES
103-
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL"
104-
)
10597
endfunction()
10698

10799
function(add_flangrt_nongtest_unittest test_name)

0 commit comments

Comments
 (0)