[llvm-branch-commits] [clang] [flang] [lld] [llvm] [Flang] LLVM_ENABLE_RUNTIMES=flang-rt (PR #110217)
Petr Hosek via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Dec 11 22:10:32 PST 2024
================
@@ -0,0 +1,226 @@
+#===-- CMakeLists.txt ------------------------------------------------------===#
+#
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#
+#===------------------------------------------------------------------------===#
+#
+# Build instructions for the flang-rt library. This is file is intended to be
+# included using the LLVM_ENABLE_RUNTIMES mechanism.
+#
+#===------------------------------------------------------------------------===#
+
+set(LLVM_SUBPROJECT_TITLE "Fortran Runtime")
+set(FLANG_RT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
+set(FLANG_RT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
+set(FLANG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../flang")
+
+
+# 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 (CMAKE_VERSION VERSION_LESS "3.24")
+ cmake_path(GET CMAKE_Fortran_COMPILER STEM _Fortran_COMPILER_STEM)
+ if (_Fortran_COMPILER_STEM STREQUAL "flang-new" OR _Fortran_COMPILER_STEM STREQUAL "flang")
+ include(CMakeForceCompiler)
+ CMAKE_FORCE_Fortran_COMPILER("${CMAKE_Fortran_COMPILER}" "LLVMFlang")
+
+ set(CMAKE_Fortran_COMPILER_ID "LLVMFlang")
+ set(CMAKE_Fortran_COMPILER_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}")
+
+ set(CMAKE_Fortran_SUBMODULE_SEP "-")
+ set(CMAKE_Fortran_SUBMODULE_EXT ".mod")
+
+ set(CMAKE_Fortran_PREPROCESS_SOURCE
+ "<CMAKE_Fortran_COMPILER> -cpp <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
+
+ set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-ffixed-form")
+ set(CMAKE_Fortran_FORMAT_FREE_FLAG "-ffree-form")
+
+ set(CMAKE_Fortran_MODDIR_FLAG "-module-dir")
+
+ set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON "-cpp")
+ set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_OFF "-nocpp")
+ set(CMAKE_Fortran_POSTPROCESS_FLAG "-ffixed-line-length-72")
+
+ set(CMAKE_Fortran_COMPILE_OPTIONS_TARGET "--target=")
+
+ set(CMAKE_Fortran_LINKER_WRAPPER_FLAG "-Wl,")
+ set(CMAKE_Fortran_LINKER_WRAPPER_FLAG_SEP ",")
+ endif ()
+endif ()
+enable_language(Fortran)
+
+
+list(APPEND CMAKE_MODULE_PATH
+ "${FLANG_RT_SOURCE_DIR}/cmake/modules"
+ "${FLANG_SOURCE_DIR}/cmake/modules"
+ )
+include(AddFlangRT)
+include(FlangCommon)
+
+
+############################
+# Build Mode Introspection #
+############################
+
+# Setting these variables from an LLVM build is sufficient that flang-rt can
+# construct the output paths, so it can behave as if it was in-tree here.
+set(LLVM_TREE_AVAILABLE OFF)
+if (LLVM_LIBRARY_OUTPUT_INTDIR AND LLVM_RUNTIME_OUTPUT_INTDIR AND PACKAGE_VERSION)
+ # This is a bootstap build
+ set(LLVM_TREE_AVAILABLE ON)
+endif()
+
+# Path to LLVM development tools (FileCheck, llvm-lit, not, ...)
+set(LLVM_TOOLS_DIR "${LLVM_BINARY_DIR}/bin")
+
+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.
+ #
+ # 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(FLANG_RT_BUILD_LIB_DIR PREFIX "${LLVM_LIBRARY_OUTPUT_INTDIR}/.." SUBDIR "lib${LLVM_LIBDIR_SUFFIX}")
+ get_clang_resource_dir(FLANG_RT_INSTALL_LIB_DIR SUBDIR "lib${LLVM_LIBDIR_SUFFIX}") # No prefix, CMake's install command finds the install prefix itself
+else ()
+ # In a runtimes build never write into LLVM's build dir. It might be reused
+ # for mutliple Flang-RT builds (e.g. Debug/Release). Instead create our own
+ # library directory.
+ #
+ # TODO: Support multi-config generators
+ set(FLANG_RT_BUILD_LIB_DIR "${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}")
+ set(FLANG_RT_INSTALL_LIB_DIR "lib${LLVM_LIBDIR_SUFFIX}")
+endif ()
+
+if (DEFINED WIN32)
+ set(FLANG_RT_BUILD_LIB_DIR "${FLANG_RT_BUILD_LIB_DIR}/windows")
+ set(FLANG_RT_INSTALL_LIB_DIR "${FLANG_RT_INSTALL_LIB_DIR}/windows")
----------------
petrhosek wrote:
Is there a reason for not using target triple on Windows?
https://github.com/llvm/llvm-project/pull/110217
More information about the llvm-branch-commits
mailing list