[Lldb-commits] [lldb] build: enable CONFIG mode search for LibXml2 for LLDB (PR #117615)

Saleem Abdulrasool via lldb-commits lldb-commits at lists.llvm.org
Tue Nov 26 08:17:54 PST 2024


https://github.com/compnerd updated https://github.com/llvm/llvm-project/pull/117615

>From 0b7645656a9a79a496438f49c7906dead1319fe7 Mon Sep 17 00:00:00 2001
From: Saleem Abdulrasool <compnerd at compnerd.org>
Date: Mon, 25 Nov 2024 11:21:17 -0800
Subject: [PATCH] build: enable CONFIG mode search for LibXml2 for LLDB

The `find_package(LibXml2 ...)` invocation that we are currently using
precludes the use of "CONFIG mode" for libxml2. This is important to
allow dependencies to flow through the build with static builds on
Windows, which depends on Bcrypt and conditionally on Ws2_32 (in
development - current releases are unconditionally dependent on it). If
libxml2 is built statically, this dependency would need to be replicated
into LLDB's build configuration to ensure that the dependencies are met.

Add a workaround to support CONFIG mode search which avoids this need.
Additionally, clean up some unnecessary include paths. The use of
`LibXml2::LibXml2` with `target_link_libraries` on `libLLDBHost` ensures
that the header search path is properly propagated.
---
 lldb/cmake/modules/LLDBConfig.cmake | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/lldb/cmake/modules/LLDBConfig.cmake b/lldb/cmake/modules/LLDBConfig.cmake
index 93ccd9c479c2b8..bf659c1648b867 100644
--- a/lldb/cmake/modules/LLDBConfig.cmake
+++ b/lldb/cmake/modules/LLDBConfig.cmake
@@ -57,7 +57,17 @@ add_optional_dependency(LLDB_ENABLE_CURSES "Enable curses support in LLDB" Curse
 add_optional_dependency(LLDB_ENABLE_LZMA "Enable LZMA compression support in LLDB" LibLZMA LIBLZMA_FOUND)
 add_optional_dependency(LLDB_ENABLE_LUA "Enable Lua scripting support in LLDB" LuaAndSwig LUAANDSWIG_FOUND)
 add_optional_dependency(LLDB_ENABLE_PYTHON "Enable Python scripting support in LLDB" PythonAndSwig PYTHONANDSWIG_FOUND)
-add_optional_dependency(LLDB_ENABLE_LIBXML2 "Enable Libxml 2 support in LLDB" LibXml2 LIBXML2_FOUND VERSION 2.8)
+# The FindLibXml2.cmake module from CMake does not seem to search for the
+# package in both CONFIG and MODULE mode as the `find_package` documentation
+# states. Workaround this by initially doing an optional search in CONFIG mode
+# and fallback to the default search, if needed, which currently only does the
+# MODULE mode search.
+if(LLDB_ENABLE_LIBXML2 OR "${LLDB_ENABLE_LIBXML2}" STREQUAL "AUTO")
+  find_package(LibXml2 CONFIG)
+  if(NOT TARGET LibXml2::LibXml2)
+    add_optional_dependency(LLDB_ENABLE_LIBXML2 "Enable Libxml 2 support in LLDB" LibXml2 LIBXML2_FOUND VERSION 2.8)
+  endif()
+endif()
 add_optional_dependency(LLDB_ENABLE_FBSDVMCORE "Enable libfbsdvmcore support in LLDB" FBSDVMCore FBSDVMCore_FOUND QUIET)
 
 option(LLDB_USE_ENTITLEMENTS "When codesigning, use entitlements if available" ON)
@@ -239,10 +249,6 @@ if (LLDB_ENABLE_LZMA)
   include_directories(${LIBLZMA_INCLUDE_DIRS})
 endif()
 
-if (LLDB_ENABLE_LIBXML2)
-  include_directories(${LIBXML2_INCLUDE_DIR})
-endif()
-
 include_directories(BEFORE
   ${CMAKE_CURRENT_BINARY_DIR}/include
   ${CMAKE_CURRENT_SOURCE_DIR}/include
@@ -283,7 +289,6 @@ if (APPLE)
   find_library(FOUNDATION_LIBRARY Foundation)
   find_library(CORE_FOUNDATION_LIBRARY CoreFoundation)
   find_library(SECURITY_LIBRARY Security)
-  include_directories(${LIBXML2_INCLUDE_DIR})
 endif()
 
 if( WIN32 AND NOT CYGWIN )



More information about the lldb-commits mailing list