[clang] [llvm] Skipping host target exports during cross-compilation (PR #209922)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 15 16:48:31 PDT 2026
https://github.com/zeroomega created https://github.com/llvm/llvm-project/pull/209922
Under CMake 4+, calling add_library(... SHARED IMPORTED) on a target platform that lacks dynamic linking support triggers a fatal error. This becomes an issue when building LLVM and cross compile runtimes for baremetal targets like armv6m-none-eabi. This patch skips including the host target exports when doing cross-compiling in any LLVM sub builds to solve this issue.
>From 5ac5d847ef9e4f14de68aa381420b27033f5b37d Mon Sep 17 00:00:00 2001
From: Haowei Wu <haowei at google.com>
Date: Wed, 15 Jul 2026 16:41:32 -0700
Subject: [PATCH] Skipping host target exports during cross-compilation
Under CMake 4+, calling add_library(... SHARED IMPORTED) on a
target platform that lacks dynamic linking support triggers a fatal
error. This becomes an issue when building LLVM and cross compile
runtimes for baremetal targets like armv6m-none-eabi. This patch
skips including the host target exports when doing cross-compiling
in any LLVM sub builds to solve this issue.
---
clang/cmake/modules/ClangConfig.cmake.in | 5 ++++-
llvm/cmake/modules/LLVMConfig.cmake.in | 2 +-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/clang/cmake/modules/ClangConfig.cmake.in b/clang/cmake/modules/ClangConfig.cmake.in
index 68f723d050117..e199c7e17b6b7 100644
--- a/clang/cmake/modules/ClangConfig.cmake.in
+++ b/clang/cmake/modules/ClangConfig.cmake.in
@@ -13,7 +13,10 @@ set(CLANG_LINK_CLANG_DYLIB "@CLANG_LINK_CLANG_DYLIB@")
set(CLANG_DEFAULT_LINKER "@CLANG_DEFAULT_LINKER@")
# Provide all our library targets to users.
- at CLANG_CONFIG_INCLUDE_EXPORTS@
+# Skip when cross-compiling, as host library targets are not usable.
+if(NOT CMAKE_CROSSCOMPILING)
+ @CLANG_CONFIG_INCLUDE_EXPORTS@
+endif()
# By creating clang-tablegen-targets here, subprojects that depend on Clang's
# tablegen-generated headers can always depend on this target whether building
diff --git a/llvm/cmake/modules/LLVMConfig.cmake.in b/llvm/cmake/modules/LLVMConfig.cmake.in
index 300c25e7c6101..60e155acbd9ba 100644
--- a/llvm/cmake/modules/LLVMConfig.cmake.in
+++ b/llvm/cmake/modules/LLVMConfig.cmake.in
@@ -152,7 +152,7 @@ set(LLVM_ENABLE_SHARED_LIBS @BUILD_SHARED_LIBS@)
set(LLVM_DEFAULT_EXTERNAL_LIT "@LLVM_CONFIG_DEFAULT_EXTERNAL_LIT@")
set(LLVM_LIT_ARGS "@LLVM_LIT_ARGS@")
-if(NOT TARGET LLVMSupport)
+if(NOT TARGET LLVMSupport AND NOT CMAKE_CROSSCOMPILING)
@LLVM_CONFIG_INCLUDE_EXPORTS@
@llvm_config_include_buildtree_only_exports@
endif()
More information about the cfe-commits
mailing list