From d4755a76385f7168f2571be3e10604579c51e505 Mon Sep 17 00:00:00 2001
From: Martchus <martchus@gmx.net>
Date: Tue, 26 Apr 2022 20:16:31 +0200
Subject: [PATCH 10/17] Allow using properties of PkgConfig targets for glib2
 to handle deps of static glib2

Change-Id: I37d20256d17ae9cc0775e32aa479f1e433ece908
---
 .../find-modules/FindGLIB2.cmake              | 22 +++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/cmake/3rdparty/extra-cmake-modules/find-modules/FindGLIB2.cmake b/cmake/3rdparty/extra-cmake-modules/find-modules/FindGLIB2.cmake
index a6a16b494fd..a5da57824c9 100644
--- a/cmake/3rdparty/extra-cmake-modules/find-modules/FindGLIB2.cmake
+++ b/cmake/3rdparty/extra-cmake-modules/find-modules/FindGLIB2.cmake
@@ -52,7 +52,7 @@
 #=============================================================================
 
 find_package(PkgConfig QUIET)
-pkg_check_modules(PC_GLIB2 QUIET glib-2.0)
+pkg_check_modules(PC_GLIB2 QUIET glib-2.0 IMPORTED_TARGET)
 
 find_path(GLIB2_INCLUDE_DIRS
           NAMES glib.h
@@ -64,14 +64,14 @@ find_library(GLIB2_LIBRARIES
              HINTS ${PC_GLIB2_LIBDIR}
 )
 
-pkg_check_modules(PC_GTHREAD2 QUIET gthread-2.0)
+pkg_check_modules(PC_GTHREAD2 QUIET gthread-2.0 IMPORTED_TARGET)
 
 find_library(GTHREAD2_LIBRARIES
              NAMES gthread-2.0
              HINTS ${PC_GTHREAD2_LIBDIR}
 )
 
-pkg_check_modules(PC_GOBJECT QUIET gobject-2.0)
+pkg_check_modules(PC_GOBJECT QUIET gobject-2.0 IMPORTED_TARGET)
 
 find_path(GLIB2_GOBJECT_INCLUDE_DIRS
           NAMES glib-object.h
@@ -83,7 +83,7 @@ find_library(GLIB2_GOBJECT_LIBRARIES
              HINTS ${PC_GOBJECT_LIBDIR}
 )
 
-pkg_check_modules(PC_GIO QUIET gio-2.0)
+pkg_check_modules(PC_GIO QUIET gio-2.0 IMPORTED_TARGET)
 
 find_path(GLIB2_GIO_INCLUDE_DIRS
           NAMES gio/gio.h
@@ -160,6 +160,20 @@ mark_as_advanced(GLIB2_INCLUDE_DIRS GLIB2_INCLUDE_DIR
                  GLIB2_GIO_INCLUDE_DIRS GLIB2_GIO_INCLUDE_DIR
                  GLIB2_GIO_LIBRARIES GLIB2_GIO_LIBRARY)
 
+option(GLIB2_USE_PKG_CONFIG "Use properties from PkgConfig targets" OFF)
+if(GLIB2_USE_PKG_CONFIG)
+  foreach(TARGET_NAME GLIB2 GOBJECT GIO)
+    if(TARGET "GLIB2::${TARGET_NAME}")
+      foreach(PROP_NAME INTERFACE_LINK_OPTIONS INTERFACE_LINK_LIBRARIES
+                        INTERFACE_COMPILE_OPTIONS INTERFACE_COMPILE_DEFINITIONS
+                        INTERFACE_INCLUDE_DIRECTORIES)
+        get_target_property(PROP_VAL "PkgConfig::PC_${TARGET_NAME}" "${PROP_NAME}")
+        set_target_properties("GLIB2::${TARGET_NAME}" PROPERTIES "${PROP_NAME}" "${PROP_VAL}")
+      endforeach()
+    endif()
+  endforeach()
+endif()
+
 include(FeatureSummary)
 set_package_properties(GLIB2 PROPERTIES
   URL "https://wiki.gnome.org/Projects/GLib"
-- 
2.44.0

