https://github.com/zeroomega updated 
https://github.com/llvm/llvm-project/pull/209922

>From 09bf06b5436d627f788346c14bb97df576de7572 Mon Sep 17 00:00:00 2001
From: Haowei Wu <[email protected]>
Date: Wed, 15 Jul 2026 16:41:32 -0700
Subject: [PATCH] Adding an option to Skip LLVM and Clang exports

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 runtimes for
baremetal targets like armv6m-none-eabi. This patch
adds the option "LLVM_OMIT_EXPORTS_FROM_CONFIG" in LLVM.
When used in sub builds like LLVM runtimes, it makes CMake to skip
including the LLVM and Clang exports. This mitigates the CMake 4
errors on baremetal runtimes.
---
 clang/cmake/modules/ClangConfig.cmake.in        | 8 +++++++-
 compiler-rt/cmake/Modules/CompilerRTUtils.cmake | 5 +++++
 llvm/CMakeLists.txt                             | 2 ++
 llvm/cmake/modules/LLVMConfig.cmake.in          | 2 +-
 runtimes/CMakeLists.txt                         | 7 +++++++
 5 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/clang/cmake/modules/ClangConfig.cmake.in 
b/clang/cmake/modules/ClangConfig.cmake.in
index 68f723d050117..2d37c5a443ae2 100644
--- a/clang/cmake/modules/ClangConfig.cmake.in
+++ b/clang/cmake/modules/ClangConfig.cmake.in
@@ -13,7 +13,13 @@ set(CLANG_LINK_CLANG_DYLIB "@CLANG_LINK_CLANG_DYLIB@")
 set(CLANG_DEFAULT_LINKER "@CLANG_DEFAULT_LINKER@")
 
 # Provide all our library targets to users.
-@CLANG_CONFIG_INCLUDE_EXPORTS@
+# Skip when LLVM_OMIT_EXPORTS_FROM_CONFIG flag is set.
+# Runtimes build do not need these and they are causing
+# problems when cross compiling for embeded platforms which
+# lack shared library support.
+if(NOT LLVM_OMIT_EXPORTS_FROM_CONFIG)
+  @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/compiler-rt/cmake/Modules/CompilerRTUtils.cmake 
b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
index c2bf2e54b9fd4..a6f62948d05a1 100644
--- a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
+++ b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
@@ -313,6 +313,11 @@ macro(load_llvm_config)
       "You are not using the monorepo layout. This configuration is 
DEPRECATED.")
   endif()
 
+  # Skip importing LLVM exported targets as they are not needed.
+  # On baremetal platforms that lacks shared library support,
+  # these exports may contain shared libraries and they will
+  # trigger cmake errors.
+  set(LLVM_OMIT_EXPORTS_FROM_CONFIG ON)
   find_package(LLVM HINTS "${LLVM_CMAKE_DIR}")
   if (NOT LLVM_FOUND)
      message(WARNING "UNSUPPORTED COMPILER-RT CONFIGURATION DETECTED: "
diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 7b8f1b3b3ced9..8fdae085e9524 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -1017,6 +1017,8 @@ if (CMAKE_BUILD_TYPE AND uppercase_CMAKE_BUILD_TYPE 
MATCHES "^(RELWITHDEBINFO|DE
   set(LLVM_OMIT_DAGISEL_COMMENTS OFF)
 endif()
 
+option(LLVM_OMIT_EXPORTS_FROM_CONFIG "Do not import LLVM and Clang exports. 
This is used in runtimes sub builds" OFF)
+
 if (MSVC_IDE)
   option(LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION "Configure project to use 
Visual Studio native visualizers" TRUE)
 endif()
diff --git a/llvm/cmake/modules/LLVMConfig.cmake.in 
b/llvm/cmake/modules/LLVMConfig.cmake.in
index 300c25e7c6101..6f5fcc6a926f9 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 LLVM_OMIT_EXPORTS_FROM_CONFIG)
   @LLVM_CONFIG_INCLUDE_EXPORTS@
   @llvm_config_include_buildtree_only_exports@
 endif()
diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt
index 67ed49a7dcabb..98d8e6462a10f 100644
--- a/runtimes/CMakeLists.txt
+++ b/runtimes/CMakeLists.txt
@@ -76,6 +76,13 @@ if(LLVM_BINARY_DIR)
   list(APPEND llvm_search_paths 
"${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm")
   list(APPEND clang_search_paths 
"${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/clang")
 endif()
+
+# Skip importing LLVM exported targets as they are not needed.
+# On baremetal platforms that lacks shared library support,
+# these exports may contain shared libraries and they will
+# trigger cmake errors.
+set(LLVM_OMIT_EXPORTS_FROM_CONFIG ON)
+
 find_package(LLVM PATHS ${llvm_search_paths} NO_DEFAULT_PATH 
NO_CMAKE_FIND_ROOT_PATH)
 find_package(Clang PATHS ${clang_search_paths} NO_DEFAULT_PATH 
NO_CMAKE_FIND_ROOT_PATH)
 

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to