[llvm] [cmake] Pass cached library variables only if target matches host (PR #227660)

Raul Tambre via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 30 07:50:45 PDT 2026


https://github.com/tambry updated https://github.com/llvm/llvm-project/pull/227660

>From a296288fd0d7611bbac113805bf7a3f0e2a2c0b9 Mon Sep 17 00:00:00 2001
From: Raul Tambre <raul at tambre.ee>
Date: Wed, 30 Sep 2026 13:55:46 +0300
Subject: [PATCH] [cmake] Pass cached library variables only if target matches
 host

If we're building runtimes for say an embedded none triple then LLVMConfig.cmake finding Zst will
fail as it will try to create a SHARED target, which isn't possible for baremetal targets.

This came up as due to same changes I switched my runtime builds to define CMAKE_SYSTEM_NAME=Generic.
But that brings up the aforementioned shared library target issue.

This coincidentally somewhat relates to an ongoing RFC:
https://discourse.llvm.org/t/rfc-fixing-cmake-system-name-in-cross-compiled-runtimes-builds/91897
---
 .../modules/LLVMExternalProjectUtils.cmake    | 48 +++++++++++--------
 1 file changed, 28 insertions(+), 20 deletions(-)

diff --git a/llvm/cmake/modules/LLVMExternalProjectUtils.cmake b/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
index 32e25567ef57e2..c1d9e942e81030 100644
--- a/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
+++ b/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
@@ -174,26 +174,34 @@ function(llvm_ExternalProject_Add name source_dir)
     set_target_properties(${name}-clear PROPERTIES FOLDER "${ARG_FOLDER}")
   endif ()
 
-  set(DEFAULT_PASSTHROUGH_VARIABLES
-    LibEdit_INCLUDE_DIRS
-    LibEdit_LIBRARIES
-    ZLIB_INCLUDE_DIR
-    ZLIB_LIBRARY
-    ZLIB_LIBRARY_RELEASE
-    ZLIB_LIBRARY_DEBUG
-    zstd_INCLUDE_DIR
-    zstd_LIBRARY
-    LIBXML2_LIBRARY
-    LIBXML2_INCLUDE_DIR
-    CURL_INCLUDE_DIR
-    CURL_LIBRARY
-    HTTPLIB_INCLUDE_DIR
-    HTTPLIB_HEADER_PATH
-    Python3_EXECUTABLE
-    Python3_LIBRARIES
-    Python3_INCLUDE_DIRS
-    Python3_RPATH
-    )
+  # Add only if the target matches.
+  # Otherwise LLVMConfig.cmake dependency finding will short-circuit to almost
+  # certainly incompatible host system libraries.
+  # LLVM target triple and the passed triple are assumed to be of the same form
+  # as semantically comparing triples in CMake would be an ordeal.
+  if("${ARG_TARGET_TRIPLE}" STREQUAL "${LLVM_TARGET_TRIPLE}")
+    set(DEFAULT_PASSTHROUGH_VARIABLES
+      LibEdit_INCLUDE_DIRS
+      LibEdit_LIBRARIES
+      ZLIB_INCLUDE_DIR
+      ZLIB_LIBRARY
+      ZLIB_LIBRARY_RELEASE
+      ZLIB_LIBRARY_DEBUG
+      zstd_INCLUDE_DIR
+      zstd_LIBRARY
+      LIBXML2_LIBRARY
+      LIBXML2_INCLUDE_DIR
+      CURL_INCLUDE_DIR
+      CURL_LIBRARY
+      HTTPLIB_INCLUDE_DIR
+      HTTPLIB_HEADER_PATH
+      Python3_EXECUTABLE
+      Python3_LIBRARIES
+      Python3_INCLUDE_DIRS
+      Python3_RPATH
+      )
+  endif()
+
   foreach(variable ${DEFAULT_PASSTHROUGH_VARIABLES})
     get_property(is_value_set CACHE ${variable} PROPERTY VALUE SET)
     if(${is_value_set})



More information about the llvm-commits mailing list