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

Qt CMake packages should not create targets if dependencies are not met

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 6.3.0 Alpha
    • 6.2.1
    • Build System: CMake
    • None
    • f04dbdfc97f88260f312da325efd60170450671a (qt/qtbase/dev) c3a1cdde082aeedc2c8c009ef3d7a31c0e630f33 (qt/qtbase/6.2)

    Description

      Currently, if an optional dependency is found but it doesn't have all its dependencies satisfied, it will still create imported targets.

      # Find required dependencies, if any.
      if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/Qt6GuiDependencies.cmake")
          include("${CMAKE_CURRENT_LIST_DIR}/Qt6GuiDependencies.cmake")
      endif()
      # ....
      if (NOT QT_NO_CREATE_TARGETS)
          include("${CMAKE_CURRENT_LIST_DIR}/Qt6GuiTargets.cmake")
      

      Checking for the existence of those targets is then not enough to be sure that the package is found.

      E.g. QtGui depends on QtDBus. If the Qt6DBus package is not found, and Gui was mentioned in find_package() as an OPTIONAL component, Qt6Gui_FOUND will be False, but the Qt6::Gui target will still be created.

      All our Qt repo top-level CMakeLists.txt usually check for target existence after find_package calls to determine which subdirectories of the repo to build.
      This can cause issues if some subset of targets are made available, but not all of them.

      Originally reported as an issue for qtdatavis3d after the rpath-link fixes added an additional package dependency on DBus for Gui.
      https://codereview.qt-project.org/c/qt/qtbase/+/377189
      https://codereview.qt-project.org/c/qt/qtbase/+/377916

      [   28s] CMake Warning at /usr/share/cmake/Modules/CMakeFindDependencyMacro.cmake:47 (find_package):
      [   28s]   Found package configuration file:
      [   28s]
      [   28s]     /usr/lib64/cmake/Qt6Gui/Qt6GuiConfig.cmake
      [   28s]
      [   28s]   but it set Qt6Gui_FOUND to FALSE so package "Qt6Gui" is considered to be
      [   28s]   NOT FOUND.  Reason given by package:
      [   28s]
      [   28s]   Qt6Gui could not be found because dependency Qt6DBus could not be found.
      [   28s]
      [   28s] Call Stack (most recent call first):
      [   28s]   /usr/lib64/cmake/Qt6/QtPublicDependencyHelpers.cmake:14 (find_dependency)
      [   28s]   /usr/lib64/cmake/Qt6OpenGL/Qt6OpenGLDependencies.cmake:91 (_qt_internal_find_dependencies)
      [   28s]   /usr/lib64/cmake/Qt6OpenGL/Qt6OpenGLConfig.cmake:50 (include)
      [   28s]   /usr/lib64/cmake/Qt6/Qt6Config.cmake:187 (find_package)
      [   28s]   CMakeLists.txt:12 (find_package)
      [   28s]
      [   28s]
      [   28s] CMake Warning at /usr/lib64/cmake/Qt6/Qt6Config.cmake:187 (find_package):
      [   28s]   Found package configuration file:
      [   28s]
      [   28s]     /usr/lib64/cmake/Qt6OpenGL/Qt6OpenGLConfig.cmake
      [   28s]
      [   28s]   but it set Qt6OpenGL_FOUND to FALSE so package "Qt6OpenGL" is considered to
      [   28s]   be NOT FOUND.  Reason given by package:
      [   28s]
      [   28s]   Qt6OpenGL could not be found because dependency Qt6Gui could not be found.
      [   28s]
      [   28s] Call Stack (most recent call first):
      [   28s]   CMakeLists.txt:12 (find_package)
      [   28s]
      [   28s]
      [   28s] CMake Warning at /usr/lib64/cmake/Qt6/Qt6Config.cmake:236 (message):
      [   28s]   Failed to find Qt component "OpenGL".
      [   28s]
      [   28s]   Expected Config file at "/usr/lib64/cmake/Qt6OpenGL/Qt6OpenGLConfig.cmake"
      [   28s]   exists
      [   28s]
      [   28s] Call Stack (most recent call first):
      [   28s]   CMakeLists.txt:12 (find_package)
      [   28s]
      [   28s]
      [   28s] -- Could NOT find Qt6DBus (missing: Qt6DBus_DIR)
      
      ....
      
      [   31s] -- Configuring done
      [   31s] CMake Error at /usr/lib64/cmake/Qt6Core/Qt6CoreMacros.cmake:2214 (add_library):
      [   31s]   Target "DataVisualization" links to target "Qt6::QmlModels" but the target
      [   31s]   was not found.  Perhaps a find_package() call is missing for an IMPORTED
      [   31s]   target, or an ALIAS target is missing?
      [   31s] Call Stack (most recent call first):
      [   31s]   /usr/lib64/cmake/Qt6/QtModuleHelpers.cmake:108 (_qt_internal_add_library)
      [   31s]   src/datavisualization/CMakeLists.txt:1 (qt_internal_add_module)
      

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              alexandru.croitor Alexandru Croitor
              alexandru.croitor Alexandru Croitor
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes