cmake: implement default qpa plugin behavior for static builds

This is done by adding a DEFAULT_IF argument to add_qt_plugin, which accepts
if-evaluated expressions.

e.g.

    add_qt_plugin(myplugin
	DEFAULT_IF ${foo} STREQUAL ${bar}
        ...
    )

so that this mechanism can be reused later if necessary.

Change-Id: I7eba9adaaa28e55a4f0f94cf206e868b990027e6
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Jean-Michaël Celerier 2019-07-05 11:55:05 +02:00
parent 5769e1a2f6
commit a5b78a3660
13 changed files with 40 additions and 10 deletions

View File

@ -1449,7 +1449,7 @@ function(add_qt_plugin target)
qt_parse_all_arguments(arg "add_qt_plugin" "STATIC;EXCEPTIONS"
"TYPE;CLASS_NAME;OUTPUT_DIRECTORY;INSTALL_DIRECTORY;ARCHIVE_INSTALL_DIRECTORY"
"${__default_private_args};${__default_public_args}" ${ARGN})
"${__default_private_args};${__default_public_args};DEFAULT_IF" ${ARGN})
set(output_directory_default "${QT_BUILD_DIR}/${INSTALL_PLUGINSDIR}/${arg_TYPE}")
@ -1501,7 +1501,15 @@ function(add_qt_plugin target)
set_property(TARGET "${qt_module}" APPEND PROPERTY QT_PLUGINS "${target}")
endif()
set_property(TARGET "${target}" APPEND PROPERTY EXPORT_PROPERTIES "QT_PLUGIN_CLASS_NAME;QT_MODULE")
set(_default_plugin 1)
if (DEFINED arg_DEFAULT_IF)
if (NOT ${arg_DEFAULT_IF})
set(_default_plugin 0)
endif()
endif()
set_property(TARGET "${target}" PROPERTY QT_DEFAULT_PLUGIN "${_default_plugin}")
set_property(TARGET "${target}" APPEND PROPERTY EXPORT_PROPERTIES "QT_PLUGIN_CLASS_NAME;QT_MODULE;QT_DEFAULT_PLUGIN")
extend_target("${target}"
SOURCES ${arg_SOURCES}

View File

@ -3,7 +3,7 @@
if(NOT @BUILD_SHARED_LIBS@)
set(_module_target "@INSTALL_CMAKE_NAMESPACE@::@QT_MODULE@")
set(_default_plugins_genex "$<GENEX_EVAL:$<TARGET_PROPERTY:QT_DEFAULT_PLUGINS>>")
set(_default_plugins_are_enabled "$<GENEX_EVAL:$<TARGET_PROPERTY:QT_DEFAULT_PLUGINS>>")
set(_manual_plugins_genex "$<GENEX_EVAL:$<TARGET_PROPERTY:QT_PLUGINS>>")
set(_no_plugins_genex "$<GENEX_EVAL:$<TARGET_PROPERTY:QT_NO_PLUGINS>>")
@ -15,17 +15,17 @@ if(NOT @BUILD_SHARED_LIBS@)
continue()
endif()
set(_user_specified_genex "$<IN_LIST:${_plugin_target},${_manual_plugins_genex}>")
set(_plugin_is_default "$<TARGET_PROPERTY:${_plugin_target},QT_DEFAULT_PLUGIN>")
set(_plugin_is_not_blacklisted "$<NOT:$<IN_LIST:${_plugin_target},${_no_plugins_genex}>>")
set(_plugin_is_whitelisted "$<IN_LIST:${_plugin_target},${_manual_plugins_genex}>")
string(CONCAT _plugin_condition
"$<BOOL:$<OR:"
# Add this plugin if it\'s in the list of manual plugins or plugins for the type
"${_user_specified_genex},"
# Add this plugin if the default plugins haven't been disabled, the module of the plug-in
# is either empty or equal to the module name, and the user hasn't blacklisted it
"${_plugin_is_whitelisted},"
"$<AND:"
"${_default_plugins_genex},"
"$<NOT:$<IN_LIST:${_plugin_target},${_no_plugins_genex}>>"
"${_default_plugins_are_enabled},"
"${_plugin_is_default},"
"${_plugin_is_not_blacklisted}"
">"
">>"
)

View File

@ -38,6 +38,18 @@ define_property(TARGET
For instance, Sql for qsqlite"
)
define_property(TARGET
PROPERTY
QT_DEFAULT_PLUGIN
BRIEF_DOCS
"Indicates whether a plug-in is added by default."
FULL_DOCS
"This is a property on Qt plug-ins.
It is mainly used to indicate if a plug-in should be added
to the default set of plug-ins when building a static app -
for instance, which QPA should be linked."
)
define_property(GLOBAL
PROPERTY
QT_KNOWN_PLUGINS

View File

@ -6,6 +6,7 @@
add_qt_plugin(qtforandroid
TYPE platforms
DEFAULT_IF ${QT_QPA_DEFAULT_PLATFORM} MATCHES android # special case
SOURCES
androidcontentfileengine.cpp androidcontentfileengine.h
androiddeadlockprotector.cpp androiddeadlockprotector.h

View File

@ -9,6 +9,7 @@ qt_find_package(Cups PROVIDED_TARGETS Cups::Cups)
add_qt_plugin(qcocoa
TYPE platforms
DEFAULT_IF ${QT_QPA_DEFAULT_PLATFORM} MATCHES cocoa # special case
CLASS_NAME QCocoaIntegrationPlugin
SOURCES
main.mm

View File

@ -80,6 +80,7 @@ extend_target(EglFSDeviceIntegration CONDITION QT_FEATURE_opengl
add_qt_plugin(qeglfs
TYPE platforms
CLASS_NAME QEglFSIntegrationPlugin
DEFAULT_IF ${QT_QPA_DEFAULT_PLATFORM} MATCHES eglfs # special case
SOURCES
qeglfsmain.cpp
DEFINES

View File

@ -7,6 +7,7 @@
add_qt_plugin(qlinuxfb
TYPE platforms
CLASS_NAME QLinuxFbIntegrationPlugin
DEFAULT_IF ${QT_QPA_DEFAULT_PLATFORM} MATCHES linuxfb # special case
SOURCES
main.cpp
qlinuxfbintegration.cpp qlinuxfbintegration.h

View File

@ -7,6 +7,7 @@
add_qt_plugin(qminimal
TYPE platforms
CLASS_NAME QMinimalIntegrationPlugin
DEFAULT_IF ${QT_QPA_DEFAULT_PLATFORM} MATCHES minimal # special case
SOURCES
main.cpp
qminimalbackingstore.cpp qminimalbackingstore.h

View File

@ -7,6 +7,7 @@
add_qt_plugin(qminimalegl
TYPE platforms
CLASS_NAME QMinimalEglIntegrationPlugin
DEFAULT_IF ${QT_QPA_DEFAULT_PLATFORM} MATCHES minimalegl # special case
SOURCES
main.cpp
qminimaleglintegration.cpp qminimaleglintegration.h

View File

@ -7,6 +7,7 @@
add_qt_plugin(qoffscreen
TYPE platforms
CLASS_NAME QOffscreenIntegrationPlugin
DEFAULT_IF ${QT_QPA_DEFAULT_PLATFORM} MATCHES offscreen # special case
SOURCES
main.cpp
qoffscreencommon.cpp qoffscreencommon.h

View File

@ -7,6 +7,7 @@
add_qt_plugin(qvnc
TYPE platforms
CLASS_NAME QVncIntegrationPlugin
DEFAULT_IF ${QT_QPA_DEFAULT_PLATFORM} MATCHES vnc # special case
SOURCES
main.cpp
qvnc.cpp qvnc_p.h

View File

@ -7,6 +7,7 @@
add_qt_plugin(qwindows
TYPE platforms
CLASS_NAME QWindowsIntegrationPlugin
DEFAULT_IF ${QT_QPA_DEFAULT_PLATFORM} MATCHES windows # special case
SOURCES
main.cpp
qtwindowsglobal.h

View File

@ -190,6 +190,7 @@ extend_target(XcbQpa CONDITION QT_FEATURE_fontconfig AND QT_FEATURE_xcb_native_p
add_qt_plugin(qxcb
TYPE platforms
CLASS_NAME QXcbIntegrationPlugin
DEFAULT_IF ${QT_QPA_DEFAULT_PLATFORM} MATCHES xcb # special case
SOURCES
qxcbmain.cpp
DEFINES