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
Pick-to: 6.5
Change-Id: Iab36060a28fbaa16a3b3bdba67795955c496b0c3
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Amir Masoud Abdol <amir.abdol@qt.io>
This commit is contained in:
Alexey Edelev 2023-04-28 17:27:48 +02:00
parent f18842dc38
commit 18ef6849d2
3 changed files with 17 additions and 4 deletions

View File

@ -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()

View File

@ -582,7 +582,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)

View File

@ -50,10 +50,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})
@ -230,7 +233,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()
@ -244,6 +247,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()
@ -253,6 +257,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".