Alexandru Croitor 15178c9919 CMake: Conditionally pass PATHS to FindWrapHelper package lookup
The setup:
- build Qt with '-static -qt-zlib'
- configure a user project with plain cmake and -DQt6_DIR pointing to
  the Qt6 package

In this case, the implicit find_dependency(BundledZlib) call will
fail with:

CMake Error at lib/cmake/Qt6/QtFindWrapHelper.cmake:120 (message):
  Can't find Qt6::BundledZLIB.
Call Stack (most recent call first):
  lib/cmake/Qt6/FindWrapZLIB.cmake:6 (qt_find_package_system_or_bundled)
  cmake/share/cmake-3.31/Modules/CMakeFindDependencyMacro.cmake:76
    (find_package)
  lib/cmake/Qt6/QtPublicDependencyHelpers.cmake:36 (find_dependency)
  lib/cmake/Qt6Core/Qt6CoreDependencies.cmake:39
    (_qt_internal_find_third_party_dependencies)
  lib/cmake/Qt6Core/Qt6CoreConfig.cmake:42 (include)
  lib/cmake/Qt6/Qt6Config.cmake:233 (find_package)
  CMakeLists.txt:7 (find_package)

For example it would fail for the rasterwindow example configured with:
 cmake ~/qtbase/examples/gui/rasterwindow \
   -DQt6_DIR=$HOME/builds/dev-mac-static/qtbase/lib/cmake/Qt6

The failure happens because we don't pass any additional paths to the
find_package call that looks for BundledZlib, as opposed to how we do
it for module packages.

The project configuration does not fail if it is configured with any
of the following variables:
- Qt6_ROOT or
- CMAKE_PREFIX_PATH or
- the Qt generated toolchain file.

That's because these implicitly add relevant paths where to look for
Qt packages.

This came up in qtdeclarative RunCMake CI tests, where we only pass
Qt6_DIR to the test projects. It didn't come up in qtbase, because
none of the current qtbase RunCMake tests try to find Qt6Core.

To fix this particular case, conditionally pass the same paths that
Qt6Config.cmake uses when looking for module packages, to the
find_package call that looks for the bundled target.

We do it conditionally for bundled targets only, because for system
libraries we want to default looking for the module
FindWrapSystemFoo.cmake files.

Add a RunCMake test which will try to find a few Qt modules solely
based on having only Qt6_DIR set.

Pick-to: 6.8 6.9
Change-Id: I4d4e548f4c10370c4964ab8968b5772e26855dd4
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2025-05-15 03:08:03 +02:00
..
2024-11-05 14:36:16 +01:00

This directory contains autotests and benchmarks based on Qt Test. In order
to run the autotests reliably, you need to configure a desktop to match the
test environment that these tests are written for.

Linux X11:

   * The user must be logged in to an active desktop; you can't run the
     autotests without a valid DISPLAY that allows X11 connections.

   * The tests are run against a KDE3 or KDE4 desktop.

   * Window manager uses "click to focus", and not "focus follows mouse". Many
     tests move the mouse cursor around and expect this to not affect focus
     and activation.

   * Disable "click to activate", i.e., when a window is opened, the window
     manager should automatically activate it (give it input focus) and not
     wait for the user to click the window.