From 0d4b18109630751a0e646376c3565f0befeed0fa Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@ycbcr.xyz>
Date: Mon, 16 Dec 2024 11:46:16 +0100
Subject: [PATCH] cmake: export the necessary library in the pkg-config file

That includes gnutls on Linux if it's used.
---
 CMakeLists.txt        | 8 ++++++++
 cmake/libnfs.pc.cmake | 2 +-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1b94d2e3..86e0845c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -155,6 +155,14 @@ install(FILES cmake/FindNFS.cmake
         DESTINATION ${INSTALL_CMAKE_DIR})
 
 # handle pc-config files
+set(PKG_LIBLIST "")
+foreach(LIB ${SYSTEM_LIBRARIES})
+  if(IS_ABSOLUTE ${LIB} AND EXISTS ${LIB})
+    list(APPEND PKG_LIBLIST "${LIB}")
+  else()
+    list(APPEND PKG_LIBLIST "-l${LIB}")
+  endif()
+endforeach()
 configure_file(cmake/libnfs.pc.cmake
                ${CMAKE_CURRENT_BINARY_DIR}/libnfs.pc @ONLY)
 
diff --git a/cmake/libnfs.pc.cmake b/cmake/libnfs.pc.cmake
index 8a4e11e1..783c2e37 100644
--- a/cmake/libnfs.pc.cmake
+++ b/cmake/libnfs.pc.cmake
@@ -10,5 +10,5 @@ Description: libnfs is a client library for accessing NFS shares over a network.
 Version: @PROJECT_VERSION@
 Requires:
 Conflicts:
-Libs: -L${libdir} -lnfs
+Libs: -L${libdir} -lnfs @PKG_LIBLIST@
 Cflags: -I${includedir}
