[llvm] [CMake] Fix config when static zstd libraries are not found (PR #113584)

Udit Kumar Agarwal via llvm-commits llvm-commits at lists.llvm.org
Wed May 21 07:52:23 PDT 2025


https://github.com/uditagarwal97 updated https://github.com/llvm/llvm-project/pull/113584

>From c58034c40b7d5ce489b553a44a7cef4c56ff39bd Mon Sep 17 00:00:00 2001
From: Udit Agarwal <udit.agarwal at intel.com>
Date: Thu, 24 Oct 2024 08:31:47 -0700
Subject: [PATCH 1/3] Fix config when static zstd libraries are not found

---
 llvm/cmake/config-ix.cmake | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/llvm/cmake/config-ix.cmake b/llvm/cmake/config-ix.cmake
index 86f2bac7d23e8..03a532772cbfe 100644
--- a/llvm/cmake/config-ix.cmake
+++ b/llvm/cmake/config-ix.cmake
@@ -157,7 +157,14 @@ if(LLVM_ENABLE_ZSTD)
     find_package(zstd QUIET)
   endif()
 endif()
+
+# If LLVM_USE_STATIC_ZSTD is specified, make sure we enable zstd only if static
+# libraries are found.
+if(LLVM_USE_STATIC_ZSTD AND NOT TARGET zstd::libzstd_static)
+set(LLVM_ENABLE_ZSTD OFF)
+else()
 set(LLVM_ENABLE_ZSTD ${zstd_FOUND})
+endif()
 
 if(LLVM_ENABLE_LIBXML2)
   if(LLVM_ENABLE_LIBXML2 STREQUAL FORCE_ON)

>From b6a84d3740be1b1b9767f2f51080b02e3746a5ab Mon Sep 17 00:00:00 2001
From: Udit Agarwal <udit.agarwal at intel.com>
Date: Tue, 29 Oct 2024 16:11:38 -0700
Subject: [PATCH 2/3] Fail if static zstd libs are not found

---
 llvm/cmake/config-ix.cmake | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/llvm/cmake/config-ix.cmake b/llvm/cmake/config-ix.cmake
index 03a532772cbfe..6375280e03b38 100644
--- a/llvm/cmake/config-ix.cmake
+++ b/llvm/cmake/config-ix.cmake
@@ -161,6 +161,10 @@ endif()
 # If LLVM_USE_STATIC_ZSTD is specified, make sure we enable zstd only if static
 # libraries are found.
 if(LLVM_USE_STATIC_ZSTD AND NOT TARGET zstd::libzstd_static)
+  # Fail if LLVM_ENABLE_ZSTD is FORCE_ON.
+  if(LLVM_ENABLE_ZSTD STREQUAL FORCE_ON)
+      message(FATAL_ERROR "Failed to find static zstd libraries, but LLVM_USE_STATIC_ZSTD=ON and LLVM_ENABLE_ZSTD=FORCE_ON.")
+  endif()
 set(LLVM_ENABLE_ZSTD OFF)
 else()
 set(LLVM_ENABLE_ZSTD ${zstd_FOUND})

>From c8447a8a4e821a3e844b733a1271f87ebacb1a9f Mon Sep 17 00:00:00 2001
From: Udit Kumar Agarwal <udit.agarwal at intel.com>
Date: Wed, 21 May 2025 07:52:12 -0700
Subject: [PATCH 3/3] Fix indentation

---
 llvm/cmake/config-ix.cmake | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/cmake/config-ix.cmake b/llvm/cmake/config-ix.cmake
index 001b3b2fcb583..4138212aeb942 100644
--- a/llvm/cmake/config-ix.cmake
+++ b/llvm/cmake/config-ix.cmake
@@ -204,9 +204,9 @@ if(LLVM_USE_STATIC_ZSTD AND NOT TARGET zstd::libzstd_static)
   if(LLVM_ENABLE_ZSTD STREQUAL FORCE_ON)
       message(FATAL_ERROR "Failed to find static zstd libraries, but LLVM_USE_STATIC_ZSTD=ON and LLVM_ENABLE_ZSTD=FORCE_ON.")
   endif()
-set(LLVM_ENABLE_ZSTD OFF)
+  set(LLVM_ENABLE_ZSTD OFF)
 else()
-set(LLVM_ENABLE_ZSTD ${zstd_FOUND})
+  set(LLVM_ENABLE_ZSTD ${zstd_FOUND})
 endif()
 
 if(LLVM_ENABLE_LIBXML2)



More information about the llvm-commits mailing list