cmake-gui: Install only necessary plugins for Qt 6

This commit is contained in:
Brad King
2025-10-24 21:56:42 -04:00
parent 74dec2c7fd
commit 2ae318bb5d

View File

@@ -105,32 +105,15 @@ if(CMake_INSTALL_DEPENDENCIES AND (APPLE OR WIN32))
"${${_qt_plugins_var}};\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${_qt_plugin_dest}/${_qt_plugin_file}")
endif()
endmacro()
macro(install_qt_plugins _comps _plugins_var)
foreach(_qt_comp IN LISTS ${_comps})
if(CMake_QT_MAJOR_VERSION VERSION_LESS 6)
set(_qt_module_plugins ${Qt${CMake_QT_MAJOR_VERSION}${_qt_comp}_PLUGINS})
else()
get_target_property(_qt_module_plugins Qt${CMake_QT_MAJOR_VERSION}::${_qt_comp} QT_PLUGINS)
endif()
foreach(_qt_plugin IN LISTS _qt_module_plugins)
if(CMake_QT_MAJOR_VERSION VERSION_GREATER_EQUAL 6)
# Qt6 provides the plugins as individual packages that need to be found.
find_package(Qt${CMake_QT_MAJOR_VERSION}${_qt_plugin} QUIET
PATHS ${Qt${CMake_QT_MAJOR_VERSION}${_qt_comp}_DIR})
endif()
install_qt_plugin("${_qt_plugin}" "${_plugins_var}")
endforeach()
endforeach()
endmacro()
if(APPLE)
if(CMake_QT_MAJOR_VERSION VERSION_EQUAL 5)
install_qt_plugin("Qt5::QCocoaIntegrationPlugin" QT_PLUGINS)
if(TARGET Qt5::QMacStylePlugin)
install_qt_plugin("Qt5::QMacStylePlugin" QT_PLUGINS)
endif()
else()
# FIXME: Minimize plugins for Qt6.
install_qt_plugins(QT_COMPONENTS QT_PLUGINS)
if(CMake_QT_MAJOR_VERSION VERSION_GREATER_EQUAL 6)
# Qt6 provides the plugins as individual packages that need to be found.
find_package(Qt${CMake_QT_MAJOR_VERSION}QCocoaIntegrationPlugin QUIET PATHS ${Qt${CMake_QT_MAJOR_VERSION}Gui_DIR})
find_package(Qt${CMake_QT_MAJOR_VERSION}QMacStylePlugin QUIET PATHS ${Qt${CMake_QT_MAJOR_VERSION}Widgets_DIR})
endif()
install_qt_plugin("Qt${CMake_QT_MAJOR_VERSION}::QCocoaIntegrationPlugin" QT_PLUGINS)
if(TARGET Qt${CMake_QT_MAJOR_VERSION}::QMacStylePlugin)
install_qt_plugin("Qt${CMake_QT_MAJOR_VERSION}::QMacStylePlugin" QT_PLUGINS)
endif()
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/qt.conf"
"[Paths]\nPlugins = ${_qt_plugin_dir}\n")
@@ -138,12 +121,11 @@ if(CMake_INSTALL_DEPENDENCIES AND (APPLE OR WIN32))
DESTINATION "${CMake_INSTALL_APP_DIR_SLASH}Resources"
${COMPONENT})
elseif(WIN32 AND NOT CMake_QT_STATIC_QWindowsIntegrationPlugin_LIBRARIES)
if(CMake_QT_MAJOR_VERSION VERSION_EQUAL 5)
install_qt_plugin("Qt5::QWindowsIntegrationPlugin" QT_PLUGINS)
else()
# FIXME: Minimize plugins for Qt6.
install_qt_plugins(QT_COMPONENTS QT_PLUGINS)
if(CMake_QT_MAJOR_VERSION VERSION_GREATER_EQUAL 6)
# Qt6 provides the plugins as individual packages that need to be found.
find_package(Qt${CMake_QT_MAJOR_VERSION}QWindowsIntegrationPlugin QUIET PATHS ${Qt${CMake_QT_MAJOR_VERSION}Gui_DIR})
endif()
install_qt_plugin("Qt${CMake_QT_MAJOR_VERSION}::QWindowsIntegrationPlugin" QT_PLUGINS)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/qt.conf"
"[Paths]\nPlugins = ../${_qt_plugin_dir}\n")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/qt.conf"