Fix TLS support for static builds when using Qt 6.2.0 or newer

This Qt release "pluginized" the backends for TLS support so we need to
make sure to link against at least one TLS plugin since all of my
applications which use Qt Network expect TLS to work.
This commit is contained in:
Martchus 2021-10-02 19:39:51 +02:00
parent b51ac8c322
commit 9b559b153c
3 changed files with 37 additions and 0 deletions

View File

@ -110,6 +110,15 @@ foreach (MODULE ${IMPORTED_KF_MODULES})
endif ()
endforeach ()
# enable TLS support by default when using Qt Network (relevant for linking against static plugin)
if (NOT DEFINED TLS_SUPPORT)
if (Network IN_LIST QT_MODULES OR Network IN_LIST IMPORTED_QT_MODULES)
set(TLS_SUPPORT ON)
else ()
set(TLS_SUPPORT OFF)
endif ()
endif ()
# built-in platform, imageformat and iconengine plugins when linking statically against Qt
if (STATIC_LINKAGE AND META_PROJECT_IS_APPLICATION)
message(STATUS "Linking application ${META_PROJECT_NAME} against Qt plugins because static linkage is enabled.")
@ -149,6 +158,32 @@ if (STATIC_LINKAGE AND META_PROJECT_IS_APPLICATION)
endif ()
endif ()
# ensure a TLS plugin is built-in when available and when creating an app using Qt Network - required since Qt 6.2.0
# which "pluginized" TLS support
if (TLS_SUPPORT)
set(KNOWN_TLS_PLUGINS ${META_TLS_PLUGINS} SchannelBackend TlsBackendOpenSSL)
set(USED_TLS_PLUGINS)
foreach (TLS_PLUGIN ${KNOWN_TLS_PLUGINS})
if (TARGET "${QT_PACKAGE_PREFIX}::Q${TLS_PLUGIN}Plugin")
use_qt_module(
PREFIX
"${QT_PACKAGE_PREFIX}"
MODULE
Network
PLUGINS
${TLS_PLUGIN}
ONLY_PLUGINS)
list(APPEND USED_TLS_PLUGINS "${TLS_PLUGIN}")
break() # one plugin is sufficient
endif ()
endforeach ()
# allow importing TLS plugins via qtconfig.h
if (USED_TLS_PLUGINS)
list_to_string(" " "\\\n Q_IMPORT_PLUGIN(Q" ")" "${USED_TLS_PLUGINS}" USED_TLS_PLUGINS_ARRAY)
endif ()
endif ()
# ensure all available widget style plugins are built-in when creating a Qt Widgets application - required since Qt 5.10
# because the styles have been "pluginized" (see commit 4f3249f)
set(KNOWN_WIDGET_STYLE_PLUGINS WindowsVistaStyle MacStyle AndroidStyle)

View File

@ -12,5 +12,6 @@
#cmakedefine IMAGE_FORMAT_SUPPORT
#define IMPORT_IMAGE_FORMAT_PLUGINS @IMAGE_FORMAT_SUPPORT_ARRAY@
#define IMPORT_WIDGET_STYLE_PLUGINS @WIDGET_STYLE_PLUGINS_ARRAY@
#define IMPORT_TLS_PLUGINS @USED_TLS_PLUGINS_ARRAY@
@META_CUSTOM_QT_CONFIG@
#endif // @META_PROJECT_VARNAME_UPPER@_QT_CONFIG

View File

@ -23,6 +23,7 @@ IMPORT_IMAGE_FORMAT_PLUGINS
#endif
IMPORT_WIDGET_STYLE_PLUGINS
#endif // defined(QT_UTILITIES_GUI_QTWIDGETS) || defined(QT_UTILITIES_GUI_QTQUICK)
IMPORT_TLS_PLUGINS
#endif // QT_STATIC
#endif // MISC_UTILS_IMPORT_PLUGIN_H