qt5base-lts/cmake/QtPluginConfig.cmake.in
Alexandru Croitor be1ee03a0f CMake: Fix auto-linking of static plugins in standalone tests
The change introduced in 98e8180e56
fixes reconfiguration issues for repositories that provide plugins
associated with modules from a different repository
(QSvgPlugin -> QtGui -> qtbase).

It does so by only loading the public Plugin CMake packages of
dependent repositories.

For executables / tests that are built as part of the current
repository, plugins are linked via a different simplified mechanism in
qt_add_internal_plugin and qt_internal_add_plugin in order to prevent
exporting link cycles between plugins and Qt modules.

This works for the majority of in-tree tests, but unfortunately breaks
static standalone tests.

For example in qtbase neither mechanism will link plugins to the
standalone tests:

 - qtbase has no repo dependencies, so the first mechanism (loading of
   public plugin packages) is skipped because we assume we are merely
   reconfiguring the main build of qtbase and we don't want to
   accidentally create duplicate plugin targets

 - because a standalone test configuration does not call
   qt_internal_add_plugin, no association is done between qt plugin
   and module and thus all tests (qt_internal_add_test ->
   qt_internal_add_executable) don't get the simplified plugin
   linking

Fix this by allowing loading of the public CMake plugin packages when
doing standalone tests. It should be safe to do so because we don't
build any plugins in this case, only tests.

Amends 98e8180e56

Pick-to: 6.1
Task-number: QTBUG-87580
Change-Id: I690a0366c73a24e7f49c65ed13cd70362c273d81
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2021-04-21 15:21:08 +02:00

30 lines
1.1 KiB
CMake

include_guard(DIRECTORY)
if(DEFINED QT_REPO_DEPENDENCIES AND NOT QT_BUILD_STANDALONE_TESTS)
# We're building a Qt repository.
# Skip this plugin if it has not been provided by one of this repo's dependencies.
string(TOLOWER "@PROJECT_NAME@" lower_case_project_name)
if(NOT lower_case_project_name IN_LIST QT_REPO_DEPENDENCIES)
return()
endif()
endif()
@PACKAGE_INIT@
cmake_minimum_required(VERSION @min_new_policy_version@...@max_new_policy_version@)
include(CMakeFindDependencyMacro)
get_filename_component(_import_prefix "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(_import_prefix "${_import_prefix}" REALPATH)
if (NOT QT_NO_CREATE_TARGETS)
# Find required dependencies, if any.
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@Dependencies.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@Dependencies.cmake")
endif()
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@Targets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@AdditionalTargetInfo.cmake")
endif()