summaryrefslogtreecommitdiffstats
path: root/Modules/Platform/Windows-LLVMFlang-Fortran.cmake
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-09-28 23:36:56 (GMT)
committerBrad King <brad.king@kitware.com>2023-10-03 13:15:24 (GMT)
commit26bf32cdc67271547ca0b0d38872f8f23a90d191 (patch)
treecb7fff6bad7898d9ae422078394893d35136db25 /Modules/Platform/Windows-LLVMFlang-Fortran.cmake
parente9af7b968756e72553296ecdcde6f36606a0babf (diff)
downloadCMake-26bf32cdc67271547ca0b0d38872f8f23a90d191.zip
CMake-26bf32cdc67271547ca0b0d38872f8f23a90d191.tar.gz
CMake-26bf32cdc67271547ca0b0d38872f8f23a90d191.tar.bz2
LLVMFlang: Add support for targeting MSVC ABI on Windows
The compiler does not yet support everything needed to integrate well with the MSVC ABI, in particular for runtime library selection and debug format selection. Document them in FIXME comments and leave this support undocumented by CMake for now. Fixes: #24840 Inspired-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Diffstat (limited to 'Modules/Platform/Windows-LLVMFlang-Fortran.cmake')
-rw-r--r--Modules/Platform/Windows-LLVMFlang-Fortran.cmake61
1 files changed, 58 insertions, 3 deletions
diff --git a/Modules/Platform/Windows-LLVMFlang-Fortran.cmake b/Modules/Platform/Windows-LLVMFlang-Fortran.cmake
index 64dc0da..3e22a6e 100644
--- a/Modules/Platform/Windows-LLVMFlang-Fortran.cmake
+++ b/Modules/Platform/Windows-LLVMFlang-Fortran.cmake
@@ -1,3 +1,58 @@
-include(Platform/Windows-GNU)
-__windows_compiler_gnu(Fortran)
-# TODO: MSVC ABI Support
+if("x${CMAKE_Fortran_SIMULATE_ID}" STREQUAL "xGNU")
+ include(Platform/Windows-GNU)
+ __windows_compiler_gnu(Fortran)
+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 "")
+
+ # FIXME(LLVMFlang): It does not provide all debug information format flags or predefines.
+ # It should be given a flag to enable Embedded debug information like MSVC -Z7.
+ #set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_DEBUG_INFORMATION_FORMAT_Embedded) # not supported by LLVMFlang
+ #set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_DEBUG_INFORMATION_FORMAT_EditAndContinue) # not supported by LLVMFlang
+ set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_DEBUG_INFORMATION_FORMAT_ProgramDatabase "-g")
+
+ set(CMAKE_Fortran_COMPILE_OBJECT "<CMAKE_Fortran_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>")
+
+ if(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT_DEFAULT)
+ set(_g "")
+ else()
+ set(_g " -g")
+ endif()
+ string(APPEND CMAKE_Fortran_FLAGS_DEBUG_INIT "${_g}")
+ string(APPEND CMAKE_Fortran_FLAGS_RELEASE_INIT "")
+ string(APPEND CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT "${_g}")
+ string(APPEND CMAKE_Fortran_FLAGS_MINSIZEREL_INIT "")
+ unset(_g)
+
+ # We link with lld-link.exe instead of the compiler driver, so explicitly
+ # pass implicit link information previously detected from the compiler.
+ set(_LLVMFlang_LINK_DIRS "${CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES}")
+ list(TRANSFORM _LLVMFlang_LINK_DIRS PREPEND "-libpath:\"")
+ list(TRANSFORM _LLVMFlang_LINK_DIRS APPEND "\"")
+ string(JOIN " " _LLVMFlang_LINK_DIRS ${_LLVMFlang_LINK_DIRS})
+ string(JOIN " " _LLVMFlang_LINK_LIBS ${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES})
+ foreach(v IN ITEMS
+ CMAKE_Fortran_LINK_EXECUTABLE
+ CMAKE_Fortran_CREATE_SHARED_LIBRARY
+ CMAKE_Fortran_CREATE_SHARED_MODULE
+ )
+ string(APPEND "${v}" " ${_LLVMFlang_LINK_DIRS} ${_LLVMFlang_LINK_LIBS} ${_LLVMFlang_LINK_RUNTIME}")
+ endforeach()
+ unset(_LLVMFlang_LINK_DIRS)
+ unset(_LLVMFlang_LINK_LIBS)
+ unset(_LLVMFlang_LINK_RUNTIME)
+else()
+ message(FATAL_ERROR "LLVMFlang target ABI unrecognized: ${CMAKE_Fortran_SIMULATE_ID}")
+endif()