[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
Mon Nov 25 11:31:35 PST 2024


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

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.

>From 733687bd4aef042df4d1e7587cd78d6ba9e6c37f 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..ba3ce6c444f887 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)
+# LibXml2 is required if LLDB_ENABLE_LIBXML2 is ON or AUTO. The LibXml2 package
+# search is not setup properly to support the CONFIG mode search. Furthermore,
+# in CONFIG mode, we cannot specify the version as that is an exact match. As a
+# mitigation, perform a CONFIG mode search for LibXml2 if LLDB_ENABLE_LIBXML2
+# is ON or AUTO, and fallback to the old path if not found.
+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