commit: c774f99101c5c940c92fea36061e838ce7514c3e
Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Mon Dec 16 10:24:07 2024 +0000
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Mon Dec 30 11:32:30 2024 +0000
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=c774f991
llvm-r2.eclass: Add llvm_chost_setup, set CMake path variables
Add a llvm_chost_setup function that handles CHOST-specific setup.
Initially, this means setting CMake variables that control
`find_package()` lookups.
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>
eclass/llvm-r2.eclass | 37 ++++++++++++++++++++++++++++++-------
1 file changed, 30 insertions(+), 7 deletions(-)
diff --git a/eclass/llvm-r2.eclass b/eclass/llvm-r2.eclass
index 93c16e75be83..91e841821331 100644
--- a/eclass/llvm-r2.eclass
+++ b/eclass/llvm-r2.eclass
@@ -248,16 +248,35 @@ llvm_cbuild_setup() {
llvm_prepend_path -b "${LLVM_SLOT}"
}
-# @FUNCTION: llvm-r2_pkg_setup
+# @FUNCTION: llvm_chost_setup
# @DESCRIPTION:
-# Prepend the appropriate executable directory for the selected LLVM
-# slot to PATH.
+# Set the environment for finding selected LLVM slot installed
+# for CHOST.
#
-# The PATH manipulation is only done for source builds. The function
-# is a no-op when installing a binary package.
+# This function is meant to be used when the package in question uses
+# LLVM compiles against and links to LLVM. It is called automatically
+# by llvm-r2_pkg_setup if LLVM is found installed in ESYSROOT.
+llvm_chost_setup() {
+ debug-print-function ${FUNCNAME} "$@"
+
+ local esysroot_prefix=$(get_llvm_prefix -d)
+ einfo "Using ${esysroot_prefix} for CHOST LLVM ${LLVM_SLOT}"
+ [[ -d ${esysroot_prefix} ]] ||
+ die "LLVM ${LLVM_SLOT} not found installed in ESYSROOT
(expected: ${esysroot_prefix})"
+
+ # satisfies find_package() in CMake
+ export LLVM_ROOT="${esysroot_prefix}"
+ export Clang_ROOT="${esysroot_prefix}"
+ export LLD_ROOT="${esysroot_prefix}"
+}
+
+# @FUNCTION: llvm-r2_pkg_setup
+# @DESCRIPTION:
+# Handle all supported setup actions automatically. If LLVM is found
+# installed for CBUILD, call llvm_cbuild_setup. If it is found
+# installed for CHOST, call llvm_chost_setup.
#
-# If any other behavior is desired, the contents of the function
-# should be inlined into the ebuild and modified as necessary.
+# This function is a no-op when installing a binary package.
#
# Note that this function is not exported if LLVM_OPTIONAL is set.
# In that case, it needs to be called manually.
@@ -270,6 +289,10 @@ llvm-r2_pkg_setup() {
if [[ -d $(get_llvm_prefix -b)/bin ]]; then
llvm_cbuild_setup
fi
+
+ if [[ -d $(get_llvm_prefix -d) ]]; then
+ llvm_chost_setup
+ fi
fi
}