diff options
Diffstat (limited to 'cmake/QtPublicPluginHelpers.cmake')
-rw-r--r-- | cmake/QtPublicPluginHelpers.cmake | 93 |
1 files changed, 82 insertions, 11 deletions
diff --git a/cmake/QtPublicPluginHelpers.cmake b/cmake/QtPublicPluginHelpers.cmake index dec3f15222..7087c31234 100644 --- a/cmake/QtPublicPluginHelpers.cmake +++ b/cmake/QtPublicPluginHelpers.cmake @@ -1,5 +1,5 @@ # Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +# SPDX-License-Identifier: BSD-3-Clause # Gets the qt plugin type of the given plugin into out_var_plugin_type. # Also sets out_var_has_plugin_type to TRUE or FALSE depending on whether the plugin type was found. @@ -39,22 +39,32 @@ endfunction() # # The conditions are based on the various properties set in qt_import_plugins. -# All the TARGET_PROPERTY genexes are evaluated in the context of the currently linked target. +# All the TARGET_PROPERTY genexes are evaluated in the context of the currently linked target, +# unless the TARGET argument is given. # # The genex is saved into out_var. function(__qt_internal_get_static_plugin_condition_genex plugin_target_unprefixed out_var) + set(options) + set(oneValueArgs TARGET) + set(multiValueArgs) + cmake_parse_arguments(arg "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) set(plugin_target "${QT_CMAKE_EXPORT_NAMESPACE}::${plugin_target_unprefixed}") set(plugin_target_versionless "Qt::${plugin_target_unprefixed}") get_target_property(_plugin_type "${plugin_target}" QT_PLUGIN_TYPE) + set(target_infix "") + if(arg_TARGET) + set(target_infix "${arg_TARGET},") + endif() + set(_default_plugins_are_enabled - "$<NOT:$<STREQUAL:$<GENEX_EVAL:$<TARGET_PROPERTY:QT_DEFAULT_PLUGINS>>,0>>") - set(_manual_plugins_genex "$<GENEX_EVAL:$<TARGET_PROPERTY:QT_PLUGINS>>") - set(_no_plugins_genex "$<GENEX_EVAL:$<TARGET_PROPERTY:QT_NO_PLUGINS>>") + "$<NOT:$<STREQUAL:$<GENEX_EVAL:$<TARGET_PROPERTY:${target_infix}QT_DEFAULT_PLUGINS>>,0>>") + set(_manual_plugins_genex "$<GENEX_EVAL:$<TARGET_PROPERTY:${target_infix}QT_PLUGINS>>") + set(_no_plugins_genex "$<GENEX_EVAL:$<TARGET_PROPERTY:${target_infix}QT_NO_PLUGINS>>") # Plugin genex marker for prl processing. set(_is_plugin_marker_genex "$<BOOL:QT_IS_PLUGIN_GENEX>") @@ -81,7 +91,7 @@ function(__qt_internal_get_static_plugin_condition_genex ">," # Excludes both plugins targeted by EXCLUDE_BY_TYPE and not included in # INCLUDE_BY_TYPE. - "$<STREQUAL:,$<GENEX_EVAL:$<TARGET_PROPERTY:QT_PLUGINS_${_plugin_type}>>>" + "$<STREQUAL:,$<GENEX_EVAL:$<TARGET_PROPERTY:${target_infix}QT_PLUGINS_${_plugin_type}>>>" ">" ) @@ -90,7 +100,7 @@ function(__qt_internal_get_static_plugin_condition_genex "$<IN_LIST:" "${plugin_target}," "$<GENEX_EVAL:" - "$<TARGET_PROPERTY:QT_PLUGINS_${_plugin_type}>" + "$<TARGET_PROPERTY:${target_infix}QT_PLUGINS_${_plugin_type}>" ">" ">" ) @@ -98,7 +108,7 @@ function(__qt_internal_get_static_plugin_condition_genex "$<IN_LIST:" "${plugin_target_versionless}," "$<GENEX_EVAL:" - "$<TARGET_PROPERTY:QT_PLUGINS_${_plugin_type}>" + "$<TARGET_PROPERTY:${target_infix}QT_PLUGINS_${_plugin_type}>" ">" ">" ) @@ -106,7 +116,7 @@ function(__qt_internal_get_static_plugin_condition_genex # No point in linking the plugin initialization source file into static libraries. The # initialization symbol will be discarded by the linker when the static lib is linked into an # executable or shared library, because nothing is referencing the global static symbol. - set(type_genex "$<TARGET_PROPERTY:TYPE>") + set(type_genex "$<TARGET_PROPERTY:${target_infix}TYPE>") set(no_static_genex "$<NOT:$<STREQUAL:${type_genex},STATIC_LIBRARY>>") # Complete condition that defines whether a static plugin is linked @@ -177,7 +187,7 @@ function(__qt_internal_get_plugin_import_macro plugin_target out_var) set(class_name "${class_name_prefixed}") endif() - set(${out_var} "Q_IMPORT_PLUGIN(${class_name})" PARENT_SCOPE) + set(${out_var} "Q_IMPORT_PLUGIN(${class_name})\n" PARENT_SCOPE) endfunction() function(__qt_internal_get_plugin_include_prelude out_var) @@ -308,6 +318,25 @@ function(__qt_internal_collect_plugin_init_libraries plugin_targets out_var) set("${out_var}" "${plugin_inits_to_link}" PARENT_SCOPE) endfunction() +# Collect a list of genexes to deploy plugin libraries. +function(__qt_internal_collect_plugin_library_files target plugin_targets out_var) + set(library_files "") + + foreach(plugin_target ${plugin_targets}) + set(plugin_target_versioned "${QT_CMAKE_EXPORT_NAMESPACE}::${plugin_target}") + __qt_internal_get_static_plugin_condition_genex( + "${plugin_target}" + plugin_condition + TARGET ${target} + ) + + set(target_genex "$<${plugin_condition}:${plugin_target_versioned}>") + list(APPEND library_files "$<$<BOOL:${target_genex}>:$<TARGET_FILE:${target_genex}>>") + endforeach() + + set("${out_var}" "${library_files}" PARENT_SCOPE) +endfunction() + # Collects all plugin targets discovered by walking the dependencies of ${target}. # # Walks immediate dependencies and their transitive dependencies. @@ -387,6 +416,46 @@ function(__qt_internal_collect_plugin_targets_from_dependencies_of_plugins targe set("${out_var}" "${plugin_targets}" PARENT_SCOPE) endfunction() +# Generate plugin information files for deployment +# +# Arguments: +# OUT_PLUGIN_TARGETS - Variable name to store the plugin targets that were collected with +# __qt_internal_collect_plugin_targets_from_dependencies. +function(__qt_internal_generate_plugin_deployment_info target) + set(no_value_options "") + set(single_value_options "OUT_PLUGIN_TARGETS") + set(multi_value_options "") + cmake_parse_arguments(PARSE_ARGV 0 arg + "${no_value_options}" "${single_value_options}" "${multi_value_options}" + ) + + __qt_internal_collect_plugin_targets_from_dependencies("${target}" plugin_targets) + if(NOT "${arg_OUT_PLUGIN_TARGETS}" STREQUAL "") + set("${arg_OUT_PLUGIN_TARGETS}" "${plugin_targets}" PARENT_SCOPE) + endif() + + get_target_property(marked_for_deployment ${target} _qt_marked_for_deployment) + if(NOT marked_for_deployment) + return() + endif() + + __qt_internal_collect_plugin_library_files(${target} "${plugin_targets}" plugins_files) + set(plugins_files "$<FILTER:${plugins_files},EXCLUDE,^$>") + + _qt_internal_get_deploy_impl_dir(deploy_impl_dir) + set(file_path "${deploy_impl_dir}/${target}-plugins") + get_cmake_property(is_multi_config GENERATOR_IS_MULTI_CONFIG) + if(is_multi_config) + string(APPEND file_path "-$<CONFIG>") + endif() + string(APPEND file_path ".cmake") + + file(GENERATE + OUTPUT ${file_path} + CONTENT "set(__QT_DEPLOY_PLUGINS ${plugins_files})" + ) +endfunction() + # Main logic of finalizer mode. function(__qt_internal_apply_plugin_imports_finalizer_mode target) # Process a target only once. @@ -395,6 +464,9 @@ function(__qt_internal_apply_plugin_imports_finalizer_mode target) return() endif() + __qt_internal_generate_plugin_deployment_info(${target} + OUT_PLUGIN_TARGETS plugin_targets) + # By default if the project hasn't explicitly opted in or out, use finalizer mode. # The precondition for this is that qt_finalize_target was called (either explicitly by the user # or auto-deferred by CMake 3.19+). @@ -408,7 +480,6 @@ function(__qt_internal_apply_plugin_imports_finalizer_mode target) return() endif() - __qt_internal_collect_plugin_targets_from_dependencies("${target}" plugin_targets) __qt_internal_collect_plugin_init_libraries("${plugin_targets}" init_libraries) __qt_internal_collect_plugin_libraries("${plugin_targets}" plugin_libraries) |