File 0004-Add-CMake-module-to-find-system-utf8proc.patch of Package kdrive
From 8b31066fd2c4bd1f6b5b483253bc7fd94025837c Mon Sep 17 00:00:00 2001
From: Christophe Marin <christophe@krop.fr>
Date: Wed, 23 Apr 2025 17:09:16 +0200
Subject: [PATCH 04/10] Add CMake module to find system utf8proc
---
CMakeLists.txt | 9 ++--
cmake/modules/Findutf8proc.cmake | 71 ++++++++++++++++++++++++++++++
src/libcommonserver/CMakeLists.txt | 17 ++++---
3 files changed, 89 insertions(+), 8 deletions(-)
create mode 100644 cmake/modules/Findutf8proc.cmake
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1c488d8..e03f0fc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -10,11 +10,16 @@ if(APPLE)
enable_language(OBJCXX)
endif()
+set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
+
##### Submodules
# utf8proc
if(UNIX)
- add_subdirectory(src/3rdparty/utf8proc)
+ find_package(utf8proc)
+ if(NOT utf8proc_FOUND)
+ add_subdirectory(src/3rdparty/utf8proc)
+ endif()
endif()
# keychain
@@ -48,8 +53,6 @@ set(BUILD_SHARED_LIBS FALSE)
include("${CMAKE_CURRENT_LIST_DIR}/THEME.cmake")
-set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
-
IF (WIN32)
SET(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH}
"C:/Program Files (x86)/Poco"
diff --git a/cmake/modules/Findutf8proc.cmake b/cmake/modules/Findutf8proc.cmake
new file mode 100644
index 0000000..7c9c723
--- /dev/null
+++ b/cmake/modules/Findutf8proc.cmake
@@ -0,0 +1,71 @@
+# SPDX-FileCopyrightText: 2025 Christophe Marin <christophe@krop.fr>
+#
+# SPDX-License-Identifier: BSD-2-Clause
+
+#[=======================================================================[.rst:
+Findutf8proc
+-------------
+
+Try to find utf8proc library.
+
+The following variables will be defined:
+
+``utf8proc_FOUND``
+ True if utf8proc is available
+``utf8proc_VERSION``
+ utf8proc version
+``utf8proc_LIBRARIES``
+ utf8proc libraries. This variable can be used with target_link_libraries()
+``utf8proc_INCLUDE_DIRS``
+ Include directories of utf8proc. This variable can be used with target_include_directories()
+
+If ``utf8proc_FOUND`` is TRUE, the following imported target will be defined:
+
+``utf8proc::utf8proc``
+ The utf8proc library
+
+Using the imported targets is recommended.
+
+#]=======================================================================]
+
+find_package(PkgConfig QUIET)
+pkg_check_modules(PC_utf8proc QUIET IMPORTED_TARGET libutf8proc)
+
+find_library(utf8proc_LIBRARIES
+ NAMES utf8proc
+ HINTS ${PC_utf8proc_LIBRARY_DIRS}
+)
+
+find_path(utf8proc_INCLUDE_DIRS
+ NAMES utf8proc.h
+ HINTS ${PC_utf8proc_INCLUDE_DIRS}
+)
+
+set(utf8proc_VERSION ${PC_utf8proc_VERSION})
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(utf8proc
+ FOUND_VAR
+ utf8proc_FOUND
+ REQUIRED_VARS
+ utf8proc_LIBRARIES
+ utf8proc_INCLUDE_DIRS
+ VERSION_VAR
+ utf8proc_VERSION
+)
+
+if(utf8proc_FOUND AND NOT TARGET utf8proc::utf8proc)
+ add_library(utf8proc::utf8proc UNKNOWN IMPORTED)
+ set_target_properties(utf8proc::utf8proc PROPERTIES
+ IMPORTED_LOCATION "${utf8proc_LIBRARIES}"
+ INTERFACE_COMPILE_OPTIONS "${PC_utf8proc_CFLAGS}"
+ INTERFACE_INCLUDE_DIRECTORIES "${utf8proc_INCLUDE_DIRS}")
+endif()
+
+include(FeatureSummary)
+set_package_properties(utf8proc PROPERTIES
+ DESCRIPTION "Library for processing UTF-8 encoded Unicode strings"
+ URL "https://julialang.org/utf8proc"
+)
+
+mark_as_advanced(utf8proc_LIBRARIES utf8proc_INCLUDE_DIRS utf8proc_VERSION)
diff --git a/src/libcommonserver/CMakeLists.txt b/src/libcommonserver/CMakeLists.txt
index 1eaa64a..148629f 100644
--- a/src/libcommonserver/CMakeLists.txt
+++ b/src/libcommonserver/CMakeLists.txt
@@ -126,8 +126,11 @@ else()
target_include_directories(${libcommonserver_NAME} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
- "/usr/local/include"
- ${CMAKE_SOURCE_DIR}/src/3rdparty/utf8proc)
+ "/usr/local/include")
+endif()
+if(NOT utf8proc_FOUND)
+ target_include_directories(${libcommonserver_NAME} PUBLIC
+ ${CMAKE_SOURCE_DIR}/src/3rdparty/utf8proc)
endif()
if(USE_OUR_OWN_SQLITE3)
@@ -160,9 +163,13 @@ elseif(APPLE)
${CORESERVICES_LIBRARY}
${APPKIT_LIBRARY})
else()
- target_link_libraries(${libcommonserver_NAME}
- utf8proc
- )
+ if(utf8proc_FOUND)
+ target_link_libraries(${libcommonserver_NAME}
+ utf8proc::utf8proc)
+ else()
+ target_link_libraries(${libcommonserver_NAME}
+ utf8proc)
+ endif()
include(ConanGetLibDirs)
get_library_dirs("OpenSSL" "openssl")
get_library_dirs("xxHash" "xxhash")
--
2.50.0