From 36a375ff4c9c55112d2fec0f74f81f20b8ccaa9b Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Thu, 19 Jun 2025 15:31:09 +0200 Subject: [PATCH] CMake: Always execute qt_find_package(MODULE) calls A qt_find_package(Foo MODULE) call is only executed if Foo_FOUND is 0, otherwise it is skipped. This is problematic for FindFoo scripts that are implemented using pkg_check_modules calls which specify a that matches the package name (Foo), because pkg_check_modules then sets the Foo_FOUND cache var to 1. On reconfiguration Foo_FOUND is 1, the qt_find_package call is skipped, and thus no targets are created, which can lead to 'unknown target' errors. The fact that pkg_check_modules sets a cache var, rather than a local var is a CMake issue: https://gitlab.kitware.com/cmake/cmake/-/issues/27014 One workaround would be to modify all our Find scripts to use a that does not match the package name, so the _FOUND cache var is not set. That is somewhat error prone though, and requires some effort. Until CMake changes its behavior, make sure we always run qt_find_package(MODULE) calls, even if the cache var is set as found. Pick-to: 6.10 Task-number: QTBUG-137870 Change-Id: Ifad8807fd69a65be8e338695b9002760c6d97461 Reviewed-by: Joerg Bornemann --- cmake/QtFindPackageHelpers.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/QtFindPackageHelpers.cmake b/cmake/QtFindPackageHelpers.cmake index 9143f560e2c..614fe8a9dfd 100644 --- a/cmake/QtFindPackageHelpers.cmake +++ b/cmake/QtFindPackageHelpers.cmake @@ -136,7 +136,7 @@ macro(qt_find_package) # TODO: Handle packages with components where a previous component is already found. # 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) + if ((NOT ${ARGV0}_FOUND OR arg_MODULE) AND NOT _qt_find_package_skip_find_package) # Call original function without our custom arguments. find_package(${arg_UNPARSED_ARGUMENTS}) endif()