Source: https://github.com/eBookProjects/uChmViewer/pull/58

From d3fecffbc959df7b8b7fa029c3575376c8f9e263 Mon Sep 17 00:00:00 2001
From: Andreas Sturmlechner <asturm@gentoo.org>
Date: Thu, 23 Oct 2025 11:34:07 +0200
Subject: [PATCH 1/2] Raise CMake minimum version to 3.16

CMake 3.31 warns about compat. for <3.10 being removed in the future. Qt6
CMake modules already require 3.16 though, so it is a good base line.

CMake 3.16 was released in 2019.

Signed-off-by: Andreas Sturmlechner <asturm@gentoo.org>
---
 CMakeLists.txt              | 2 +-
 cmake/Findlibzip.cmake      | 2 +-
 cmake/get-version.cmake     | 3 +--
 cmake/qt-aliases.cmake      | 2 +-
 cmake/use-in.cmake          | 2 +-
 lib/CMakeLists.txt          | 2 +-
 lib/libebook/CMakeLists.txt | 2 +-
 packages/CMakeLists.txt     | 2 +-
 po/CMakeLists.txt           | 2 +-
 src/CMakeLists.txt          | 2 +-
 10 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index dbc9f89..ca4e68f 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -19,7 +19,7 @@
 #                      The default is ON.
 ################################################
 
-cmake_minimum_required(VERSION 3.13)
+cmake_minimum_required(VERSION 3.16)
 
 # Project info
 project(uchmviewer HOMEPAGE_URL "https://github.com/u-235/uchmviewer")
diff --git a/cmake/Findlibzip.cmake b/cmake/Findlibzip.cmake
index 580e77a..cba1ed3 100644
--- a/cmake/Findlibzip.cmake
+++ b/cmake/Findlibzip.cmake
@@ -1,6 +1,6 @@
 # Tries to find libzip
 
-cmake_minimum_required(VERSION 3.5)
+cmake_minimum_required(VERSION 3.16)
 
 find_path(libzip_INCLUDE_DIR NAMES zip.h
     PATHS ${libzip_ROOT}
diff --git a/cmake/get-version.cmake b/cmake/get-version.cmake
index ba9e40e..675ce89 100644
--- a/cmake/get-version.cmake
+++ b/cmake/get-version.cmake
@@ -1,8 +1,7 @@
 # Getting the application version from the version.h file.
 # The result is saved in the APP_VERSION cache variables.
-# CMAKE_MATCH_n request CMake 3.9
 
-cmake_minimum_required(VERSION 3.9)
+cmake_minimum_required(VERSION 3.16)
 
 set (f_ver "src/version.h")
 
diff --git a/cmake/qt-aliases.cmake b/cmake/qt-aliases.cmake
index 0e4e0c1..1e7aae1 100644
--- a/cmake/qt-aliases.cmake
+++ b/cmake/qt-aliases.cmake
@@ -31,7 +31,7 @@
 #
 ################################################################################
 
-cmake_minimum_required(VERSION 3.13)
+cmake_minimum_required(VERSION 3.16)
 
 ############################
 #  Core macros             #
diff --git a/cmake/use-in.cmake b/cmake/use-in.cmake
index 3691e99..1341bc2 100644
--- a/cmake/use-in.cmake
+++ b/cmake/use-in.cmake
@@ -3,7 +3,7 @@
 # Copyright (c) 2022 Nick Egorrov
 ########################################
 
-cmake_minimum_required(VERSION 3.5)
+cmake_minimum_required(VERSION 3.16)
 
 #[==============================[
 Attempts to set the cache variable to ON when building for a specific OS.
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index ce560d0..7cbc530 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -1,5 +1,5 @@
 
-cmake_minimum_required(VERSION 3.5)
+cmake_minimum_required(VERSION 3.16)
 
 if (${USE_STATIC_CHMLIB})
     set(CHMLIB_SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/CHMLib/src)
diff --git a/lib/libebook/CMakeLists.txt b/lib/libebook/CMakeLists.txt
index bdc132e..3b7a48b 100644
--- a/lib/libebook/CMakeLists.txt
+++ b/lib/libebook/CMakeLists.txt
@@ -1,5 +1,5 @@
 
-cmake_minimum_required(VERSION 3.5)
+cmake_minimum_required(VERSION 3.16)
 
 # Project files
 set(CPP_SOURCES
diff --git a/packages/CMakeLists.txt b/packages/CMakeLists.txt
index 53e71bd..5e9d5de 100644
--- a/packages/CMakeLists.txt
+++ b/packages/CMakeLists.txt
@@ -1,5 +1,5 @@
 
-cmake_minimum_required(VERSION 3.5)
+cmake_minimum_required(VERSION 3.16)
 
 if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
     install(FILES freedesktop/uchmviewer.desktop DESTINATION ${APP_DEF_INSTALL_DIR})
diff --git a/po/CMakeLists.txt b/po/CMakeLists.txt
index 32f4b4a..7af790c 100644
--- a/po/CMakeLists.txt
+++ b/po/CMakeLists.txt
@@ -1,6 +1,6 @@
 # Create and install translation files.
 
-cmake_minimum_required(VERSION 3.5)
+cmake_minimum_required(VERSION 3.16)
 
 set(CATALOG_NAME uchmviewer)
 # The languages.txt file contains a list of locales.
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 9e1c7e5..49c7bfc 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,5 +1,5 @@
 
-cmake_minimum_required(VERSION 3.5)
+cmake_minimum_required(VERSION 3.16)
 # Need to include generated files.
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 
-- 
2.51.1


From 97fab8d74068936adeaf79bc31839e8a2c0666e7 Mon Sep 17 00:00:00 2001
From: Andreas Sturmlechner <asturm@gentoo.org>
Date: Thu, 23 Oct 2025 11:56:57 +0200
Subject: [PATCH 2/2] Do not expand variables beforehand

See also:
https://invent.kde.org/plasma/libplasma/-/merge_requests/267
https://cmake.org/cmake/help/latest/command/if.html#variable-expansion
https://cmake.org/cmake/help/latest/policy/CMP0054.html#policy:CMP0054

Signed-off-by: Andreas Sturmlechner <asturm@gentoo.org>
---
 CMakeLists.txt          | 10 +++++-----
 lib/CMakeLists.txt      |  4 ++--
 packages/CMakeLists.txt |  4 ++--
 po/CMakeLists.txt       |  2 +-
 src/CMakeLists.txt      |  6 +++---
 5 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index ca4e68f..b6bc021 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -49,7 +49,7 @@ find_package(libzip REQUIRED)
 set(APP_QT_MIN_VERSION 5.0)
 set(APP_QT_MODULES Core Network PrintSupport Widgets Xml)
 # Modules for WebKit or WebEngine.
-if (${USE_WEBENGINE})
+if (USE_WEBENGINE)
     set(APP_QT_MIN_VERSION 5.9)
     list(APPEND APP_QT_MODULES WebEngineWidgets)
     target_link_libraries(extra INTERFACE Qt::WebEngineWidgets)
@@ -73,25 +73,25 @@ endif ()
 
 set(QT Qt${QT_VERSION_MAJOR})
 # Since Qt 6 QTextCodec moved in the Qt 5 Core Compat module.
-if (${QT_VERSION_MAJOR} GREATER_EQUAL 6)
+if (QT_VERSION_MAJOR GREATER_EQUAL 6)
     list(APPEND APP_QT_MODULES Core5Compat)
     target_link_libraries(extra INTERFACE ${QT}::Core5Compat)
 endif ()
 
-if (${USE_DBUS})
+if (USE_DBUS)
     list(APPEND APP_QT_MODULES DBus)
     target_link_libraries(extra INTERFACE Qt::DBus)
     target_compile_definitions(extra INTERFACE USE_DBUS)
 endif ()
 
-if (${USE_MAC_APP})
+if (USE_MAC_APP)
     target_compile_definitions(extra INTERFACE USE_MAC_APP)
 endif ()
 
 # Now we know all the required Qt modules.
 find_package(${QT} REQUIRED ${APP_QT_MODULES})
 
-if (${USE_KF5})
+if (USE_KF5)
     # Needed by find_package(KF5) below.
     find_package(ECM REQUIRED)
     list(APPEND CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 7cbc530..5a12a5d 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -1,10 +1,10 @@
 
 cmake_minimum_required(VERSION 3.16)
 
-if (${USE_STATIC_CHMLIB})
+if (USE_STATIC_CHMLIB)
     set(CHMLIB_SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/CHMLib/src)
 
-    if (EXISTS ${CHMLIB_SRC_DIR}/chm_lib.h)
+    if (EXISTS CHMLIB_SRC_DIR/chm_lib.h)
         add_library(chmlib STATIC
             ${CHMLIB_SRC_DIR}/chm_lib.c
             ${CHMLIB_SRC_DIR}/chm_lib.h
diff --git a/packages/CMakeLists.txt b/packages/CMakeLists.txt
index 5e9d5de..46a5aea 100644
--- a/packages/CMakeLists.txt
+++ b/packages/CMakeLists.txt
@@ -1,7 +1,7 @@
 
 cmake_minimum_required(VERSION 3.16)
 
-if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
+if (CMAKE_SYSTEM_NAME MATCHES "Linux")
     install(FILES freedesktop/uchmviewer.desktop DESTINATION ${APP_DEF_INSTALL_DIR})
     install(DIRECTORY freedesktop/icons/ DESTINATION ${APP_ICONS_INSTALL_DIR})
 elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND USE_MACOS_BUNDLE)
@@ -26,7 +26,7 @@ if (USE_DEPLOY_RUNTIME)
         install(FILES $<TARGET_FILE:chm> DESTINATION ${APP_BIN_INSTALL_DIR})
     endif ()
 
-    if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
+    if (CMAKE_SYSTEM_NAME MATCHES "Windows")
         # Copying runtime dependencies for Windows deployment
         # See https://doc.qt.io/qt-5/windows-deployment.html
         set(QT_DEPLOY_DIR ${CMAKE_CURRENT_BINARY_DIR}/qt-deploy)
diff --git a/po/CMakeLists.txt b/po/CMakeLists.txt
index 7af790c..57e6b82 100644
--- a/po/CMakeLists.txt
+++ b/po/CMakeLists.txt
@@ -38,7 +38,7 @@ endif ()
 if (USE_GETTEXT)
     foreach (LANG ${LANGUAGES})
         set(CATALOG ${CMAKE_CURRENT_SOURCE_DIR}/${CATALOG_NAME}_${LANG}.po)
-        if(EXISTS ${CATALOG})
+        if(EXISTS "${CATALOG}")
             file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${LANG}/LC_MESSAGES)
             set(GMO_FILE ${CMAKE_CURRENT_BINARY_DIR}/${LANG}/LC_MESSAGES/${CATALOG_NAME}.mo)
             list(APPEND GMO_LIST ${GMO_FILE})
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 49c7bfc..f0128b4 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -76,7 +76,7 @@ set(UIS
     window_browser.ui
     )
 
-if (${USE_WEBENGINE})
+if (USE_WEBENGINE)
     list(APPEND CPP_SOURCES
         qtwebengine/viewwindow.cpp
         qtwebengine/viewwindow.h
@@ -94,13 +94,13 @@ else ()
     list(APPEND MOC_HEADERS qtwebkit/viewwindow.h)
 endif ()
 
-if (${USE_DBUS})
+if (USE_DBUS)
     list(APPEND CPP_SOURCES dbus_interface.cpp dbus_interface.h)
     list(APPEND MOC_HEADERS dbus_interface.h)
 endif ()
 
 # Mac OS specific
-if (${USE_MAC_APP})
+if (USE_MAC_APP)
     list(APPEND CPP_SOURCES uchmviewerapp.cpp uchmviewerapp.h)
     list(APPEND MOC_HEADERS uchmviewerapp.h)
 endif ()
-- 
2.51.1

