[llvm] [cmake] use target names instead of legacy variables (PR #185463)

Andrew Marshall via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 9 10:17:19 PDT 2026


https://github.com/planetmarshall created https://github.com/llvm/llvm-project/pull/185463

Use the [name of the imported targets](https://cmake.org/cmake/help/latest/module/CheckSymbolExists.html) when testing the libraries during cmake configuration. This removes the need  to also set `CMAKE_REQUIRED_INCLUDES` and `CMAKE_REQUIRED_DEFINITIONS` and reflects more modern CMake usage where targets are preferred over variables.

This is already the case when checking libcurl in the same file.

>From 54fe3c3dc35e859f96218a5deb6228da027bec5a Mon Sep 17 00:00:00 2001
From: Andrew Marshall <planetmarshalluk at gmail.com>
Date: Mon, 9 Mar 2026 17:11:48 +0000
Subject: [PATCH] [cmake] use target names instead of legacy variables

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

diff --git a/llvm/cmake/config-ix.cmake b/llvm/cmake/config-ix.cmake
index a12eaf76d15df..8948db76ce297 100644
--- a/llvm/cmake/config-ix.cmake
+++ b/llvm/cmake/config-ix.cmake
@@ -172,8 +172,7 @@ if(LLVM_ENABLE_ZLIB)
     # Check if zlib we found is usable; for example, we may have found a 32-bit
     # library on a 64-bit system which would result in a link-time failure.
     cmake_push_check_state()
-    list(APPEND CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIRS})
-    list(APPEND CMAKE_REQUIRED_LIBRARIES ${ZLIB_LIBRARY})
+    list(APPEND CMAKE_REQUIRED_LIBRARIES ZLIB::ZLIB)
     check_symbol_exists(compress2 zlib.h HAVE_ZLIB)
     cmake_pop_check_state()
     if(LLVM_ENABLE_ZLIB STREQUAL FORCE_ON AND NOT HAVE_ZLIB)
@@ -219,9 +218,7 @@ if(LLVM_ENABLE_LIBXML2)
     # Check if libxml2 we found is usable; for example, we may have found a 32-bit
     # library on a 64-bit system which would result in a link-time failure.
     cmake_push_check_state()
-    list(APPEND CMAKE_REQUIRED_INCLUDES ${LIBXML2_INCLUDE_DIRS})
-    list(APPEND CMAKE_REQUIRED_LIBRARIES ${LIBXML2_LIBRARIES})
-    list(APPEND CMAKE_REQUIRED_DEFINITIONS ${LIBXML2_DEFINITIONS})
+    list(APPEND CMAKE_REQUIRED_LIBRARIES LibXml2::LibXml2)
     check_symbol_exists(xmlReadMemory libxml/xmlreader.h HAVE_LIBXML2)
     cmake_pop_check_state()
     if(LLVM_ENABLE_LIBXML2 STREQUAL FORCE_ON AND NOT HAVE_LIBXML2)



More information about the llvm-commits mailing list