[llvm] [runtimes][CMake] Move Fortran support code from flang-rt (PR #171610)

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 19 08:06:20 PST 2026


================
@@ -85,6 +85,195 @@ include(CheckLibraryExists)
 include(LLVMCheckCompilerLinkerFlag)
 include(CheckCCompilerFlag)
 include(CheckCXXCompilerFlag)
+include(GetToolchainDirs)
+include(ExtendPath)
+
+# Check whether the Fortran compiler already access to builtin modules. Sets
+# HAVE_FORTRAN_INTRINSIC_MODS when returning.
+#
+# This must be wrapped in a function because
+# cmake_push_check_state/cmake_pop_check_state is insufficient to isolate
+# a compiler introspection environment, see
+# https://gitlab.kitware.com/cmake/cmake/-/issues/27419
+function (check_fortran_builtins_available)
+  if (CMAKE_Fortran_COMPILER_FORCED AND CMAKE_Fortran_COMPILER_ID STREQUAL "LLVMFlang")
+    # CMake's try_compile does not take a user-defined
+    # CMAKE_Fortran_PREPROCESS_SOURCE into account. Instead of test-compiling,
+    # ask Flang directly for the builtin module files.
----------------
Meinersbur wrote:

At AMD we currently are using CMake 3.22 across our infrastructure, i.e. it was easier to add this workaround than trying to bump the CMake version (RFC, ...).

If we bump CMake, we should bumpt to at least [CMake 3.28](https://github.com/llvm/llvm-project/blob/users/meinersbur/runtimes_flangrt-common/runtimes/cmake/config-runtimes-Fortran.cmake#L100-L102)

Will add a comment this is a workaround for older CMake versions.

https://github.com/llvm/llvm-project/pull/171610


More information about the llvm-commits mailing list