File 0002-Add-CMake-module-to-find-log4cplus.patch of Package kdrive
From 7ffd338ade44690882df685641fd01b7ea1bc605 Mon Sep 17 00:00:00 2001
From: Christophe Marin <christophe@krop.fr>
Date: Wed, 23 Apr 2025 16:56:10 +0200
Subject: [PATCH 02/10] Add CMake module to find log4cplus
---
CMakeLists.txt | 7 +++
cmake/modules/Findlog4cplus.cmake | 89 +++++++++++++++++++++++++++++
src/libcommon/CMakeLists.txt | 26 ++++-----
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, 112 insertions(+), 19 deletions(-)
create mode 100644 cmake/modules/Findlog4cplus.cmake
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e15edf6..1c488d8 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)
@@ -17,6 +20,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")
diff --git a/cmake/modules/Findlog4cplus.cmake b/cmake/modules/Findlog4cplus.cmake
new file mode 100644
index 0000000..cc68075
--- /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 62e2b2c..09912f7 100644
--- a/src/libcommon/CMakeLists.txt
+++ b/src/libcommon/CMakeLists.txt
@@ -7,7 +7,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")
@@ -122,7 +121,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
@@ -142,17 +141,18 @@ endif()
if(UNIX)
target_link_libraries(${libcommon_NAME} utf8proc)
-
- if(NOT APPLE)
- # Copy .so files to the conan dependency directory
- include(ConanGetLibDirs)
- get_library_dirs("log4cplus" "log4cplus")
- install(FILES
- "${_log4cplus_LIB_DIRS}/liblog4cplus.so"
- "${_log4cplus_LIB_DIRS}/liblog4cplus.so.9"
- DESTINATION "${CONAN_DEP_DIR}"
- PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
- )
+ if(NOT USE_SYSTEM_LOG4CPLUS)
+ if(NOT APPLE)
+ # Copy .so files to the conan dependency directory
+ include(ConanGetLibDirs)
+ get_library_dirs("log4cplus" "log4cplus")
+ install(FILES
+ "${_log4cplus_LIB_DIRS}/liblog4cplus.so"
+ "${_log4cplus_LIB_DIRS}/liblog4cplus.so.9"
+ DESTINATION "${CONAN_DEP_DIR}"
+ PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
+ )
+ endif()
endif()
endif()
diff --git a/src/server/CMakeLists.txt b/src/server/CMakeLists.txt
index b703296..9df742f 100644
--- a/src/server/CMakeLists.txt
+++ b/src/server/CMakeLists.txt
@@ -212,6 +212,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 9bcb1a8..b6c9a52 100644
--- a/test/libcommon/CMakeLists.txt
+++ b/test/libcommon/CMakeLists.txt
@@ -6,7 +6,6 @@ else()
endif()
find_package(Poco REQUIRED Foundation)
-find_package(log4cplus 2.1.2 REQUIRED)
set(testcommon_NAME ${APPLICATION_NAME}_test_common)
@@ -64,4 +63,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 df62fe5..efe86a3 100644
--- a/test/libcommonserver/CMakeLists.txt
+++ b/test/libcommonserver/CMakeLists.txt
@@ -6,7 +6,6 @@ else()
endif()
find_package(Poco REQUIRED Foundation)
-find_package(log4cplus 2.1.2 REQUIRED)
set(testcommonserver_NAME ${APPLICATION_NAME}_test_common_server)
@@ -73,4 +72,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 dba3406..dfdb144 100644
--- a/test/libparms/CMakeLists.txt
+++ b/test/libparms/CMakeLists.txt
@@ -7,7 +7,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 034a375..7a6c2de 100644
--- a/test/libsyncengine/CMakeLists.txt
+++ b/test/libsyncengine/CMakeLists.txt
@@ -7,7 +7,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.50.0