cmake: Link static plugins even in shared Qt builds
It's perfectly possible to create static plugins in an otherwise shared Qt build, but the logic to import these plugins into applications was assuming a fully static Qt build. We now handle this more granularly. This works for in-source tools and tests as well, which don't go through the same CMake machinery for plugins as user projects do. The only case that does not currently work is in-source examples, as they don't share any of the plugin machinery with neither Qt internal tools/tests or user project, but that's a bigger architectural issue that goes beyond this change. Change-Id: Ie00a97b02ac38ec4affadc447a3bfd0ec7d9c69a Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
parent
5a4e5c62af
commit
f68e2c92cc
@ -193,8 +193,7 @@ function(qt_internal_add_executable name)
|
|||||||
add_dependencies("${name}" qpa_default_plugins)
|
add_dependencies("${name}" qpa_default_plugins)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(NOT BUILD_SHARED_LIBS)
|
# For static plugins, we need to explicitly link to plugins we want to be
|
||||||
# For static builds, we need to explicitly link to plugins we want to be
|
|
||||||
# loaded with the executable. User projects get that automatically, but
|
# loaded with the executable. User projects get that automatically, but
|
||||||
# for tools built as part of Qt, we can't use that mechanism because it
|
# for tools built as part of Qt, we can't use that mechanism because it
|
||||||
# would pollute the targets we export as part of an install and lead to
|
# would pollute the targets we export as part of an install and lead to
|
||||||
@ -281,5 +280,5 @@ Q_IMPORT_PLUGIN($<JOIN:${class_names},)\nQ_IMPORT_PLUGIN(>)
|
|||||||
"$<TARGET_PROPERTY:${lib},_qt_initial_repo_plugins>"
|
"$<TARGET_PROPERTY:${lib},_qt_initial_repo_plugins>"
|
||||||
"$<TARGET_PROPERTY:${lib},${prop_prefix}_plugins>")
|
"$<TARGET_PROPERTY:${lib},${prop_prefix}_plugins>")
|
||||||
endforeach()
|
endforeach()
|
||||||
endif()
|
|
||||||
endfunction()
|
endfunction()
|
||||||
|
@ -203,6 +203,9 @@ function(qt_internal_add_plugin target)
|
|||||||
endif()
|
endif()
|
||||||
get_target_property(is_imported_qt_module ${qt_module_target} IMPORTED)
|
get_target_property(is_imported_qt_module ${qt_module_target} IMPORTED)
|
||||||
|
|
||||||
|
set(plugin_target_versioned "${QT_CMAKE_EXPORT_NAMESPACE}::${target}")
|
||||||
|
get_target_property(type "${plugin_target_versioned}" TYPE)
|
||||||
|
if(type STREQUAL STATIC_LIBRARY)
|
||||||
# Associate plugin with its Qt module when both are both built in the same repository.
|
# Associate plugin with its Qt module when both are both built in the same repository.
|
||||||
# Check that by comparing the PROJECT_NAME of each.
|
# Check that by comparing the PROJECT_NAME of each.
|
||||||
# This covers auto-linking of the majority of plugins to executables and in-tree tests.
|
# This covers auto-linking of the majority of plugins to executables and in-tree tests.
|
||||||
@ -268,6 +271,7 @@ function(qt_internal_add_plugin target)
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
# Change the configuration file install location for qml plugins into the Qml package location.
|
# Change the configuration file install location for qml plugins into the Qml package location.
|
||||||
if(plugin_type_escaped STREQUAL "qml_plugin" AND TARGET "${INSTALL_CMAKE_NAMESPACE}::Qml")
|
if(plugin_type_escaped STREQUAL "qml_plugin" AND TARGET "${INSTALL_CMAKE_NAMESPACE}::Qml")
|
||||||
|
@ -263,12 +263,16 @@ function(__qt_internal_collect_plugin_libraries plugin_targets out_var)
|
|||||||
set(plugins_to_link "")
|
set(plugins_to_link "")
|
||||||
|
|
||||||
foreach(plugin_target ${plugin_targets})
|
foreach(plugin_target ${plugin_targets})
|
||||||
|
set(plugin_target_versioned "${QT_CMAKE_EXPORT_NAMESPACE}::${plugin_target}")
|
||||||
|
get_target_property(type "${plugin_target_versioned}" TYPE)
|
||||||
|
if(NOT type STREQUAL STATIC_LIBRARY)
|
||||||
|
continue()
|
||||||
|
endif()
|
||||||
|
|
||||||
__qt_internal_get_static_plugin_condition_genex(
|
__qt_internal_get_static_plugin_condition_genex(
|
||||||
"${plugin_target}"
|
"${plugin_target}"
|
||||||
plugin_condition)
|
plugin_condition)
|
||||||
|
|
||||||
set(plugin_target_versioned "${QT_CMAKE_EXPORT_NAMESPACE}::${plugin_target}")
|
|
||||||
|
|
||||||
list(APPEND plugins_to_link "$<${plugin_condition}:${plugin_target_versioned}>")
|
list(APPEND plugins_to_link "$<${plugin_condition}:${plugin_target_versioned}>")
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
@ -282,6 +286,12 @@ function(__qt_internal_collect_plugin_init_libraries plugin_targets out_var)
|
|||||||
set(plugin_inits_to_link "")
|
set(plugin_inits_to_link "")
|
||||||
|
|
||||||
foreach(plugin_target ${plugin_targets})
|
foreach(plugin_target ${plugin_targets})
|
||||||
|
set(plugin_target_versioned "${QT_CMAKE_EXPORT_NAMESPACE}::${plugin_target}")
|
||||||
|
get_target_property(type "${plugin_target_versioned}" TYPE)
|
||||||
|
if(NOT type STREQUAL STATIC_LIBRARY)
|
||||||
|
continue()
|
||||||
|
endif()
|
||||||
|
|
||||||
__qt_internal_get_static_plugin_condition_genex(
|
__qt_internal_get_static_plugin_condition_genex(
|
||||||
"${plugin_target}"
|
"${plugin_target}"
|
||||||
plugin_condition)
|
plugin_condition)
|
||||||
@ -376,11 +386,6 @@ endfunction()
|
|||||||
|
|
||||||
# Main logic of finalizer mode.
|
# Main logic of finalizer mode.
|
||||||
function(__qt_internal_apply_plugin_imports_finalizer_mode target)
|
function(__qt_internal_apply_plugin_imports_finalizer_mode target)
|
||||||
# Nothing to do in a shared build.
|
|
||||||
if(QT6_IS_SHARED_LIBS_BUILD)
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Process a target only once.
|
# Process a target only once.
|
||||||
get_target_property(processed ${target} _qt_plugin_finalizer_imports_processed)
|
get_target_property(processed ${target} _qt_plugin_finalizer_imports_processed)
|
||||||
if(processed)
|
if(processed)
|
||||||
@ -461,8 +466,10 @@ function(__qt_internal_include_plugin_packages target)
|
|||||||
|
|
||||||
list(APPEND "QT_ALL_PLUGINS_FOUND_BY_FIND_PACKAGE_${__plugin_type}" "${plugin_target}")
|
list(APPEND "QT_ALL_PLUGINS_FOUND_BY_FIND_PACKAGE_${__plugin_type}" "${plugin_target}")
|
||||||
|
|
||||||
# Auto-linkage should be set up only for static library builds.
|
# Auto-linkage should be set up only for static plugins.
|
||||||
if(NOT QT6_IS_SHARED_LIBS_BUILD)
|
set(plugin_target_versioned "${QT_CMAKE_EXPORT_NAMESPACE}::${plugin_target}")
|
||||||
|
get_target_property(type "${plugin_target_versioned}" TYPE)
|
||||||
|
if(type STREQUAL STATIC_LIBRARY)
|
||||||
__qt_internal_add_static_plugin_linkage("${plugin_target}" "${_module_target}")
|
__qt_internal_add_static_plugin_linkage("${plugin_target}" "${_module_target}")
|
||||||
__qt_internal_add_static_plugin_import_macro(
|
__qt_internal_add_static_plugin_import_macro(
|
||||||
"${plugin_target}" ${_module_target} "${target}")
|
"${plugin_target}" ${_module_target} "${target}")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user