[llvm] [runtimes][CMake] Move Fortran support code from flang-rt (PR #171610)
Petr Hosek via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 13 09:24:06 PST 2026
================
@@ -236,6 +414,100 @@ if(CMAKE_C_COMPILER_ID MATCHES "Clang")
endif()
endif()
+# Determine output and install paths based on LLVM_TARGET_TRIPLE
+if(LLVM_TREE_AVAILABLE)
+ # In a bootstrap build emit the libraries into a default search path in the
+ # build directory of the just-built compiler. This allows using the
+ # just-built compiler without specifying paths to runtime libraries.
+ # LLVM_LIBRARY_OUTPUT_INTDIR/LLVM_RUNTIME_OUTPUT_INTDIR is used by
+ # AddLLVM.cmake as artifact output locations.
+ set(LLVM_LIBRARY_OUTPUT_INTDIR ${LLVM_LIBRARY_DIR})
+ set(LLVM_RUNTIME_OUTPUT_INTDIR ${LLVM_TOOLS_BINARY_DIR})
+
+ # Despite Clang in the name, get_clang_resource_dir does not depend on Clang
+ # being added to the build. Flang uses the same resource dir as Clang.
+ include(GetClangResourceDir)
+ get_clang_resource_dir(RUNTIMES_OUTPUT_RESOURCE_DIR PREFIX "${LLVM_LIBRARY_OUTPUT_INTDIR}/..")
+ get_clang_resource_dir(RUNTIMES_INSTALL_RESOURCE_PATH_DEFAULT)
+else()
+ # In a default runtimes build, do not write into LLVM_BINARY_DIR. It may be
+ # read-only and/or shared by multiple runtimes with different build
+ # configurations (e.g. Debug/Release). Use the runtime's own lib dir like any
+ # non-toolchain library. Use own build directory for artifact output.
+ set(LLVM_LIBRARY_OUTPUT_INTDIR "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}")
+ set(LLVM_RUNTIME_OUTPUT_INTDIR "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin")
+
+ # For the install prefix, still use the resource dir assuming the compilers
+ # looking for it (Clang, Flang) will be installed there using the same prefix.
+ # This is to not have a difference between bootstrapping and default runtimes
+ # builds.
+ set(RUNTIMES_OUTPUT_RESOURCE_DIR "${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/clang/${LLVM_VERSION_MAJOR}")
+ set(RUNTIMES_INSTALL_RESOURCE_PATH_DEFAULT "lib${LLVM_LIBDIR_SUFFIX}/clang/${LLVM_VERSION_MAJOR}")
+endif()
+
+# Determine build and install paths. The ouptut paths are absolute, but the
+# install dirs are relative to CMAKE_INSTALL_PREFIX to be resolved by CMake.
+get_toolchain_library_subdir(toolchain_lib_subdir)
+extend_path(RUNTIMES_OUTPUT_RESOURCE_LIB_DIR "${RUNTIMES_OUTPUT_RESOURCE_DIR}" "${toolchain_lib_subdir}")
+
+set(RUNTIMES_INSTALL_RESOURCE_PATH "${RUNTIMES_INSTALL_RESOURCE_PATH_DEFAULT}" CACHE PATH "Path to install headers, runtime libraries, and Fortran modules to (default: Clang resource dir)")
+extend_path(RUNTIMES_INSTALL_RESOURCE_LIB_PATH "${RUNTIMES_INSTALL_RESOURCE_PATH}" "${toolchain_lib_subdir}")
----------------
petrhosek wrote:
We've been reserving `RUNTIMES_` names for variables used across all runtimes so I'd like to avoid introducing such variables that are only used by Flang. With that being said, I believe these variables could be helpful in other runtimes. Would it be possible to extract this change into its own PR so we can try to use these in other runtimes as a more general cleanup/refactoring?
https://github.com/llvm/llvm-project/pull/171610
More information about the llvm-commits
mailing list