[llvm] [flang-rt][cmake] Fix Windows build with CMAKE_Fortran_SIMULATE_ID (PR #202981)

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 10 07:05:54 PDT 2026


https://github.com/Meinersbur updated https://github.com/llvm/llvm-project/pull/202981

>From 9417caffbfd687f79548dd4f61dcb1bcbd96b33c Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Wed, 10 Jun 2026 15:36:25 +0200
Subject: [PATCH 1/2] flangrt_simulate-id

---
 runtimes/cmake/config-Fortran.cmake | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/runtimes/cmake/config-Fortran.cmake b/runtimes/cmake/config-Fortran.cmake
index c4e65656ccb6a..3dd81ce595ab7 100644
--- a/runtimes/cmake/config-Fortran.cmake
+++ b/runtimes/cmake/config-Fortran.cmake
@@ -91,11 +91,21 @@ if (CMAKE_Fortran_COMPILER)
     # Force the compiler ID so CMake does not try to run the compiler for
     # identification. In a bootstrapping build the Flang binary may not be
     # built yet at configure time (only CMAKE_Fortran_COMPILER_WORKS is set).
+    # FIXME: flang has has not equivalent to clang-cl, so
+    # CMAKE_Fortran_SIMULATE_ID=GNU should be the only correct value. CMake may
+    # imply that supports different toolchains for each language but in
+    # practice is doesn't. In particular, the last enabled
+    # language will overwrite global variables such as CMAKE_LINK_LIBRARY_FLAG
+    # depending on CMAKE_<lang>_SIMULATE_ID, i.e. they cannot be different.
+    # Fortunately, "MSVC" still works for Flang.
     set(CMAKE_Fortran_COMPILER_ID "LLVMFlang")
     set(CMAKE_Fortran_COMPILER_ID_RUN TRUE)
     set(CMAKE_Fortran_COMPILER_FORCED TRUE)
-    set(CMAKE_Fortran_COMPILER_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}")
-    set(CMAKE_Fortran_SIMULATE_ID "GNU")
+    set(CMAKE_Fortran_COMPILER_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}")
+    set(CMAKE_Fortran_SIMULATE_ID "${CMAKE_CXX_SIMULATE_ID}")
+    set(CMAKE_Fortran_SIMULATE_VERSION "${CMAKE_CXX_SIMULATE_VERSION}")
+    set(CMAKE_Fortran_COMPILER_SUPPORTS_F90 1)
+    set(CMAKE_Fortran_PLATFORM_ID "${CMAKE_CXX_PLATFORM_ID}")
 
     # CMake 3.24 is the first version of CMake that directly recognizes Flang.
     # LLVM's requirement is only CMake 3.20, teach CMake 3.20-3.23 how to use Flang, if used.

>From cecfab22387bf91273ac6dec79782bf60c8b8320 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Wed, 10 Jun 2026 16:05:18 +0200
Subject: [PATCH 2/2] Fix typo

---
 runtimes/cmake/config-Fortran.cmake | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/runtimes/cmake/config-Fortran.cmake b/runtimes/cmake/config-Fortran.cmake
index 3dd81ce595ab7..e9ac8e7b7eac3 100644
--- a/runtimes/cmake/config-Fortran.cmake
+++ b/runtimes/cmake/config-Fortran.cmake
@@ -91,13 +91,12 @@ if (CMAKE_Fortran_COMPILER)
     # Force the compiler ID so CMake does not try to run the compiler for
     # identification. In a bootstrapping build the Flang binary may not be
     # built yet at configure time (only CMAKE_Fortran_COMPILER_WORKS is set).
-    # FIXME: flang has has not equivalent to clang-cl, so
+    # FIXME: flang has no equivalent to clang-cl, so
     # CMAKE_Fortran_SIMULATE_ID=GNU should be the only correct value. CMake may
     # imply that supports different toolchains for each language but in
     # practice is doesn't. In particular, the last enabled
     # language will overwrite global variables such as CMAKE_LINK_LIBRARY_FLAG
     # depending on CMAKE_<lang>_SIMULATE_ID, i.e. they cannot be different.
-    # Fortunately, "MSVC" still works for Flang.
     set(CMAKE_Fortran_COMPILER_ID "LLVMFlang")
     set(CMAKE_Fortran_COMPILER_ID_RUN TRUE)
     set(CMAKE_Fortran_COMPILER_FORCED TRUE)



More information about the llvm-commits mailing list