From 3b3d491e374394eb6da6db34620c0f7759927ef3 Mon Sep 17 00:00:00 2001 From: Alexey Edelev Date: Fri, 28 Apr 2023 17:27:48 +0200 Subject: [PATCH] Add the list of previously searched packages to qt_find_package When configuring Qt the second time it might be situation that the set of qt_find_package calls is changed. One of the scenarios is the changing of the submodule list that needs to be built in top-level builds. It's also applicable for Qt features that lead to extra package lookup in the unlocked subdirectories. Current approach collects packages that were found at the previous run and skips search of the packages that are missing. The problem is that it also skips packages even if qt_find_package was not called at previous run. QT_INTERNAL_PREVIOUSLY_SEARCHED_PACKAGES collects all packages that were actually searched at the previous run to make sure that qt_find_package don't skip packages that appeared at second run only. Note: Described scenarios may still have other issues and are not tested well. Fixes: QTBUG-113244 Change-Id: Iab36060a28fbaa16a3b3bdba67795955c496b0c3 Reviewed-by: Joerg Bornemann Reviewed-by: Amir Masoud Abdol (cherry picked from commit 18ef6849d23e4c55cc311205151b1215222b5e96) Reviewed-by: Qt Cherry-pick Bot --- cmake/QtBuildInformation.cmake | 2 +- .../QtBuildInternalsConfig.cmake | 2 +- cmake/QtFindPackageHelpers.cmake | 17 +++++++++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/cmake/QtBuildInformation.cmake b/cmake/QtBuildInformation.cmake index 9d8a11cb2d9..6929f9134ef 100644 --- a/cmake/QtBuildInformation.cmake +++ b/cmake/QtBuildInformation.cmake @@ -109,7 +109,7 @@ from the build directory") set(QT_INTERNAL_BUILD_INSTRUCTIONS_SHOWN "TRUE" CACHE STRING "" FORCE) if(QT_SUPERBUILD) - qt_internal_save_previously_found_packages() + qt_internal_save_previously_visited_packages() endif() endfunction() diff --git a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake index 7a69a635016..5dfcbd36675 100644 --- a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake +++ b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake @@ -562,7 +562,7 @@ macro(qt_build_repo_end) endif() if(NOT QT_SUPERBUILD) - qt_internal_save_previously_found_packages() + qt_internal_save_previously_visited_packages() endif() if(QT_INTERNAL_FRESH_REQUESTED) diff --git a/cmake/QtFindPackageHelpers.cmake b/cmake/QtFindPackageHelpers.cmake index 407e41b8332..15651b31167 100644 --- a/cmake/QtFindPackageHelpers.cmake +++ b/cmake/QtFindPackageHelpers.cmake @@ -41,10 +41,13 @@ macro(qt_find_package) # Due to this behavior being different from what general CMake projects expect, it is only # done for -developer-builds. if(QT_INTERNAL_PREVIOUSLY_FOUND_PACKAGES AND - NOT "${ARGV0}" IN_LIST QT_INTERNAL_PREVIOUSLY_FOUND_PACKAGES) + NOT "${ARGV0}" IN_LIST QT_INTERNAL_PREVIOUSLY_FOUND_PACKAGES + AND "${ARGV0}" IN_LIST QT_INTERNAL_PREVIOUSLY_SEARCHED_PACKAGES) set(_qt_find_package_skip_find_package TRUE) endif() + set_property(GLOBAL APPEND PROPERTY _qt_previously_searched_packages "${ARGV0}") + if(QT_DEBUG_QT_FIND_PACKAGE AND ${ARGV0}_FOUND AND arg_PROVIDED_TARGETS) set(_qt_find_package_skip_find_package TRUE) foreach(qt_find_package_target_name ${arg_PROVIDED_TARGETS}) @@ -221,7 +224,7 @@ endmacro() # Only applies to -developer-builds by default. # Can also be opted in or opted out via QT_INTERNAL_SAVE_PREVIOUSLY_FOUND_PACKAGES. # Opting out will need two reconfigurations to take effect. -function(qt_internal_save_previously_found_packages) +function(qt_internal_save_previously_visited_packages) if(DEFINED QT_INTERNAL_SAVE_PREVIOUSLY_FOUND_PACKAGES) set(should_save "${QT_INTERNAL_SAVE_PREVIOUSLY_FOUND_PACKAGES}") else() @@ -235,6 +238,7 @@ function(qt_internal_save_previously_found_packages) if(NOT should_save) # When the value is flipped to OFF, remove any previously saved packages. unset(QT_INTERNAL_PREVIOUSLY_FOUND_PACKAGES CACHE) + unset(QT_INTERNAL_PREVIOUSLY_SEARCHED_PACKAGES CACHE) return() endif() @@ -244,6 +248,15 @@ function(qt_internal_save_previously_found_packages) set(QT_INTERNAL_PREVIOUSLY_FOUND_PACKAGES "${_qt_previously_found_packages}" CACHE INTERNAL "List of CMake packages found during configuration using qt_find_package.") endif() + + get_property(_qt_previously_searched_packages GLOBAL PROPERTY _qt_previously_searched_packages) + if(_qt_previously_searched_packages) + list(REMOVE_DUPLICATES _qt_previously_searched_packages) + set(QT_INTERNAL_PREVIOUSLY_SEARCHED_PACKAGES + "${_qt_previously_searched_packages}" CACHE INTERNAL + "List of CMake packages searched during configuration using qt_find_package." + ) + endif() endfunction() # Return qmake library name for the given target, e.g. return "vulkan" for "Vulkan::Vulkan".