diff options
author | Cristian Le <[email protected]> | 2025-03-26 19:10:53 +0100 |
---|---|---|
committer | Cristian Le <[email protected]> | 2025-06-27 20:29:16 +0200 |
commit | d497a2d97dc5baf71996d59157756aa3cef81797 (patch) | |
tree | 06f8e1b3041d6944eff3b06f41335d57cb1b91ac | |
parent | 2f9795aba2f1f9ca5fbcca4581b2d89fc468cf07 (diff) |
Move the plugin config special handling to TargetsPrecheck
This replaces the previous logic used in the QtPluginConfig.cmake
files, allowing now to include the plugins independent of the current
repo's dependencies. The only thing that controls whether a plugin is
being included is if the current plugin is being built or not.
Task-number: QTBUG-135233
Change-Id: I2d044eb6f6a3f36f49217eed81e799c4cfced66c
Reviewed-by: Alexandru Croitor <[email protected]>
-rw-r--r-- | cmake/QtBuildRepoHelpers.cmake | 2 | ||||
-rw-r--r-- | cmake/QtPluginConfig.cmake.in | 15 | ||||
-rw-r--r-- | cmake/QtPluginHelpers.cmake | 12 | ||||
-rw-r--r-- | cmake/QtPublicCMakeHelpers.cmake | 43 |
4 files changed, 43 insertions, 29 deletions
diff --git a/cmake/QtBuildRepoHelpers.cmake b/cmake/QtBuildRepoHelpers.cmake index 88fd8a531ff..86107179475 100644 --- a/cmake/QtBuildRepoHelpers.cmake +++ b/cmake/QtBuildRepoHelpers.cmake @@ -11,6 +11,8 @@ macro(qt_internal_project_setup) # Check for the minimum CMake version. qt_internal_require_suitable_cmake_version() qt_internal_upgrade_cmake_policies() + # Make sure QT_INTERNAL_BUILD_STANDALONE_PARTS is defined as early as possible + qt_internal_setup_standalone_parts() endmacro() macro(qt_build_internals_set_up_private_api) diff --git a/cmake/QtPluginConfig.cmake.in b/cmake/QtPluginConfig.cmake.in index 9222742d1ac..9b7ddc8ec7e 100644 --- a/cmake/QtPluginConfig.cmake.in +++ b/cmake/QtPluginConfig.cmake.in @@ -1,21 +1,6 @@ # Copyright (C) 2024 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause -include_guard(DIRECTORY) - -if(DEFINED QT_REPO_DEPENDENCIES - AND NOT QT_INTERNAL_BUILD_STANDALONE_PARTS - 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() - -@skip_internal_test_plugin@ - @PACKAGE_INIT@ cmake_minimum_required(VERSION @min_new_policy_version@...@max_new_policy_version@) diff --git a/cmake/QtPluginHelpers.cmake b/cmake/QtPluginHelpers.cmake index e5fa1ea2e2f..0d129791804 100644 --- a/cmake/QtPluginHelpers.cmake +++ b/cmake/QtPluginHelpers.cmake @@ -380,6 +380,7 @@ function(qt_internal_add_plugin target) # For test plugins we need to make sure plugins are not loaded from the Qt installation # when building standalone tests. + set(test_plugin_arg "") 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 a test" @@ -387,13 +388,7 @@ function(qt_internal_add_plugin target) "\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()" - ) + set(test_plugin_arg TEST_PLUGIN) endif() configure_package_config_file( @@ -410,8 +405,9 @@ endif()" _qt_internal_should_include_targets( TARGETS ${target} NAMESPACE ${INSTALL_CMAKE_NAMESPACE}:: + PROJECT_NAME ${PROJECT_NAME} OUT_VAR_SHOULD_SKIP __qt_${target}_skip_include_targets_file - CHECK_QT_NO_CREATE_TARGETS + ${test_plugin_arg} ) ") write_basic_package_version_file( diff --git a/cmake/QtPublicCMakeHelpers.cmake b/cmake/QtPublicCMakeHelpers.cmake index 543fa4c1aab..6c2d54cfcbc 100644 --- a/cmake/QtPublicCMakeHelpers.cmake +++ b/cmake/QtPublicCMakeHelpers.cmake @@ -1012,6 +1012,8 @@ endfunction() # TARGETS <target1> ... # NAMESPACE <str> # OUT_VAR_SHOULD_SKIP <var> +# [PROJECT_NAME <str>] +# [TEST_PLUGIN] # [CHECK_QT_NO_CREATE_TARGETS] # ) # @@ -1026,15 +1028,25 @@ endfunction() # `OUT_VAR_SHOULD_SKIP` # Output variable indicating if the `include(*Targets.cmake)` should be skipped # +# `PROJECT_NAME` +# The original project that defined the current Config.cmake file at the time of the +# generation. For now only used for plugins. +# +# `TEST_PLUGIN` +# If the module is a TEST_PLUGIN, we do additional checks based on +# `QT_BUILD_STANDALONE_TESTS` +# # `CHECK_QT_NO_CREATE_TARGETS` # Whether to check `QT_NO_CREATE_TARGETS` as a compatibility step function(_qt_internal_should_include_targets) set(option_args + TEST_PLUGIN CHECK_QT_NO_CREATE_TARGETS ) set(single_args NAMESPACE OUT_VAR_SHOULD_SKIP + PROJECT_NAME ) set(multi_args TARGETS @@ -1049,7 +1061,7 @@ function(_qt_internal_should_include_targets) endforeach() # Check for inputs that will be required in the future - foreach(check_arg IN ITEMS ) + foreach(check_arg IN ITEMS) if(NOT arg_${check_arg}) get_property(skip_warning GLOBAL PROPERTY _qt_skip_warning__qt_internal_should_include_targets @@ -1085,12 +1097,31 @@ function(_qt_internal_should_include_targets) endif() endforeach() + if(arg_PROJECT_NAME) + # Check if we are in a top-level build and which submodules will be included + if(NOT QT_INTERNAL_BUILD_STANDALONE_PARTS AND DEFINED Qt_SOURCE_DIR) + # All projects will be rebuilt so skip any include targets + set(${arg_OUT_VAR_SHOULD_SKIP} ON PARENT_SCOPE) + return() + endif() + + # Check if we are building the current project + if(NOT QT_INTERNAL_BUILD_STANDALONE_PARTS AND + PROJECT_NAME STREQUAL arg_PROJECT_NAME) + # We are currently building the project, so skip the include targets + set(${arg_OUT_VAR_SHOULD_SKIP} ON PARENT_SCOPE) + return() + endif() + + # Check if we are building the standalone tests + if(arg_TEST_PLUGIN AND QT_BUILD_STANDALONE_TESTS AND + PROJECT_NAME STREQUAL arg_PROJECT_NAME) + set(${arg_OUT_VAR_SHOULD_SKIP} ON PARENT_SCOPE) + return() + endif() + endif() + # Compatibility using the old global `QT_NO_CREATE_TARGETS` - # Currently needed for top-level builds because when a module has plugins, - # the plugins are included from the Config.cmake, before the plugin project - # is processed, so the build-time targets are not used in the - # `_qt_internal_check_multiple_inclusion` step. - # TODO: Use another method to detect if we have a project that need # TODO: Remove these once developers have reconfigured their project. if(arg_CHECK_QT_NO_CREATE_TARGETS AND QT_NO_CREATE_TARGETS) set(${arg_OUT_VAR_SHOULD_SKIP} ON PARENT_SCOPE) |