File 0001-Add-CMake-module-to-find-log4cplus.patch of Package kdrive

From 79142d9c8a00077abdcdfa014daa4499df3a4a10 Mon Sep 17 00:00:00 2001
From: Christophe Marin <christophe@krop.fr>
Date: Wed, 23 Apr 2025 16:56:10 +0200
Subject: [PATCH] Add CMake module to find log4cplus

---
 CMakeLists.txt                      | 53 ++++++++++-------
 cmake/modules/Findlog4cplus.cmake   | 89 +++++++++++++++++++++++++++++
 src/libcommon/CMakeLists.txt        |  3 +-
 src/server/CMakeLists.txt           |  1 +
 test/libcommon/CMakeLists.txt       |  3 +-
 test/libcommonserver/CMakeLists.txt |  3 +-
 test/libparms/CMakeLists.txt        |  1 -
 test/libsyncengine/CMakeLists.txt   |  1 -
 8 files changed, 124 insertions(+), 30 deletions(-)
 create mode 100644 cmake/modules/Findlog4cplus.cmake

diff --git a/CMakeLists.txt b/CMakeLists.txt
index b83b3a412..565d9d677 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,6 +2,9 @@ cmake_minimum_required(VERSION 3.16)
 
 set(CMAKE_CXX_STANDARD 20)
 project(client)
+
+include(CMakeDependentOption)
+
 if(APPLE)
     enable_language(OBJC)
     enable_language(OBJCXX)
@@ -28,6 +31,10 @@ endif()
 # keychain
 add_subdirectory(src/3rdparty/keychain)
 
+# log4cplus
+find_package(log4cplus 2.1.2)
+cmake_dependent_option(USE_SYSTEM_LOG4CPLUS "Use system log4cplus library" TRUE log4cplus_FOUND FALSE)
+
 #####
 
 if(CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo")
@@ -313,27 +320,29 @@ elseif(BUILD_CLIENT)
     endif()
 endif()
 
-if(UNIX AND NOT APPLE)
-    if (DEFINED CONAN_DEP_DIR)
-        # Copy .so files to the conan dependency directory
-        include(ConanGetLibDirs)
-        get_library_dirs("log4cplus" "log4cplus")
-        get_library_dirs("OpenSSL" "openssl")
-        get_library_dirs("xxHash" "xxhash")
-        file(COPY
-            # log4cplus
-            "${_log4cplus_LIB_DIRS}/liblog4cplus.so"
-            "${_log4cplus_LIB_DIRS}/liblog4cplus.so.9"
-            # xxHash
-            "${_xxHash_LIB_DIRS}/libxxhash.so"
-            "${_xxHash_LIB_DIRS}/libxxhash.so.0"
-            "${_xxHash_LIB_DIRS}/libxxhash.so.0.8.2"
-            # OpenSSL
-            "${_OpenSSL_LIB_DIRS}/libcrypto.so"
-            "${_OpenSSL_LIB_DIRS}/libcrypto.so.3"
-            "${_OpenSSL_LIB_DIRS}/libssl.so"
-            "${_OpenSSL_LIB_DIRS}/libssl.so.3"
-            DESTINATION "${CONAN_DEP_DIR}"
-            FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
+if(NOT USE_SYSTEM_LOG4CPLUS)
+    if(UNIX AND NOT APPLE)
+        if (DEFINED CONAN_DEP_DIR)
+            # Copy .so files to the conan dependency directory
+            include(ConanGetLibDirs)
+            get_library_dirs("log4cplus" "log4cplus")
+            get_library_dirs("OpenSSL" "openssl")
+            get_library_dirs("xxHash" "xxhash")
+            file(COPY
+                # log4cplus
+                "${_log4cplus_LIB_DIRS}/liblog4cplus.so"
+                "${_log4cplus_LIB_DIRS}/liblog4cplus.so.9"
+                # xxHash
+                "${_xxHash_LIB_DIRS}/libxxhash.so"
+                "${_xxHash_LIB_DIRS}/libxxhash.so.0"
+                "${_xxHash_LIB_DIRS}/libxxhash.so.0.8.2"
+                # OpenSSL
+                "${_OpenSSL_LIB_DIRS}/libcrypto.so"
+                "${_OpenSSL_LIB_DIRS}/libcrypto.so.3"
+                "${_OpenSSL_LIB_DIRS}/libssl.so"
+                "${_OpenSSL_LIB_DIRS}/libssl.so.3"
+                DESTINATION "${CONAN_DEP_DIR}"
+                FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
+        endif()
     endif()
 endif()
diff --git a/cmake/modules/Findlog4cplus.cmake b/cmake/modules/Findlog4cplus.cmake
new file mode 100644
index 000000000..cc68075cb
--- /dev/null
+++ b/cmake/modules/Findlog4cplus.cmake
@@ -0,0 +1,89 @@
+# SPDX-FileCopyrightText: 2025 Christophe Marin <christophe@krop.fr>
+#
+# SPDX-License-Identifier:  BSD-2-Clause
+
+#[=======================================================================[.rst:
+Findlog4cplus
+-------------
+
+Try to find log4cplus library.
+
+The following variables will be defined:
+
+``log4cplus_FOUND``
+    True if log4cplus is available
+``log4cplus_VERSION``
+    log4cplus version
+``log4cplus_LIBRARIES``
+    log4cplus libraries. This variable can be used with target_link_libraries()
+``log4cplusU_LIBRARIES``
+    log4cplusU libraries. This variable can be used with target_link_libraries()
+``log4cplus_INCLUDE_DIRS``
+    Include directories of log4cplus. This variable can be used with target_include_directories()
+
+If ``log4cplus_FOUND`` is TRUE, the following imported targets will be defined:
+
+``log4cplus::log4cplus``
+    The log4cplus library
+``log4cplus::log4cplusU``
+    The log4cplus library
+
+Using the imported targets is recommended.
+
+#]=======================================================================]
+
+find_package(PkgConfig QUIET)
+pkg_check_modules(PC_log4cplus QUIET IMPORTED_TARGET log4cplus)
+
+find_library(log4cplus_LIBRARIES
+    NAMES log4cplus
+    HINTS ${PC_log4cplus_LIBRARY_DIRS}
+)
+
+find_library(log4cplusU_LIBRARIES
+    NAMES log4cplusU
+    HINTS ${PC_log4cplus_LIBRARY_DIRS}
+)
+
+find_path(log4cplus_INCLUDE_DIRS
+    NAMES log4cplus/logger.h
+    HINTS ${PC_log4cplus_INCLUDE_DIRS}
+)
+
+set(log4cplus_VERSION ${PC_log4cplus_VERSION})
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(log4cplus
+    FOUND_VAR
+        log4cplus_FOUND
+    REQUIRED_VARS
+        log4cplus_LIBRARIES
+        log4cplusU_LIBRARIES
+        log4cplus_INCLUDE_DIRS
+    VERSION_VAR
+        log4cplus_VERSION
+)
+
+if(log4cplus_FOUND AND NOT TARGET log4cplus::log4cplus)
+    add_library(log4cplus::log4cplus UNKNOWN IMPORTED)
+    set_target_properties(log4cplus::log4cplus PROPERTIES
+        IMPORTED_LOCATION "${log4cplus_LIBRARIES}"
+        INTERFACE_COMPILE_OPTIONS "${PC_log4cplus_CFLAGS}"
+        INTERFACE_INCLUDE_DIRECTORIES "${log4cplus_INCLUDE_DIRS}")
+endif()
+
+if(log4cplus_FOUND AND NOT TARGET log4cplus::log4cplusU)
+    add_library(log4cplus::log4cplusU UNKNOWN IMPORTED)
+    set_target_properties(log4cplus::log4cplusU PROPERTIES
+        IMPORTED_LOCATION "${log4cplusU_LIBRARIES}"
+        INTERFACE_COMPILE_OPTIONS "${PC_log4cplus_CFLAGS}"
+        INTERFACE_INCLUDE_DIRECTORIES "${log4cplus_INCLUDE_DIRS}")
+endif()
+
+include(FeatureSummary)
+set_package_properties(log4cplus PROPERTIES
+    DESCRIPTION "Thread-safe C++ logging API"
+    URL "https://sourceforge.net/projects/log4cplus/"
+)
+
+mark_as_advanced(log4cplus_LIBRARIES log4cplusU_LIBRARIES log4cplus_INCLUDE_DIRS log4cplus_VERSION)
diff --git a/src/libcommon/CMakeLists.txt b/src/libcommon/CMakeLists.txt
index aec2df946..7dd5e0533 100644
--- a/src/libcommon/CMakeLists.txt
+++ b/src/libcommon/CMakeLists.txt
@@ -6,7 +6,6 @@ endif()
 
 find_package(Qt6 REQUIRED COMPONENTS Network Widgets Gui Sql)
 find_package(Poco 1.13.3 REQUIRED Foundation JSON Util)
-find_package(log4cplus 2.1.2 REQUIRED)
 find_package(sentry REQUIRED)
 
 if(UNIX AND CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo")
@@ -126,7 +125,7 @@ endif()
 target_link_libraries(${libcommon_NAME}
     Qt6::Core Qt6::Gui Qt6::Widgets Qt6::Network Qt6::Sql
     Poco::Foundation Poco::JSON Poco::Util
-    log4cplus::log4cplus
+    log4cplus::log4cplusU
     sentry::sentry
     keychain
     libzip::zip)
diff --git a/src/server/CMakeLists.txt b/src/server/CMakeLists.txt
index 926b64467..70816d14b 100644
--- a/src/server/CMakeLists.txt
+++ b/src/server/CMakeLists.txt
@@ -252,6 +252,7 @@ target_link_libraries(updater
 target_link_libraries(${APPLICATION_EXECUTABLE}
     Qt6::Svg
     sentry::sentry
+    log4cplus::log4cplusU
     updater)
 
 if( UNIX AND NOT APPLE )
diff --git a/test/libcommon/CMakeLists.txt b/test/libcommon/CMakeLists.txt
index 417a41956..540813100 100644
--- a/test/libcommon/CMakeLists.txt
+++ b/test/libcommon/CMakeLists.txt
@@ -5,7 +5,6 @@ else()
 endif()
 
 find_package(Poco REQUIRED Foundation)
-find_package(log4cplus 2.1.2 REQUIRED)
 
 set(testcommon_NAME ${APPLICATION_NAME}_test_common)
 
@@ -63,4 +62,4 @@ elseif(APPLE)
 else()
     target_link_libraries(${testcommon_NAME}
             "/usr/local/lib/libcppunit.so")
-endif ()
\ No newline at end of file
+endif ()
diff --git a/test/libcommonserver/CMakeLists.txt b/test/libcommonserver/CMakeLists.txt
index 7849f519c..9bbb85423 100644
--- a/test/libcommonserver/CMakeLists.txt
+++ b/test/libcommonserver/CMakeLists.txt
@@ -5,7 +5,6 @@ else()
 endif()
 
 find_package(Poco REQUIRED Foundation)
-find_package(log4cplus 2.1.2 REQUIRED)
 
 set(testcommonserver_NAME ${APPLICATION_NAME}_test_common_server)
 
@@ -72,4 +71,4 @@ elseif(APPLE)
 else()
     target_link_libraries(${testcommonserver_NAME}
             "/usr/local/lib/libcppunit.so")
-endif ()
\ No newline at end of file
+endif ()
diff --git a/test/libparms/CMakeLists.txt b/test/libparms/CMakeLists.txt
index 5a182543d..673cba4b2 100644
--- a/test/libparms/CMakeLists.txt
+++ b/test/libparms/CMakeLists.txt
@@ -6,7 +6,6 @@ endif()
 
 find_package(SQLite3 3.8.0 REQUIRED)
 find_package(Poco REQUIRED Foundation)
-find_package(log4cplus 2.1.2 REQUIRED)
 
 set(testparms_NAME ${APPLICATION_NAME}_test_parms)
 
diff --git a/test/libsyncengine/CMakeLists.txt b/test/libsyncengine/CMakeLists.txt
index 63504c9f3..69ceac249 100644
--- a/test/libsyncengine/CMakeLists.txt
+++ b/test/libsyncengine/CMakeLists.txt
@@ -6,7 +6,6 @@ endif()
 
 find_package(SQLite3 3.8.0 REQUIRED)
 find_package(Poco REQUIRED Foundation)
-find_package(log4cplus 2.1.2 REQUIRED)
 
 set(testsyncengine_NAME ${APPLICATION_NAME}_test_syncengine)
 
-- 
2.51.1

openSUSE Build Service is sponsored by