Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-95573

Decide what kind of error message to show when a REQUIRED Qt component is not found

    XMLWordPrintable

Details

    • Task
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 6.2.0 Beta2
    • Build System: CMake
    • None

    Description

      This issue is mostly to keep a place for the result of my investigation on how REQUIRED should affect package components.

      In the qt 5.15 CMake integration, the Umbrella Qt5Config.cmake file passed REQUIRED option to the find_package components call here
      https://github.com/qt/qtbase/blob/5.15.2/src/corelib/Qt5Config.cmake.in#L30

      In Qt 6.0-6.2-beta2, we do not pass it.
      https://github.com/qt/qtbase/blob/e933d71a610a951cc6af3c2ac40b97037a14bf9c/cmake/QtConfig.cmake.in#L102

      The variable is always expanded to an empty string, because it's not set. It was likely an oversight when porting the code.

      It's still a bit unclear to me, but I tend to think we should NOT pass REQUIRED to the component find_package calls, because I would expect that the umbrella project Config file should get the final say on whether a component is required. It also affects the error messages shown.

      There is also some inconsistency in how CMake itself handles COMPONENTS vs REQUIRED COMPONENTS signature. https://gitlab.kitware.com/cmake/cmake/-/issues/22513

      The following are the error messages shown with https://codereview.qt-project.org/c/qt/qtbase/+/362871 and REQUIRED not passed to the component find_package calls.

      find_package(Qt6 QUIET REQUIRED COMPONENTS OpenGL) # Qt6OpenGL_FOUND is set to FALSE manually
      
      CMake Error at /Volumes/T3/Dev/qt/qt5_cmake/worktrees/dev/qtbase/examples/widgets/painting/shared/use_lib.cmake:10 (find_package):
        Found package configuration file:
      
          /Volumes/T3/Dev/qt/qt5_cmake/builds/dev-mac/qtbase/lib/cmake/Qt6/Qt6Config.cmake
      
        but it set Qt6_FOUND to FALSE so package "Qt6" is considered to be NOT
        FOUND.  Reason given by package:
      
        Failed to find Qt component "OpenGL".
      
        Expected Config file at
        "/Volumes/T3/Dev/qt/qt5_cmake/builds/dev-mac/qtbase/lib/cmake/Qt6OpenGL/Qt6OpenGLConfig.cmake"
        exists
      
      find_package(Qt6 QUIET REQUIRED COMPONENTS NonExistent)
      
      CMake Error at /Volumes/T3/Dev/qt/qt5_cmake/worktrees/dev/qtbase/examples/widgets/painting/shared/use_lib.cmake:10 (find_package):
        Found package configuration file:
      
          /Volumes/T3/Dev/qt/qt5_cmake/builds/dev-mac/qtbase/lib/cmake/Qt6/Qt6Config.cmake
      
        but it set Qt6_FOUND to FALSE so package "Qt6" is considered to be NOT
        FOUND.  Reason given by package:
      
        Failed to find Qt component "NonExistent".
      
        Expected Config file at
        "/Volumes/T3/Dev/qt/qt5_cmake/builds/dev-mac/qtbase/lib/cmake/Qt6NonExistent/Qt6NonExistentConfig.cmake"
        does NOT exist
      

      The following are the error messages shown with https://codereview.qt-project.org/c/qt/qtbase/+/362871 and REQUIRED passed to the component find_package calls.

      find_package(Qt6 QUIET REQUIRED COMPONENTS OpenGL) # Qt6OpenGL_FOUND is set to FALSE manually
      
      CMake Error at /Volumes/T3/Dev/qt/qt5_cmake/builds/dev-mac/qtbase/lib/cmake/Qt6/Qt6Config.cmake:134 (find_package):
        Found package configuration file:
      
          /Volumes/T3/Dev/qt/qt5_cmake/builds/dev-mac/qtbase/lib/cmake/Qt6OpenGL/Qt6OpenGLConfig.cmake
      
        but it set Qt6OpenGL_FOUND to FALSE so package "Qt6OpenGL" is considered to
        be NOT FOUND.
      
      find_package(Qt6 QUIET REQUIRED COMPONENTS NonExistent)
      
      CMake Error at /Volumes/T3/Dev/qt/qt5_cmake/builds/dev-mac/qtbase/lib/cmake/Qt6/Qt6Config.cmake:134 (find_package):
        Could not find a package configuration file provided by "Qt6NonExistent"
        with any of the following names:
      
          Qt6NonExistentConfig.cmake
          qt6nonexistent-config.cmake
      
        Add the installation prefix of "Qt6NonExistent" to CMAKE_PREFIX_PATH or set
        "Qt6NonExistent_DIR" to a directory containing one of the above files.  If
        "Qt6NonExistent" provides a separate development package or SDK, be sure it
        has been installed.
      

      I'm undecided which of the error messages are more informational and would better serve users, but i'll probably keep the error messages where REQUIRED is not passed to the component find_package calls.

      Attachments

        Issue Links

          Activity

            People

              qtbuildsystem Qt Build System Team
              alexandru.croitor Alexandru Croitor
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: