https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/152493
Backport f73a302 Requested by: @DavidTruby >From 332baaaee9815118a44982c1efd1dc14dc16ae6c Mon Sep 17 00:00:00 2001 From: David Truby <david.tr...@arm.com> Date: Thu, 7 Aug 2025 13:09:35 +0100 Subject: [PATCH] [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 (cherry picked from commit f73a3028c2d46928280d69d9e953ff79d2eb0fbb) --- flang-rt/lib/runtime/CMakeLists.txt | 32 +++++++++++++++++++++-------- flang-rt/unittests/CMakeLists.txt | 8 -------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/flang-rt/lib/runtime/CMakeLists.txt b/flang-rt/lib/runtime/CMakeLists.txt index 332c0872e065f..dc2db1d9902cb 100644 --- a/flang-rt/lib/runtime/CMakeLists.txt +++ b/flang-rt/lib/runtime/CMakeLists.txt @@ -251,19 +251,33 @@ else() add_win_flangrt_runtime(STATIC dynamic MultiThreadedDLL INSTALL_WITH_TOOLCHAIN) add_win_flangrt_runtime(STATIC dynamic_dbg MultiThreadedDebugDLL INSTALL_WITH_TOOLCHAIN) - # Unittests link against LLVMSupport which is using CMake's default runtime - # library selection, which is either MultiThreadedDLL or MultiThreadedDebugDLL - # depending on the configuration. They have to match or linking will fail. + # Unittests link against LLVMSupport. If CMAKE_MSVC_RUNTIME_LIBRARY is set, + # that will have been used for LLVMSupport so it must also be used here. + # Otherwise this will use CMake's default runtime library selection, which + # is either MultiThreadedDLL or MultiThreadedDebugDLL depending on the configuration. + # They have to match or linking will fail. if (GENERATOR_IS_MULTI_CONFIG) # We cannot select an ALIAS library because it may be different # per configuration. Fallback to CMake's default. add_win_flangrt_runtime(STATIC unittest "" EXCLUDE_FROM_ALL) else () - string(TOLOWER ${CMAKE_BUILD_TYPE} build_type) - if (build_type STREQUAL "debug") - add_library(flang_rt.runtime.unittest ALIAS flang_rt.runtime.dynamic_dbg) - else () - add_library(flang_rt.runtime.unittest ALIAS flang_rt.runtime.dynamic) - endif () + # Check if CMAKE_MSVC_RUNTIME_LIBRARY was set. + if (CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL "MultiThreaded") + add_library(flang_rt.runtime.unittest ALIAS flang_rt.runtime.static) + elseif (CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL "MultiThreadedDLL") + add_library(flang_rt.runtime.unittest ALIAS flang_rt.runtime.dynamic) + elseif (CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL "MultiThreadedDebug") + add_library(flang_rt.runtime.unittest ALIAS flang_rt.runtime.static_dbg) + elseif (CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL "MultiThreadedDebugDLL") + add_library(flang_rt.runtime.unittest ALIAS flang_rt.runtime.dynamic_dbg) + else() + # Default based on the build type. + string(TOLOWER ${CMAKE_BUILD_TYPE} build_type) + if (build_type STREQUAL "debug") + add_library(flang_rt.runtime.unittest ALIAS flang_rt.runtime.dynamic_dbg) + else () + add_library(flang_rt.runtime.unittest ALIAS flang_rt.runtime.dynamic) + endif () + endif() endif () endif() diff --git a/flang-rt/unittests/CMakeLists.txt b/flang-rt/unittests/CMakeLists.txt index 831bc8a4c2906..fd63ad11dcf43 100644 --- a/flang-rt/unittests/CMakeLists.txt +++ b/flang-rt/unittests/CMakeLists.txt @@ -94,14 +94,6 @@ function(add_flangrt_unittest test_dirname) target_link_libraries(${test_dirname} PRIVATE ${ARG_LINK_LIBS}) add_flangrt_unittest_offload_properties(${test_dirname}) add_flangrt_dependent_libs(${test_dirname}) - - # Required because LLVMSupport is compiled with this option. - # FIXME: According to CMake documentation, this is the default. Why is it - # needed? LLVM's add_unittest doesn't set it either. - set_target_properties(${test_dirname} - PROPERTIES - MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL" - ) endfunction() function(add_flangrt_nongtest_unittest test_name) _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits