File dnf5-with-static-libsolvext.patch of Package dnf5

From ead23935896021491771553e73a43f8adc844520 Mon Sep 17 00:00:00 2001
From: Neal Gompa <ngompa@opensuse.org>
Date: Thu, 21 Sep 2023 05:50:40 -0400
Subject: [PATCH] Add build option to link libsolvext dynamic library
 dependencies

libsolv, when built only build with static link libraries, does not
make a fully usable configuration for static libsolvext to be used
because the CMake and pkgconfig files do not declare the appropriate
libraries to successfully link a static libsolvext that has dynamic library
dependencies.

This patch works around it by doing the declarations here rather than
in libsolv, since it's not easy to fix there, given upstream constraints.
---
 CMakeLists.txt         |  3 +++
 libdnf5/CMakeLists.txt | 20 +++++++++++++++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5bc551a7..3014b3e0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -56,6 +56,9 @@ option(WITH_PERL5 "Build Perl 5 bindings" ON)
 option(WITH_PYTHON3 "Build Python 3 bindings" ON)
 option(WITH_RUBY "Build Ruby bindings" ON)
 
+# build options - other
+option(WITH_STATIC_LIBSOLV "Link with dependencies of static libsolvext library" OFF)
+
 
 if(WITH_PERFORMANCE_TESTS AND WITH_SANITIZERS)
     message(FATAL_ERROR "Cannot perform performance tests with sanitizers enabled because they influence the results. Disable sanitizers to continue.")
diff --git a/libdnf5/CMakeLists.txt b/libdnf5/CMakeLists.txt
index 237ac9e4..7151c63a 100644
--- a/libdnf5/CMakeLists.txt
+++ b/libdnf5/CMakeLists.txt
@@ -63,7 +63,25 @@ pkg_check_modules(RPM REQUIRED rpm>=4.17.0)
 list(APPEND LIBDNF5_PC_REQUIRES "${RPM_MODULE_NAME}")
 target_link_libraries(libdnf5 PRIVATE ${RPM_LIBRARIES})
 
-if(WITH_COMPS)
+if(WITH_STATIC_LIBSOLV)
+    pkg_check_modules(BZIP2 REQUIRED bzip2)
+    list(APPEND LIBDNF5_PC_REQUIRES_PRIVATE "${BZIP2_MODULE_NAME}")
+    target_link_libraries(libdnf5 PRIVATE ${BZIP2_LIBRARIES})
+
+    pkg_check_modules(LZMA REQUIRED liblzma)
+    list(APPEND LIBDNF5_PC_REQUIRES_PRIVATE "${LZMA_MODULE_NAME}")
+    target_link_libraries(libdnf5 PRIVATE ${LZMA_LIBRARIES})
+
+    pkg_check_modules(ZLIB REQUIRED zlib)
+    list(APPEND LIBDNF5_PC_REQUIRES_PRIVATE "${ZLIB_MODULE_NAME}")
+    target_link_libraries(libdnf5 PRIVATE ${ZLIB_LIBRARIES})
+
+    pkg_check_modules(ZSTD REQUIRED libzstd)
+    list(APPEND LIBDNF5_PC_REQUIRES_PRIVATE "${ZSTD_MODULE_NAME}")
+    target_link_libraries(libdnf5 PRIVATE ${ZSTD_LIBRARIES})
+endif()
+
+if(WITH_COMPS OR WITH_STATIC_LIBSOLV)
     pkg_check_modules(LIBXML2 REQUIRED libxml-2.0)
     list(APPEND LIBDNF5_PC_REQUIRES_PRIVATE "${LIBXML2_MODULE_NAME}")
     include_directories(${LIBXML2_INCLUDE_DIRS})
-- 
2.45.1

openSUSE Build Service is sponsored by