From 7a1d063137a8e8c7758cfdb1c95f2b258cd0d0c6 Mon Sep 17 00:00:00 2001
From: "Friedrich W. H. Kossebau" <kossebau@kde.org>
Date: Tue, 14 Oct 2025 17:56:37 +0200
Subject: [PATCH] Public KDE-specific modules: set module cmake_policy

Ensures code is not affected by policies set by the including scope.
---
 kde-modules/KDECMakeSettings.cmake         | 13 ++++++++++---
 kde-modules/KDEClangFormat.cmake           |  2 ++
 kde-modules/KDEGitCommitHooks.cmake        |  2 ++
 kde-modules/KDEInstallDirs.cmake           |  2 ++
 kde-modules/KDEInstallDirs5.cmake          |  2 ++
 kde-modules/KDEInstallDirs6.cmake          |  2 ++
 kde-modules/KDEMetaInfoPlatformCheck.cmake |  2 ++
 kde-modules/KDEPackageAppTemplates.cmake   |  2 ++
 kde-modules/appstreamtest.cmake            |  2 ++
 9 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/kde-modules/KDECMakeSettings.cmake b/kde-modules/KDECMakeSettings.cmake
index 2210d37ac..dc825e02c 100644
--- a/kde-modules/KDECMakeSettings.cmake
+++ b/kde-modules/KDECMakeSettings.cmake
@@ -112,6 +112,13 @@ All ``KDE_L10N_*`` options have been deprecated since 5.102.0, as translations
 are meanwhile present inside the source code repositories.
 #]=======================================================================]
 
+# Explicitly pushing current policies on the stack, because this module
+# by its very purpose one day might also want to set policies to the caller scope
+# and consumers be asked to include using NO_POLICY_SCOPE.
+cmake_policy(PUSH)
+
+cmake_policy(VERSION 3.16)
+
 ################# RPATH handling ##################################
 
 if(NOT KDE_SKIP_RPATH_SETTINGS)
@@ -160,8 +167,6 @@ endif()
 
 find_program(APPSTREAMCLI appstreamcli)
 function(appstreamtest)
-    cmake_policy(PUSH)
-    cmake_policy(SET CMP0064 NEW) # enable TEST operator
     if(TEST appstreamtest)
         # already configured
     elseif(APPSTREAMCLI)
@@ -169,7 +174,6 @@ function(appstreamtest)
     else()
         message(STATUS "Could not set up the appstream test. appstreamcli is missing.")
     endif()
-    cmake_policy(POP)
 endfunction()
 
 if(NOT KDE_SKIP_TEST_SETTINGS)
@@ -391,3 +395,6 @@ if(NOT EXISTS ${CMAKE_SOURCE_DIR}/po AND NOT TARGET fetch-translations)
         execute_process(${fetch_commands})
     endif()
 endif()
+
+# see begin
+cmake_policy(POP)
diff --git a/kde-modules/KDEClangFormat.cmake b/kde-modules/KDEClangFormat.cmake
index cbe725fc0..40407052b 100644
--- a/kde-modules/KDEClangFormat.cmake
+++ b/kde-modules/KDEClangFormat.cmake
@@ -49,6 +49,8 @@ file in the directory with the following contents:
 Since 5.64
 #]=======================================================================]
 
+cmake_policy(VERSION 3.16)
+
 # try to find clang-format in path
 find_program(KDE_CLANG_FORMAT_EXECUTABLE clang-format)
 
diff --git a/kde-modules/KDEGitCommitHooks.cmake b/kde-modules/KDEGitCommitHooks.cmake
index 80cac9f74..ca9a664eb 100644
--- a/kde-modules/KDEGitCommitHooks.cmake
+++ b/kde-modules/KDEGitCommitHooks.cmake
@@ -51,6 +51,8 @@ Example usage:
 Since 5.79
 #]=======================================================================]
 
+cmake_policy(VERSION 3.16)
+
 # try to find clang-format in path
 find_program(KDE_CLANG_FORMAT_EXECUTABLE clang-format)
 find_program(KDE_CHECK_JSONSCHEMA_EXECUTABLE check-jsonschema)
diff --git a/kde-modules/KDEInstallDirs.cmake b/kde-modules/KDEInstallDirs.cmake
index 86c39368d..176ca054c 100644
--- a/kde-modules/KDEInstallDirs.cmake
+++ b/kde-modules/KDEInstallDirs.cmake
@@ -11,5 +11,7 @@ Compatibility wrapper around :kde-module:`KDEInstallDirs5`.
 Since 5.82.0, prior to that equivalent to :kde-module:`KDEInstallDirs5`.
 #]=======================================================================]
 
+cmake_policy(VERSION 3.16)
+
 include(${CMAKE_CURRENT_LIST_DIR}/../modules/QtVersionOption.cmake)
 include(${CMAKE_CURRENT_LIST_DIR}/KDEInstallDirs${QT_MAJOR_VERSION}.cmake)
diff --git a/kde-modules/KDEInstallDirs5.cmake b/kde-modules/KDEInstallDirs5.cmake
index 4550dd1b1..a346c4da4 100644
--- a/kde-modules/KDEInstallDirs5.cmake
+++ b/kde-modules/KDEInstallDirs5.cmake
@@ -237,6 +237,8 @@ for the prefix into a process.
 
 #]=======================================================================]
 
+cmake_policy(VERSION 3.16)
+
 include(${CMAKE_CURRENT_LIST_DIR}/KDEInstallDirsCommon.cmake)
 
 if(WIN32)
diff --git a/kde-modules/KDEInstallDirs6.cmake b/kde-modules/KDEInstallDirs6.cmake
index b71c5359f..792b5b947 100644
--- a/kde-modules/KDEInstallDirs6.cmake
+++ b/kde-modules/KDEInstallDirs6.cmake
@@ -194,6 +194,8 @@ file that allows to easily incorporate the necessary environment variables
 for the prefix into a process.
 #]=======================================================================]
 
+cmake_policy(VERSION 3.16)
+
 set(KDE_INSTALL_DIRS_NO_DEPRECATED TRUE)
 
 include(${CMAKE_CURRENT_LIST_DIR}/KDEInstallDirsCommon.cmake)
diff --git a/kde-modules/KDEMetaInfoPlatformCheck.cmake b/kde-modules/KDEMetaInfoPlatformCheck.cmake
index 7e354ddc2..e51d5861c 100644
--- a/kde-modules/KDEMetaInfoPlatformCheck.cmake
+++ b/kde-modules/KDEMetaInfoPlatformCheck.cmake
@@ -18,6 +18,8 @@ The check can be ignored by setting ``KF_IGNORE_PLATFORM_CHECK`` to ``ON``.
 Since 5.93
 #]=======================================================================]
 
+cmake_policy(VERSION 3.16)
+
 option(KF_IGNORE_PLATFORM_CHECK "Ignore the supported platform check against metainfo.yaml" OFF)
 if ("$ENV{KF_IGNORE_PLATFORM_CHECK}" STREQUAL "ON")
     message(WARNING "KF_IGNORE_PLATFORM_CHECK set to ON from the environment")
diff --git a/kde-modules/KDEPackageAppTemplates.cmake b/kde-modules/KDEPackageAppTemplates.cmake
index f377b2f34..e1244281c 100644
--- a/kde-modules/KDEPackageAppTemplates.cmake
+++ b/kde-modules/KDEPackageAppTemplates.cmake
@@ -70,6 +70,8 @@ Unless setting KDE_INSTALL_APP_TEMPLATES, this function is skipped when cross-co
 Since 5.18
 #]=======================================================================]
 
+cmake_policy(VERSION 3.16)
+
 if(NOT CMAKE_CROSSCOMPILING)
    set(default_kde_install_app_templates ON)
 else()
diff --git a/kde-modules/appstreamtest.cmake b/kde-modules/appstreamtest.cmake
index 02fd02ca5..7eb0a1d8e 100644
--- a/kde-modules/appstreamtest.cmake
+++ b/kde-modules/appstreamtest.cmake
@@ -1,3 +1,5 @@
+cmake_policy(VERSION 3.16)
+
 file(GLOB install_done "${INSTALL_FILES}")
 if (install_done)
     file(READ "${INSTALL_FILES}" out)
-- 
GitLab

