Avoid creating the installed test plugins when configuring standalone tests
When configuring standalone tests with some installable plugins, these plugins land inside the actual build/install directory after build/installation. This makes imposible to configure the same standalone tests second time since the same plugin targets attempt to be created within the build tree, while they are already found by the respective find_package(<Qt Module>) call. This change introduces and uses the tests-wide qt_internal_configuring_tests variable to mark the plugins that are built within the tests build tree and disallows loading them by the find_package call when building standalone tests. The trick is simple: PluginConfig.cmake files skip plugin creation if the respective plugin is a test plugin and the standalone test project matches the plugin repo project. Also we now oblige module maintainers to mark such plugins using the TEST_PLUGIN argument of the qt_internal_add_plugin function. This is needed to prevent breakage when the exact test is build alone and the qt_internal_configuring_tests is not set. If plugin is not marked as TEST_PLUGIN and is built as part of test build tree the warning is displayed to remind the maintainer about the missing flag. Suggest to make this flag mandatory for all test plugins, and throw a FATAL_ERROR if the plugin is not marked respectively. Fixes: QTBUG-127781 Change-Id: I51f8b2f2c979911dad7c90926d841c8b8f1bb5d7 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
parent
f98fd70529
commit
40def71797
@ -709,6 +709,9 @@ macro(qt_internal_find_standalone_parts_config_files)
|
||||
endmacro()
|
||||
|
||||
macro(qt_build_tests)
|
||||
# Indicates that we are configuring tests now
|
||||
set(QT_INTERNAL_CONFIGURING_TESTS TRUE)
|
||||
|
||||
# Tests are not unity-ready.
|
||||
set(CMAKE_UNITY_BUILD OFF)
|
||||
|
||||
@ -764,6 +767,7 @@ macro(qt_build_tests)
|
||||
endif()
|
||||
|
||||
set(CMAKE_UNITY_BUILD ${QT_UNITY_BUILD})
|
||||
unset(QT_INTERNAL_CONFIGURING_TESTS)
|
||||
endmacro()
|
||||
|
||||
function(qt_compute_relative_path_from_cmake_config_dir_to_prefix)
|
||||
|
@ -12,6 +12,8 @@ if(DEFINED QT_REPO_DEPENDENCIES AND NOT QT_INTERNAL_BUILD_STANDALONE_PARTS)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@skip_internal_test_plugin@
|
||||
|
||||
@PACKAGE_INIT@
|
||||
|
||||
cmake_minimum_required(VERSION @min_new_policy_version@...@max_new_policy_version@)
|
||||
|
@ -9,6 +9,7 @@ macro(qt_internal_get_internal_add_plugin_keywords option_args single_args multi
|
||||
ALLOW_UNDEFINED_SYMBOLS
|
||||
SKIP_INSTALL
|
||||
NO_UNITY_BUILD
|
||||
TEST_PLUGIN
|
||||
${__qt_internal_sbom_optional_args}
|
||||
)
|
||||
set(${single_args}
|
||||
@ -364,6 +365,25 @@ function(qt_internal_add_plugin target)
|
||||
|
||||
qt_internal_get_min_new_policy_cmake_version(min_new_policy_version)
|
||||
qt_internal_get_max_new_policy_cmake_version(max_new_policy_version)
|
||||
|
||||
# For test plugins we need to make sure plugins are not loaded from the Qt installation
|
||||
# when building standalone tests.
|
||||
if(QT_INTERNAL_CONFIGURING_TESTS OR arg_TEST_PLUGIN)
|
||||
if(NOT arg_TEST_PLUGIN)
|
||||
message(WARNING "The installable test plugin ${target} is built as part of test"
|
||||
" suite, but is not marked as TEST_PLUGIN using the repsective argument."
|
||||
"\nThis warning will soon become an error."
|
||||
)
|
||||
endif()
|
||||
set(skip_internal_test_plugin
|
||||
"if(QT_BUILD_STANDALONE_TESTS AND \"\${PROJECT_NAME}\" STREQUAL \"${PROJECT_NAME}\")
|
||||
message(DEBUG \"Skipping loading ${target}Config.cmake during \"
|
||||
\"standalone tests run of ${PROJECT_NAME}\")
|
||||
return()
|
||||
endif()"
|
||||
)
|
||||
endif()
|
||||
|
||||
configure_package_config_file(
|
||||
"${QT_CMAKE_DIR}/QtPluginConfig.cmake.in"
|
||||
"${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}Config.cmake"
|
||||
|
Loading…
x
Reference in New Issue
Block a user