summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2021-08-06 18:39:04 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2021-08-10 16:51:53 +0200
commit72a1e55472d0780996cc3843039b00427b5a420b (patch)
tree062453f9999b23a86d64b0b077d34dd86d5b1891 /cmake
parent32725806c8e5182c14cdd04cf7bcce3ba4effc0f (diff)
CMake: Fix qt_find_package to work when CMP00126 is set to NEW
When CMP00126 is set to NEW, set(CACHE) doesn't remove regular variable bindings with the same name as the cache variable. This introduced an issue in qt_find_package, which called find_package(CONFIG QUIET) to try and find a package config file, but did not clean up the non-cache _FOUND variable which is automatically set to 0 by CMake if no Config file is found. Make sure to unset both the regular and cache _FOUND variables if either the package config file was not found, or if none of the provided targets found even if the Config file was found. Also move the _DIR cache variable cleaning into the same code block. Amends 4c31ce68d5367a6ec4dd3cf2f55e4b226add876d Amends 34b1c1c23cbddf67f878579bee9d10dcac29d8ca Fixes: QTBUG-95635 Pick-to: 6.2 Change-Id: I871987217526e0f0a20038a8da52625838e49488 Reviewed-by: Craig Scott <craig.scott@qt.io> Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'cmake')
-rw-r--r--cmake/QtFindPackageHelpers.cmake32
1 files changed, 20 insertions, 12 deletions
diff --git a/cmake/QtFindPackageHelpers.cmake b/cmake/QtFindPackageHelpers.cmake
index da0b19a8d5..8519922f85 100644
--- a/cmake/QtFindPackageHelpers.cmake
+++ b/cmake/QtFindPackageHelpers.cmake
@@ -86,16 +86,31 @@ macro(qt_find_package)
# in their own way. CMake has FindSQLite3.cmake and with the original
# qt_find_package(SQLite3) call it is our intention to use the cmake package
# in module mode.
- if (${ARGV0}_FOUND AND arg_PROVIDED_TARGETS)
- unset(any_target_found)
+ unset(_qt_any_target_found)
+ unset(_qt_should_unset_found_var)
+ if(${ARGV0}_FOUND AND arg_PROVIDED_TARGETS)
foreach(expected_target ${arg_PROVIDED_TARGETS})
if (TARGET ${expected_target})
- set(any_target_found TRUE)
+ set(_qt_any_target_found TRUE)
break()
endif()
endforeach()
- if(NOT any_target_found)
- unset(${ARGV0}_FOUND)
+ if(NOT _qt_any_target_found)
+ set(_qt_should_unset_found_var TRUE)
+ endif()
+ endif()
+ # If we consider the package not to be found, make sure to unset both regular
+ # and CACHE vars, otherwise CMP0126 set to NEW might cause issues with
+ # packages not being found correctly.
+ if(NOT ${ARGV0}_FOUND OR _qt_should_unset_found_var)
+ unset(${ARGV0}_FOUND)
+ unset(${ARGV0}_FOUND CACHE)
+
+ # Unset the NOTFOUND ${package}_DIR var that might have been set by the previous
+ # find_package call, to get rid of "not found" messages in the feature summary
+ # if the package is found by the next find_package call.
+ if(DEFINED CACHE{${ARGV0}_DIR} AND NOT ${ARGV0}_DIR)
+ unset(${ARGV0}_DIR CACHE)
endif()
endif()
endif()
@@ -111,13 +126,6 @@ macro(qt_find_package)
# E.g. find_package(Qt6 COMPONENTS BuildInternals) followed by
# qt_find_package(Qt6 COMPONENTS Core) doesn't end up calling find_package(Qt6Core).
if (NOT ${ARGV0}_FOUND AND NOT _qt_find_package_skip_find_package)
- # Unset the NOTFOUND ${package}_DIR var that might have been set by the previous
- # find_package call, to get rid of "not found" messagees in the feature summary
- # if the package is found by the next find_package call.
- if(DEFINED CACHE{${ARGV0}_DIR} AND NOT ${ARGV0}_DIR)
- unset(${ARGV0}_DIR CACHE)
- endif()
-
# Call original function without our custom arguments.
find_package(${arg_UNPARSED_ARGUMENTS})
endif()