[Runtimes] Introduce variables containing resource dir paths (#177953)

Introduce common infrastructure for runtimes that determines compiler
resource path locations. These variables introduced are:

 * RUNTIMES_OUTPUT_RESOURCE_DIR
 * RUNTIMES_INSTALL_RESOURCE_PATH
 
That contain the location for the compiler resource path (typically
`lib/clang/<version>`) in the build tree and the install tree (the
latter relative to CMAKE_INSTALL_PREFIX).

Additionally, define

 * RUNTIMES_OUTPUT_RESOURCE_LIB_DIR
 * RUNTIMES_INSTALL_RESOURCE_LIB_PATH

as for the location of clang/flang version-locked libraries (typically
`lib${LLVM_LIBDIR_SUFFIX}/<targer-triple>`, but also depends on `APPLE`
and `LLVM_ENABLE_PER_TARGET_RUNTIME_DIR`). This code is moved from
flang-rt and initially becomes its only user.

Refactored out of #171610 as requested
[here](https://github.com/llvm/llvm-project/pull/171610#discussion_r2687382481).

Extracted `get_runtimes_target_libdir_common` from compiler-rt as
requested
[here](https://github.com/llvm/llvm-project/pull/171610#discussion_r2689565634).
 
Added TODO comments to all runtimes as requested
[here](https://github.com/llvm/llvm-project/pull/171610#issuecomment-3789598635).
This commit is contained in:
Michael Kruse
2026-04-02 12:32:14 +02:00
committed by GitHub
parent 57ee29a2a1
commit afb80bddf1
16 changed files with 111 additions and 148 deletions

View File

@@ -1,36 +1,27 @@
#===-- cmake/modules/GetToolchainDirs.cmake --------------------------------===#
#
# 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
#
#===------------------------------------------------------------------------===#
# Determine the subdirectory relative to Clang's resource dir/sysroot where to
# install target-specific libraries, to be found by Clang/Flang driver. This was
# adapted from Compiler-RT's mechanism to find the path for
# libclang_rt.builtins.a.
# Determine the subdirectory relative to Clang's resource dir/installation
# prefix where to install target-specific libraries, to be found by the
# Clang/Flang driver. This was adapted from Compiler-RT's mechanism to find the
# path for libclang_rt.builtins.a.
#
# Compiler-RT has two mechanisms for the path (simplified):
#
# * LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=0: lib/${oslibname}/libclang_rt.builtins-${arch}.a
# * LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=1: lib/${triple}/libclang_rt.builtins.a
# * LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF: lib/${oslibname}/libclang_rt.builtins-${arch}.a
# * LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON : lib/${triple}/libclang_rt.builtins.a
#
# LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON is the newer scheme, but the old one is
# currently still used for some platforms such as Windows. Clang looks for which
# of the files exist before passing the path to the linker. Hence, the
# directories have to match what Clang is looking for, which is done in
# ToolChain::getArchSpecificLibPaths(..), ToolChain::getRuntimePath(),
# currently still used by default for some platforms such as Windows. Clang
# looks for which of the files exist before passing the path to the linker.
# Hence, the directories have to match what Clang is looking for, which is done
# in ToolChain::getArchSpecificLibPaths(..), ToolChain::getRuntimePath(),
# ToolChain::getCompilerRTPath(), and ToolChain::getCompilerRT(..), not entirely
# consistent between these functions, Compiler-RT's CMake code, and overrides
# in different toolchains.
# consistent between these functions, overrides in different toolchains, and
# Compiler-RT's CMake code.
#
# For Fortran, Flang always assumes the library name libflang_rt.a without
# architecture suffix. Hence, we always use the second scheme even as if
# LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON, even if it actually set to OFF. It as
# added unconditionally to the library search path by
# ToolChain::getArchSpecificLibPaths(...).
# For simplicity, we always use the second scheme even as if
# LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON, even if it actually set to OFF.
# The driver's lookup does not take the build-time
# LLVM_ENABLE_PER_TARGET_RUNTIME_DIR setting into account anyway
# and will always find its files using either scheme.
function (get_toolchain_library_subdir outvar)
set(outval "lib")
@@ -39,14 +30,25 @@ function (get_toolchain_library_subdir outvar)
get_toolchain_os_dirname(os_dirname)
set(outval "${outval}/${os_dirname}")
else ()
get_toolchain_arch_dirname(arch_dirname)
set(outval "${outval}/${arch_dirname}")
get_toolchain_target_dirname(target_dirname)
set(outval "${outval}/${target_dirname}")
endif ()
set(${outvar} "${outval}" PARENT_SCOPE)
endfunction ()
# Corresponds to Flang's ToolChain::getDefaultIntrinsicModuleDir().
function (get_toolchain_fortran_module_subdir outvar)
set(outval "finclude/flang")
get_toolchain_target_dirname(target_dirname)
set(outval "${outval}/${target_dirname}")
set(${outvar} "${outval}" PARENT_SCOPE)
endfunction ()
# Corresponds to Clang's ToolChain::getOSLibName(). Adapted from Compiler-RT.
function (get_toolchain_os_dirname outvar)
if (ANDROID)
@@ -60,22 +62,17 @@ function (get_toolchain_os_dirname outvar)
endfunction ()
# Corresponds to Clang's ToolChain::getRuntimePath(). Adapted from Compiler-RT.
function (get_toolchain_arch_dirname outvar)
string(FIND ${LLVM_TARGET_TRIPLE} "-" dash_index)
string(SUBSTRING ${LLVM_TARGET_TRIPLE} ${dash_index} -1 triple_suffix)
string(SUBSTRING ${LLVM_TARGET_TRIPLE} 0 ${dash_index} triple_cpu)
set(arch "${triple_cpu}")
if("${arch}" MATCHES "^i.86$")
# Android uses i686, but that's remapped at a later stage.
set(arch "i386")
endif()
if(ANDROID AND ${arch} STREQUAL "i386")
# Internal function extracted from compiler-rt. Use get_toolchain_target_dirname
# instead for new code.
function(get_runtimes_target_libdir_common default_target_triple arch variable)
string(FIND "${default_target_triple}" "-" dash_index)
string(SUBSTRING "${default_target_triple}" "${dash_index}" -1 triple_suffix)
string(SUBSTRING "${default_target_triple}" 0 "${dash_index}" triple_cpu)
if(ANDROID AND "${arch}" STREQUAL "i386")
set(target "i686${triple_suffix}")
elseif(${arch} STREQUAL "amd64")
elseif("${arch}" STREQUAL "amd64")
set(target "x86_64${triple_suffix}")
elseif(${arch} STREQUAL "sparc64")
elseif("${arch}" STREQUAL "sparc64")
set(target "sparcv9${triple_suffix}")
elseif("${arch}" MATCHES "mips64|mips64el")
string(REGEX REPLACE "-gnu.*" "-gnuabi64" triple_suffix_gnu "${triple_suffix}")
@@ -89,7 +86,8 @@ function (get_toolchain_arch_dirname outvar)
string(REGEX REPLACE "mips64" "mips" triple_cpu_mips "${triple_cpu_mips}")
set(target "${triple_cpu_mips}${triple_suffix_gnu}")
elseif("${arch}" MATCHES "^arm")
# FIXME: Handle arch other than arm, armhf, armv6m
# Arch is arm, armhf, armv6m (anything else would come from using
# COMPILER_RT_DEFAULT_TARGET_ONLY, which is checked above).
if (${arch} STREQUAL "armhf")
# If we are building for hard float but our ABI is soft float.
if ("${triple_suffix}" MATCHES ".*eabi$")
@@ -113,5 +111,18 @@ function (get_toolchain_arch_dirname outvar)
else()
set(target "${arch}${triple_suffix}")
endif()
set(${outvar} "${target}" PARENT_SCOPE)
set("${variable}" "${target}" PARENT_SCOPE)
endfunction()
# Corresponds to Clang's ToolChain::getRuntimePath().
function (get_toolchain_target_dirname outvar)
string(FIND "${LLVM_TARGET_TRIPLE}" "-" dash_index)
string(SUBSTRING "${LLVM_TARGET_TRIPLE}" 0 "${dash_index}" triple_cpu)
set(arch "${triple_cpu}")
if("${arch}" MATCHES "^i.86$")
set(arch "i386")
endif()
get_runtimes_target_libdir_common("${LLVM_TARGET_TRIPLE}" "${arch}" target)
set("${outvar}" "${target}" PARENT_SCOPE)
endfunction()

View File

@@ -1,5 +1,6 @@
include(CMakePushCheckState)
include(CheckSymbolExists)
include(GetToolchainDirs)
# Because compiler-rt spends a lot of time setting up custom compile flags,
# define a handy helper function for it. The compile flags setting in CMake
@@ -480,59 +481,17 @@ function(filter_builtin_sources inout_var name)
endfunction()
function(get_compiler_rt_target arch variable)
string(FIND ${COMPILER_RT_DEFAULT_TARGET_TRIPLE} "-" dash_index)
string(SUBSTRING ${COMPILER_RT_DEFAULT_TARGET_TRIPLE} ${dash_index} -1 triple_suffix)
string(SUBSTRING ${COMPILER_RT_DEFAULT_TARGET_TRIPLE} 0 ${dash_index} triple_cpu)
if(COMPILER_RT_DEFAULT_TARGET_ONLY)
# Use exact spelling when building only for the target specified to CMake.
set(target "${COMPILER_RT_DEFAULT_TARGET_TRIPLE}")
elseif(ANDROID AND ${arch} STREQUAL "i386")
set(target "i686${triple_suffix}")
elseif(${arch} STREQUAL "amd64")
set(target "x86_64${triple_suffix}")
elseif(${arch} STREQUAL "sparc64")
set(target "sparcv9${triple_suffix}")
elseif("${arch}" MATCHES "mips64|mips64el")
string(REGEX REPLACE "-gnu.*" "-gnuabi64" triple_suffix_gnu "${triple_suffix}")
string(REGEX REPLACE "mipsisa32" "mipsisa64" triple_cpu_mips "${triple_cpu}")
string(REGEX REPLACE "^mips$" "mips64" triple_cpu_mips "${triple_cpu_mips}")
string(REGEX REPLACE "^mipsel$" "mips64el" triple_cpu_mips "${triple_cpu_mips}")
set(target "${triple_cpu_mips}${triple_suffix_gnu}")
elseif("${arch}" MATCHES "mips|mipsel")
string(REGEX REPLACE "-gnuabi.*" "-gnu" triple_suffix_gnu "${triple_suffix}")
string(REGEX REPLACE "mipsisa64" "mipsisa32" triple_cpu_mips "${triple_cpu}")
string(REGEX REPLACE "mips64" "mips" triple_cpu_mips "${triple_cpu_mips}")
set(target "${triple_cpu_mips}${triple_suffix_gnu}")
elseif("${arch}" MATCHES "^arm")
# Arch is arm, armhf, armv6m (anything else would come from using
# COMPILER_RT_DEFAULT_TARGET_ONLY, which is checked above).
if (${arch} STREQUAL "armhf")
# If we are building for hard float but our ABI is soft float.
if ("${triple_suffix}" MATCHES ".*eabi$")
# Change "eabi" -> "eabihf"
set(triple_suffix "${triple_suffix}hf")
endif()
# ABI is already set in the triple, don't repeat it in the architecture.
set(arch "arm")
else ()
# If we are building for soft float, but the triple's ABI is hard float.
if ("${triple_suffix}" MATCHES ".*eabihf$")
# Change "eabihf" -> "eabi"
string(REGEX REPLACE "hf$" "" triple_suffix "${triple_suffix}")
endif()
endif()
set(target "${arch}${triple_suffix}")
elseif("${arch}" MATCHES "^amdgcn")
set(target "amdgcn-amd-amdhsa")
elseif("${arch}" MATCHES "^nvptx")
set(target "nvptx64-nvidia-cuda")
else()
set(target "${arch}${triple_suffix}")
get_runtimes_target_libdir_common("${COMPILER_RT_DEFAULT_TARGET_TRIPLE}" "${arch}" target)
endif()
set(${variable} ${target} PARENT_SCOPE)
set(${variable} "${target}" PARENT_SCOPE)
endfunction()
function(get_compiler_rt_install_dir arch install_dir)
# TODO: Use RUNTIMES_INSTALL_RESOURCE_LIB_PATH instead
if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
get_compiler_rt_target(${arch} target)
set(${install_dir} ${COMPILER_RT_INSTALL_LIBRARY_DIR}/${target} PARENT_SCOPE)
@@ -542,6 +501,7 @@ function(get_compiler_rt_install_dir arch install_dir)
endfunction()
function(get_compiler_rt_output_dir arch output_dir)
# TODO: Use RUNTIMES_OUTPUT_RESOURCE_LIB_DIR instead
if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
get_compiler_rt_target(${arch} target)
set(${output_dir} ${COMPILER_RT_OUTPUT_LIBRARY_DIR}/${target} PARENT_SCOPE)

View File

@@ -121,6 +121,8 @@ if(NOT DEFINED COMPILER_RT_OS_DIR)
string(TOLOWER ${CMAKE_SYSTEM_NAME} COMPILER_RT_OS_DIR)
endif()
endif()
# TODO: Use common runtimes infrastructure for output and install paths
if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
set(COMPILER_RT_OUTPUT_LIBRARY_DIR
${COMPILER_RT_OUTPUT_DIR}/lib)

View File

@@ -75,62 +75,9 @@ include(ExtendPath)
# Build Mode Introspection #
############################
# Determine whether we are in the runtimes/runtimes-bins directory of a
# bootstrap build.
set(LLVM_TREE_AVAILABLE OFF)
if (LLVM_LIBRARY_OUTPUT_INTDIR AND LLVM_RUNTIME_OUTPUT_INTDIR AND PACKAGE_VERSION)
set(LLVM_TREE_AVAILABLE ON)
endif()
# Path to LLVM development tools (FileCheck, llvm-lit, not, ...)
set(LLVM_TOOLS_DIR "${LLVM_BINARY_DIR}/bin")
# Determine build and install paths.
# The build path is absolute, but the install dir is relative, CMake's install
# command has to apply CMAKE_INSTALL_PREFIX itself.
get_toolchain_library_subdir(toolchain_lib_subdir)
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_OUTPUT_RESOURCE_DIR PREFIX "${LLVM_LIBRARY_OUTPUT_INTDIR}/..")
get_clang_resource_dir(FLANG_RT_INSTALL_RESOURCE_PATH_DEFAULT)
extend_path(FLANG_RT_OUTPUT_RESOURCE_LIB_DIR "${FLANG_RT_OUTPUT_RESOURCE_DIR}" "${toolchain_lib_subdir}")
else ()
# In a standalone 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.
# For the install prefix, still use the resource dir assuming that Flang will
# be installed there using the same prefix. This is to not have a difference
# between bootstrap and standalone runtimes builds.
set(FLANG_RT_OUTPUT_RESOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
set(FLANG_RT_INSTALL_RESOURCE_PATH_DEFAULT "lib${LLVM_LIBDIR_SUFFIX}/clang/${LLVM_VERSION_MAJOR}")
extend_path(FLANG_RT_OUTPUT_RESOURCE_LIB_DIR "${FLANG_RT_OUTPUT_RESOURCE_DIR}" "lib${LLVM_LIBDIR_SUFFIX}")
endif ()
set(FLANG_RT_INSTALL_RESOURCE_PATH "${FLANG_RT_INSTALL_RESOURCE_PATH_DEFAULT}"
CACHE PATH "Path to install runtime libraries to (default: clang resource dir)")
extend_path(FLANG_RT_INSTALL_RESOURCE_LIB_PATH "${FLANG_RT_INSTALL_RESOURCE_PATH}" "${toolchain_lib_subdir}")
cmake_path(NORMAL_PATH FLANG_RT_OUTPUT_RESOURCE_DIR)
cmake_path(NORMAL_PATH FLANG_RT_INSTALL_RESOURCE_PATH)
# FIXME: For the libflang_rt.so, the toolchain resource lib dir is not a good
# destination because it is not a ld.so default search path.
# The machine where the executable is eventually executed may not be the
# machine where the Flang compiler and its resource dir is installed, so
# setting RPath by the driver is not an solution. It should belong into
# /usr/lib/<triple>/libflang_rt.so, like e.g. libgcc_s.so.
# But the linker as invoked by the Flang driver also requires
# libflang_rt.so to be found when linking and the resource lib dir is
# the only reliable location.
cmake_path(NORMAL_PATH FLANG_RT_OUTPUT_RESOURCE_LIB_DIR)
cmake_path(NORMAL_PATH FLANG_RT_INSTALL_RESOURCE_LIB_PATH)
#################
# Build Options #

View File

@@ -347,13 +347,13 @@ function (add_flangrt_library name)
if (ARG_INSTALL_WITH_TOOLCHAIN)
set_target_properties(${tgtname}
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${FLANG_RT_OUTPUT_RESOURCE_LIB_DIR}"
LIBRARY_OUTPUT_DIRECTORY "${FLANG_RT_OUTPUT_RESOURCE_LIB_DIR}"
ARCHIVE_OUTPUT_DIRECTORY "${RUNTIMES_OUTPUT_RESOURCE_LIB_DIR}"
LIBRARY_OUTPUT_DIRECTORY "${RUNTIMES_OUTPUT_RESOURCE_LIB_DIR}"
)
install(TARGETS ${tgtname}
ARCHIVE DESTINATION "${FLANG_RT_INSTALL_RESOURCE_LIB_PATH}"
LIBRARY DESTINATION "${FLANG_RT_INSTALL_RESOURCE_LIB_PATH}"
ARCHIVE DESTINATION "${RUNTIMES_INSTALL_RESOURCE_LIB_PATH}"
LIBRARY DESTINATION "${RUNTIMES_INSTALL_RESOURCE_LIB_PATH}"
)
endif ()

View File

@@ -6,7 +6,7 @@ config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
config.flang_source_dir = "@FLANG_SOURCE_DIR@"
config.flang_rt_source_dir = "@FLANG_RT_SOURCE_DIR@"
config.flang_rt_binary_test_dir = os.path.dirname(__file__)
config.flang_rt_output_resource_lib_dir = "@FLANG_RT_OUTPUT_RESOURCE_LIB_DIR@"
config.flang_rt_output_resource_lib_dir = "@RUNTIMES_OUTPUT_RESOURCE_LIB_DIR@"
config.flang_rt_experimental_offload_support = "@FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT@"
config.cc = "@CMAKE_C_COMPILER@"
config.flang = "@CMAKE_Fortran_COMPILER@"

View File

@@ -234,6 +234,7 @@ if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR)
cmake_path(NORMAL_PATH LIBC_TARGET_SUBDIR)
endif()
# TODO: Use common runtimes infrastructure for output and install paths
if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND (LIBC_ENABLE_USE_BY_CLANG OR LIBC_TARGET_OS_IS_GPU))
set(LIBC_INCLUDE_DIR ${LLVM_BINARY_DIR}/include/${LLVM_DEFAULT_TARGET_TRIPLE})
set(LIBC_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
@@ -260,6 +261,7 @@ else()
endif()
endif()
# TODO: Use common runtimes infrastructure for output and install paths
if(LIBC_TARGET_TRIPLE)
set(LIBC_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LIBC_TARGET_TRIPLE})
elseif(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR)

View File

@@ -448,6 +448,7 @@ set(LIBCXX_INSTALL_MODULES_DIR "share/libc++/v1" CACHE STRING
set(LIBCXX_SHARED_OUTPUT_NAME "c++" CACHE STRING "Output name for the shared libc++ runtime library.")
set(LIBCXX_STATIC_OUTPUT_NAME "c++" CACHE STRING "Output name for the static libc++ runtime library.")
# TODO: Use common runtimes infrastructure for output and install paths
if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
set(LIBCXX_TARGET_SUBDIR ${LLVM_DEFAULT_TARGET_TRIPLE})
if(LIBCXX_LIBDIR_SUBDIR)

View File

@@ -185,6 +185,7 @@ set(CMAKE_MODULE_PATH
set(LIBCXXABI_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING
"Path where built libc++abi runtime libraries should be installed.")
# TODO: Use common runtimes infrastructure for output and install paths
if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
set(LIBCXXABI_TARGET_SUBDIR ${LLVM_DEFAULT_TARGET_TRIPLE})
if(LIBCXXABI_LIBDIR_SUBDIR)

View File

@@ -37,6 +37,7 @@ option(LIBSYCL_ENABLE_PEDANTIC "Compile with pedantic enabled." OFF)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# TODO: Use common runtimes infrastructure for output and install paths
if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
set(LIBSYCL_TARGET_SUBDIR ${LLVM_DEFAULT_TARGET_TRIPLE})
if(LIBSYCL_LIBDIR_SUBDIR)

View File

@@ -140,6 +140,7 @@ set(LIBUNWIND_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING
set(LIBUNWIND_SHARED_OUTPUT_NAME "unwind" CACHE STRING "Output name for the shared libunwind runtime library.")
set(LIBUNWIND_STATIC_OUTPUT_NAME "unwind" CACHE STRING "Output name for the static libunwind runtime library.")
# TODO: Use common runtimes infrastructure for output and install paths
if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
set(LIBUNWIND_TARGET_SUBDIR ${LLVM_DEFAULT_TARGET_TRIPLE})
if(LIBUNWIND_LIBDIR_SUBDIR)

View File

@@ -61,6 +61,7 @@ endif()
# Configure System
#===============================================================================
# TODO: Use common runtimes infrastructure for output and install paths
if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
set(TARGET_SUBDIR ${LLVM_DEFAULT_TARGET_TRIPLE})
if(LLVM_LIBGCC_LIBDIR_SUBDIR)

View File

@@ -23,6 +23,7 @@ endif()
set(OFFLOAD_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
# When building in tree we install the runtime according to the LLVM settings.
# TODO: Use common runtimes infrastructure for output and install paths
if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
set(OFFLOAD_TARGET_SUBDIR "${LLVM_DEFAULT_TARGET_TRIPLE}")
if(OFFLOAD_LIBDIR_SUBDIR)
@@ -86,6 +87,7 @@ set(CMAKE_CXX_EXTENSIONS NO)
# Set the path of all resulting libraries to a unified location so that it can
# be used for testing.
# TODO: Use common runtimes infrastructure for output and install paths
set(LIBOMPTARGET_LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBOMPTARGET_LIBRARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBOMPTARGET_LIBRARY_DIR})
@@ -281,6 +283,7 @@ if(LIBOMP_OMP_TOOLS_INCLUDE_DIR)
include_directories(${LIBOMP_OMP_TOOLS_INCLUDE_DIR})
endif()
# TODO: Use RUNTIMES_OUTPUT_RESOURCE_LIB_DIR instead
set(LIBOMPTARGET_LLVM_LIBRARY_DIR "${LLVM_LIBRARY_DIR}" CACHE STRING
"Path to folder containing llvm library libomptarget.so")
set(LIBOMPTARGET_LLVM_LIBRARY_INTDIR "${LIBOMPTARGET_INTDIR}" CACHE STRING

View File

@@ -35,6 +35,7 @@ endif ()
set(OPENMP_ENABLE_WERROR ${LLVM_ENABLE_WERROR})
# When building in tree we install the runtime according to the LLVM settings.
# TODO: Use common runtimes infrastructure for output and install paths
if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
set(OPENMP_TARGET_SUBDIR "${LLVM_DEFAULT_TARGET_TRIPLE}")
if(OPENMP_LIBDIR_SUBDIR)

View File

@@ -21,6 +21,7 @@ target_link_libraries(orc-rt-executor
)
# Apply RTTI and exceptions compile flags
# TODO: Use common runtimes infrastructure for output and install paths
target_compile_options(orc-rt-executor PRIVATE ${ORC_RT_COMPILE_FLAGS})
install(TARGETS orc-rt-executor
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}

View File

@@ -88,7 +88,8 @@ include(CheckLibraryExists)
include(LLVMCheckCompilerLinkerFlag)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
include(GetToolchainDirs)
include(ExtendPath)
# Determine whether we are in the runtimes/runtimes-bins directory of a
# bootstrap build.
@@ -239,6 +240,36 @@ if(CMAKE_C_COMPILER_ID MATCHES "Clang")
endif()
endif()
# Determine output and install paths based on LLVM_TARGET_TRIPLE
if(LLVM_TREE_AVAILABLE)
# 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()
# 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/standalone 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 output 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}")
cmake_path(NORMAL_PATH RUNTIMES_OUTPUT_RESOURCE_DIR)
cmake_path(NORMAL_PATH RUNTIMES_INSTALL_RESOURCE_PATH)
cmake_path(NORMAL_PATH RUNTIMES_OUTPUT_RESOURCE_LIB_DIR)
cmake_path(NORMAL_PATH RUNTIMES_INSTALL_RESOURCE_LIB_PATH)
option(LLVM_INCLUDE_TESTS "Generate build targets for the runtimes unit tests." ON)
option(LLVM_INCLUDE_DOCS "Generate build targets for the runtimes documentation." ON)
option(LLVM_ENABLE_SPHINX "Use Sphinx to generate the runtimes documentation." OFF)