From 96f10766d4aea6f570d9d44903737e884f90b263 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sat, 10 Jun 2023 17:00:24 +0200 Subject: [PATCH] Enable web view support only by default if Qt WebEngine is present The web view is only an optional enhancement in my applications so having the support disabled is rather common. So for a better out-of-the-box experience when configuring my projects it makes sense not having to disable web view support explicitly if Qt WebEngine is not installed anyways. --- cmake/modules/QtConfig.cmake | 8 +------- cmake/modules/QtLinkage.cmake | 8 ++++++++ cmake/modules/QtWebViewProviderConfig.cmake | 12 +++++++++++- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/cmake/modules/QtConfig.cmake b/cmake/modules/QtConfig.cmake index 0eb1c47..cd075c4 100644 --- a/cmake/modules/QtConfig.cmake +++ b/cmake/modules/QtConfig.cmake @@ -66,10 +66,6 @@ if (IMPORTED_KF_MODULES) endif () # find and use the required Qt/KF modules -set(QT_PACKAGE_PREFIX - "Qt5" - CACHE STRING "specifies the prefix for Qt packages") -string(TOLOWER "${QT_PACKAGE_PREFIX}" QT_PACKAGE_PREFIX_LOWER) set(QT_LINGUIST_TOOLS_PACKAGE "${QT_PACKAGE_PREFIX}LinguistTools") set(QT_QMAKE_TARGET "${QT_PACKAGE_PREFIX}::qmake") foreach (MODULE ${QT_MODULES}) @@ -79,9 +75,6 @@ foreach (MODULE ${QT_MODULES}) endif () use_qt_module(PREFIX "${QT_PACKAGE_PREFIX}" MODULE "${MODULE}" ${MODULE_OPTIONS}) endforeach () -set(KF_PACKAGE_PREFIX - "KF5" - CACHE STRING "specifies the prefix for KDE Frameworks packages") foreach (MODULE ${KF_MODULES}) unset(MODULE_OPTIONS) if ("${MODULE}" IN_LIST META_PUBLIC_KF_MODULES) @@ -329,6 +322,7 @@ option(BUILTIN_TRANSLATIONS_OF_QT "enables/disables built-in translations of Qt "${BUILTIN_TRANSLATIONS}") # determine relevant Qt translation files +string(TOLOWER "${QT_PACKAGE_PREFIX}" QT_PACKAGE_PREFIX_LOWER) set(QT_TRANSLATION_FILES) set(QT_TRANSLATION_SEARCH_PATHS) query_qmake_variable_path(QT_INSTALL_TRANSLATIONS) diff --git a/cmake/modules/QtLinkage.cmake b/cmake/modules/QtLinkage.cmake index a853b48..5f1459c 100644 --- a/cmake/modules/QtLinkage.cmake +++ b/cmake/modules/QtLinkage.cmake @@ -11,6 +11,14 @@ set(QT_LINKAGE_DETERMINED ON) # include validate_visibility from c++utilities' 3rdParty module include(3rdParty) +# allow switching the Qt and KDE Frameworks version +set(QT_PACKAGE_PREFIX + "Qt5" + CACHE STRING "specifies the prefix for Qt packages") +set(KF_PACKAGE_PREFIX + "KF5" + CACHE STRING "specifies the prefix for KDE Frameworks packages") + # determine the minimum Qt version if (NOT META_QT_VERSION) if (META_QT5_VERSION) diff --git a/cmake/modules/QtWebViewProviderConfig.cmake b/cmake/modules/QtWebViewProviderConfig.cmake index 345c3e0..8cdb036 100644 --- a/cmake/modules/QtWebViewProviderConfig.cmake +++ b/cmake/modules/QtWebViewProviderConfig.cmake @@ -6,9 +6,19 @@ if (TARGET_CONFIG_DONE) message(FATAL_ERROR "Can not include QtWebViewProviderConfig module when targets are already configured.") endif () +# include required modules +include(QtLinkage) + +# check whether Qt WebEngine is present +find_package("${QT_PACKAGE_PREFIX}WebEngineWidgets" "${META_QT_VERSION}") +set(WEBVIEW_PROVIDER_DEFAULT "none") +if ("${${QT_PACKAGE_PREFIX}WebEngineWidgets_FOUND}") + set(WEBVIEW_PROVIDER_DEFAULT "webengine") +endif () + # configure the specified web view provider set(WEBVIEW_PROVIDER - "webengine" + "${WEBVIEW_PROVIDER_DEFAULT}" CACHE STRING "specifies the web view provider: webengine (default), webkit or none") if (WEBVIEW_PROVIDER STREQUAL "webkit") set(WEBVIEW_PROVIDER WebKitWidgets)