Description: CMake: Use IMPORTED_TARGET for 3rd-party dependencies
 Fix linking for libraries and programs that use the installed library.
 Also bumps the CMake policy version to 3.7
Origin: upstream, https://github.com/rpm-software-management/createrepo_c/commit/89fa02828cdaf1c710c38bde5fcbcf59538a9cce
Author: Pietro Cerutti <gahr@gahr.ch>
Last-Update: 2025-10-05

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,4 +1,4 @@
-CMAKE_MINIMUM_REQUIRED (VERSION 2.8.12)
+CMAKE_MINIMUM_REQUIRED (VERSION 3.7)
 PROJECT (createrepo_c C)
 
 include(GNUInstallDirs)
@@ -39,13 +39,13 @@
 find_package(OpenSSL REQUIRED)
 find_package(ZLIB REQUIRED)
 
-pkg_check_modules(GLIB2 REQUIRED glib-2.0)
-pkg_check_modules(GIO REQUIRED gio-2.0)
-pkg_check_modules(GTHREAD2 REQUIRED gthread-2.0)
-pkg_check_modules(LZMA REQUIRED liblzma)
-pkg_check_modules(SQLITE3 REQUIRED sqlite3>=3.6.18)
-pkg_check_modules(RPM REQUIRED rpm)
-pkg_check_modules(ZSTD REQUIRED libzstd)
+pkg_check_modules(GLIB2 REQUIRED IMPORTED_TARGET glib-2.0)
+pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0)
+pkg_check_modules(GTHREAD2 REQUIRED IMPORTED_TARGET gthread-2.0)
+pkg_check_modules(LZMA REQUIRED IMPORTED_TARGET liblzma)
+pkg_check_modules(SQLITE3 REQUIRED IMPORTED_TARGET sqlite3>=3.6.18)
+pkg_check_modules(RPM REQUIRED IMPORTED_TARGET rpm)
+pkg_check_modules(ZSTD REQUIRED IMPORTED_TARGET libzstd)
 
 # Add include dirs
 
@@ -73,7 +73,7 @@
 # drpm
 OPTION (ENABLE_DRPM "Enable delta RPM support?" OFF)
 IF (ENABLE_DRPM)
-    pkg_check_modules(DRPM REQUIRED drpm>=0.4.0)
+    pkg_check_modules(DRPM REQUIRED IMPORTED_TARGET drpm>=0.4.0)
     include_directories (${DRPM_INCLUDE_DIRS})
     ADD_DEFINITIONS("-DCR_DELTA_RPM_SUPPORT")
 ENDIF (ENABLE_DRPM)
@@ -83,7 +83,7 @@
 
 OPTION (WITH_ZCHUNK "Build with zchunk support" ON)
 IF (WITH_ZCHUNK)
-    pkg_check_modules(ZCK REQUIRED zck)
+    pkg_check_modules(ZCK REQUIRED IMPORTED_TARGET zck)
     include_directories(${ZCK_INCLUDE_DIRS})
     SET (CMAKE_C_FLAGS          "${CMAKE_C_FLAGS} -DWITH_ZCHUNK")
     SET (CMAKE_C_FLAGS_DEBUG    "${CMAKE_C_FLAGS_DEBUG} -DWITH_ZCHUNK")
@@ -91,7 +91,7 @@
 
 OPTION (WITH_LIBMODULEMD "Build with libmodulemd support" ON)
 IF (WITH_LIBMODULEMD)
-    pkg_check_modules(LIBMODULEMD REQUIRED modulemd-2.0)
+    pkg_check_modules(LIBMODULEMD REQUIRED IMPORTED_TARGET modulemd-2.0)
     include_directories(${LIBMODULEMD_INCLUDE_DIRS})
     SET (CMAKE_C_FLAGS          "${CMAKE_C_FLAGS} -DWITH_LIBMODULEMD")
     SET (CMAKE_C_FLAGS_DEBUG    "${CMAKE_C_FLAGS_DEBUG} -DWITH_LIBMODULEMD")
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -86,18 +86,18 @@
 ADD_LIBRARY(libcreaterepo_c ${createrepo_c_library_type} ${createrepo_c_SRCS})
 TARGET_LINK_LIBRARIES(libcreaterepo_c ${BZIP2_LIBRARIES})
 TARGET_LINK_LIBRARIES(libcreaterepo_c ${CURL_LIBRARY})
-TARGET_LINK_LIBRARIES(libcreaterepo_c ${GLIB2_LIBRARIES})
-TARGET_LINK_LIBRARIES(libcreaterepo_c ${GIO_LIBRARIES})
-TARGET_LINK_LIBRARIES(libcreaterepo_c ${LIBMODULEMD_LIBRARIES})
+TARGET_LINK_LIBRARIES(libcreaterepo_c PkgConfig::GLIB2)
+TARGET_LINK_LIBRARIES(libcreaterepo_c PkgConfig::GIO)
+TARGET_LINK_LIBRARIES(libcreaterepo_c PkgConfig::LIBMODULEMD)
 TARGET_LINK_LIBRARIES(libcreaterepo_c ${LIBXML2_LIBRARIES})
-TARGET_LINK_LIBRARIES(libcreaterepo_c ${LZMA_LIBRARIES})
+TARGET_LINK_LIBRARIES(libcreaterepo_c PkgConfig::LZMA)
 TARGET_LINK_LIBRARIES(libcreaterepo_c ${OPENSSL_LIBRARIES})
-TARGET_LINK_LIBRARIES(libcreaterepo_c ${RPM_LIBRARIES})
-TARGET_LINK_LIBRARIES(libcreaterepo_c ${SQLITE3_LIBRARIES})
+TARGET_LINK_LIBRARIES(libcreaterepo_c PkgConfig::RPM)
+TARGET_LINK_LIBRARIES(libcreaterepo_c PkgConfig::SQLITE3)
 TARGET_LINK_LIBRARIES(libcreaterepo_c ${ZLIB_LIBRARY})
-TARGET_LINK_LIBRARIES(libcreaterepo_c ${ZCK_LIBRARIES})
-TARGET_LINK_LIBRARIES(libcreaterepo_c ${DRPM_LIBRARIES})
-TARGET_LINK_LIBRARIES(libcreaterepo_c ${ZSTD_LIBRARIES})
+TARGET_LINK_LIBRARIES(libcreaterepo_c PkgConfig::ZCK)
+TARGET_LINK_LIBRARIES(libcreaterepo_c PkgConfig::DRPM)
+TARGET_LINK_LIBRARIES(libcreaterepo_c PkgConfig::ZSTD)
 
 SET_TARGET_PROPERTIES(libcreaterepo_c PROPERTIES
                       OUTPUT_NAME "createrepo_c"
@@ -108,27 +108,27 @@
 ADD_EXECUTABLE(createrepo_c createrepo_c.c cmd_parser.c)
 TARGET_LINK_LIBRARIES(createrepo_c
                         libcreaterepo_c
-                        ${GLIB2_LIBRARIES}
-                        ${GTHREAD2_LIBRARIES})
+                        PkgConfig::GLIB2
+                        PkgConfig::GTHREAD2)
 
 ADD_EXECUTABLE(mergerepo_c mergerepo_c.c)
 TARGET_LINK_LIBRARIES(mergerepo_c
                         libcreaterepo_c
-                        ${GLIB2_LIBRARIES}
-                        ${GTHREAD2_LIBRARIES}
-                        ${LIBMODULEMD_LIBRARIES})
+                        PkgConfig::GLIB2
+                        PkgConfig::GTHREAD2
+                        PkgConfig::LIBMODULEMD)
 
 ADD_EXECUTABLE(modifyrepo_c modifyrepo_c.c)
 TARGET_LINK_LIBRARIES(modifyrepo_c
                         libcreaterepo_c
-                        ${GLIB2_LIBRARIES}
-                        ${GTHREAD2_LIBRARIES})
+                        PkgConfig::GLIB2
+                        PkgConfig::GTHREAD2)
 
 ADD_EXECUTABLE(sqliterepo_c sqliterepo_c.c)
 TARGET_LINK_LIBRARIES(sqliterepo_c
                         libcreaterepo_c
-                        ${GLIB2_LIBRARIES}
-                        ${GTHREAD2_LIBRARIES})
+                        PkgConfig::GLIB2
+                        PkgConfig::GTHREAD2)
 
 CONFIGURE_FILE("createrepo_c.pc.cmake" "${CMAKE_SOURCE_DIR}/src/createrepo_c.pc" @ONLY)
 CONFIGURE_FILE("version.h.in" "${CMAKE_CURRENT_SOURCE_DIR}/version.h" @ONLY)
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,61 +1,61 @@
 ADD_EXECUTABLE(test_checksum test_checksum.c)
-TARGET_LINK_LIBRARIES(test_checksum libcreaterepo_c ${GLIB2_LIBRARIES})
+TARGET_LINK_LIBRARIES(test_checksum libcreaterepo_c PkgConfig::GLIB2)
 ADD_DEPENDENCIES(tests test_checksum)
 
 ADD_EXECUTABLE(test_compression_wrapper test_compression_wrapper.c)
-TARGET_LINK_LIBRARIES(test_compression_wrapper libcreaterepo_c ${GLIB2_LIBRARIES})
+TARGET_LINK_LIBRARIES(test_compression_wrapper libcreaterepo_c PkgConfig::GLIB2)
 ADD_DEPENDENCIES(tests test_compression_wrapper)
 
 ADD_EXECUTABLE(test_load_metadata test_load_metadata.c)
-TARGET_LINK_LIBRARIES(test_load_metadata libcreaterepo_c ${GLIB2_LIBRARIES})
+TARGET_LINK_LIBRARIES(test_load_metadata libcreaterepo_c PkgConfig::GLIB2)
 ADD_DEPENDENCIES(tests test_load_metadata)
 
 ADD_EXECUTABLE(test_locate_metadata test_locate_metadata.c)
-TARGET_LINK_LIBRARIES(test_locate_metadata libcreaterepo_c ${GLIB2_LIBRARIES})
+TARGET_LINK_LIBRARIES(test_locate_metadata libcreaterepo_c PkgConfig::GLIB2)
 ADD_DEPENDENCIES(tests test_locate_metadata)
 
 ADD_EXECUTABLE(test_misc test_misc.c)
-TARGET_LINK_LIBRARIES(test_misc libcreaterepo_c ${GLIB2_LIBRARIES})
+TARGET_LINK_LIBRARIES(test_misc libcreaterepo_c PkgConfig::GLIB2)
 ADD_DEPENDENCIES(tests test_misc)
 
 ADD_EXECUTABLE(test_sqlite test_sqlite.c)
-TARGET_LINK_LIBRARIES(test_sqlite libcreaterepo_c ${GLIB2_LIBRARIES})
+TARGET_LINK_LIBRARIES(test_sqlite libcreaterepo_c PkgConfig::GLIB2)
 ADD_DEPENDENCIES(tests test_sqlite)
 
 ADD_EXECUTABLE(test_xml_file test_xml_file.c)
-TARGET_LINK_LIBRARIES(test_xml_file libcreaterepo_c ${GLIB2_LIBRARIES})
+TARGET_LINK_LIBRARIES(test_xml_file libcreaterepo_c PkgConfig::GLIB2)
 ADD_DEPENDENCIES(tests test_xml_file)
 
 ADD_EXECUTABLE(test_xml_parser_filelists test_xml_parser_filelists.c)
-TARGET_LINK_LIBRARIES(test_xml_parser_filelists libcreaterepo_c ${GLIB2_LIBRARIES})
+TARGET_LINK_LIBRARIES(test_xml_parser_filelists libcreaterepo_c PkgConfig::GLIB2)
 ADD_DEPENDENCIES(tests test_xml_parser_filelists)
 
 ADD_EXECUTABLE(test_xml_parser_repomd test_xml_parser_repomd.c)
-TARGET_LINK_LIBRARIES(test_xml_parser_repomd libcreaterepo_c ${GLIB2_LIBRARIES})
+TARGET_LINK_LIBRARIES(test_xml_parser_repomd libcreaterepo_c PkgConfig::GLIB2)
 ADD_DEPENDENCIES(tests test_xml_parser_repomd)
 
 ADD_EXECUTABLE(test_xml_parser_updateinfo test_xml_parser_updateinfo.c)
-TARGET_LINK_LIBRARIES(test_xml_parser_updateinfo libcreaterepo_c ${GLIB2_LIBRARIES})
+TARGET_LINK_LIBRARIES(test_xml_parser_updateinfo libcreaterepo_c PkgConfig::GLIB2)
 ADD_DEPENDENCIES(tests test_xml_parser_updateinfo)
 
 ADD_EXECUTABLE(test_xml_parser_main_metadata_together test_xml_parser_main_metadata_together.c)
-TARGET_LINK_LIBRARIES(test_xml_parser_main_metadata_together libcreaterepo_c ${GLIB2_LIBRARIES})
+TARGET_LINK_LIBRARIES(test_xml_parser_main_metadata_together libcreaterepo_c PkgConfig::GLIB2)
 ADD_DEPENDENCIES(tests test_xml_parser_main_metadata_together)
 
 ADD_EXECUTABLE(test_xml_dump test_xml_dump.c)
-TARGET_LINK_LIBRARIES(test_xml_dump libcreaterepo_c ${GLIB2_LIBRARIES})
+TARGET_LINK_LIBRARIES(test_xml_dump libcreaterepo_c PkgConfig::GLIB2)
 ADD_DEPENDENCIES(tests test_xml_dump)
 
 ADD_EXECUTABLE(test_xml_dump_primary test_xml_dump_primary.c)
-TARGET_LINK_LIBRARIES(test_xml_dump_primary libcreaterepo_c ${GLIB2_LIBRARIES})
+TARGET_LINK_LIBRARIES(test_xml_dump_primary libcreaterepo_c PkgConfig::GLIB2)
 ADD_DEPENDENCIES(tests test_xml_dump_primary)
 
 ADD_EXECUTABLE(test_koji test_koji.c)
-TARGET_LINK_LIBRARIES(test_koji libcreaterepo_c ${GLIB2_LIBRARIES})
+TARGET_LINK_LIBRARIES(test_koji libcreaterepo_c PkgConfig::GLIB2)
 ADD_DEPENDENCIES(tests test_koji)
 
 ADD_EXECUTABLE(test_modifyrepo_shared test_modifyrepo_shared.c)
-TARGET_LINK_LIBRARIES(test_modifyrepo_shared libcreaterepo_c ${GLIB2_LIBRARIES})
+TARGET_LINK_LIBRARIES(test_modifyrepo_shared libcreaterepo_c PkgConfig::GLIB2)
 ADD_DEPENDENCIES(tests test_modifyrepo_shared)
 
 CONFIGURE_FILE("run_tests.sh.in"  "${CMAKE_BINARY_DIR}/tests/run_tests.sh")
