LLVMFlang: Update MSVC runtime library selection for LLVMFlang 18.0

LLVMFlang 18.0 adds MSVC runtime library selection flags and associated
Fortran runtime library variants.  Resolve the corresponding FIXME left
by commit 26bf32cdc6 (LLVMFlang: Add support for targeting MSVC ABI on
Windows, 2023-09-28, v3.28.0-rc1~10^2).

Issue: #24840
stage/master/nightly/2023/12/07
Brad King 2023-11-20 14:15:05 -05:00
parent 1c07758ca2
commit 48302b469e
3 changed files with 23 additions and 16 deletions

View File

@ -265,8 +265,8 @@ if("${CMAKE_Fortran_COMPILER_ID};${CMAKE_Fortran_SIMULATE_ID}" STREQUAL "LLVMFla
"${log}\n"
)
set(_CMAKE_Fortran_IMPLICIT_LINK_INFORMATION_DETERMINED_EARLY 1)
if("x${CMAKE_Fortran_COMPILER_ARCHITECTURE_ID}" STREQUAL "xARM64")
# FIXME(LLVMFlang): It does not add `-defaultlib:` fields to object
if("x${CMAKE_Fortran_COMPILER_ARCHITECTURE_ID}" STREQUAL "xARM64" AND CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 18.0)
# LLVMFlang < 18.0 does not add `-defaultlib:` fields to object
# files to specify link dependencies on its runtime libraries.
# For now, we add them ourselves.
list(APPEND CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES "clang_rt.builtins-aarch64.lib")

View File

@ -5,17 +5,22 @@ elseif("x${CMAKE_Fortran_SIMULATE_ID}" STREQUAL "xMSVC")
include(Platform/Windows-MSVC)
__windows_compiler_msvc(Fortran)
# FIXME(LLVMFlang): It does not provides MSVC runtime library selection flags.
# It should be given a flag like classic Flang's `-Xclang --dependent-lib=`, or a
# dedicated flag to select among multiple `Fortran*.lib` runtime library variants
# that each depend on a different MSVC runtime library. For now, LLVMFlang's
# `Fortran*.lib` runtime libraries hard-code use of msvcrt (MultiThreadedDLL),
# so we link to it ourselves.
set(_LLVMFlang_LINK_RUNTIME "-defaultlib:msvcrt")
set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreaded "")
set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL "")
set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebug "")
set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebugDLL "")
if(CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER_EQUAL 18.0)
set(_LLVMFlang_LINK_RUNTIME "")
set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreaded "-fms-runtime-lib=static")
set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL "-fms-runtime-lib=dll")
set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebug "-fms-runtime-lib=static_dbg")
set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebugDLL "-fms-runtime-lib=dll_dbg")
else()
# LLVMFlang < 18.0 does not have MSVC runtime library selection flags.
# The official distrubtion's `Fortran*.lib` runtime libraries hard-code
# use of msvcrt (MultiThreadedDLL), so we link to it ourselves.
set(_LLVMFlang_LINK_RUNTIME "-defaultlib:msvcrt")
set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreaded "")
set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL "")
set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebug "")
set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebugDLL "")
endif()
# LLVMFlang, like Clang, does not provide all debug information format flags.
# In order to provide easy integration with C and C++ projects that use the

View File

@ -21,14 +21,16 @@ foreach(t MultiThreaded SingleThreaded)
endforeach()
endforeach()
endforeach()
if(CMAKE_Fortran_COMPILER_ID STREQUAL "LLVMFlang")
# LLVMFlang does not actually define these, so inject them
if(CMAKE_Fortran_COMPILER_ID STREQUAL "LLVMFlang" AND CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 18.0)
# LLVMFlang < 18.0 does not define these, so inject them.
set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreaded "-D_MT")
set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL "-D_MT;-D_DLL")
set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebug "-D_MT;-D_DEBUG")
set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebugDLL "-D_MT;-D_DEBUG;-D_DLL")
endif()
string(APPEND CMAKE_Fortran_FLAGS " -w")
if(NOT CMAKE_Fortran_SIMULATE_ID STREQUAL "MSVC")
string(APPEND CMAKE_Fortran_FLAGS " -w")
endif()
function(verify_combinations threads lang src)
set(verify_tc_config_ Release)