Skip to content

[flang-rt] Use correct flang-rt build for flang-rt unit tests on Windows #152318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions flang-rt/lib/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
8 changes: 0 additions & 8 deletions flang-rt/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading