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

Using qt_add_library and qt_add_executable causes failure to link Qt6::QuickControls2 (and probably other imported targets)

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P3: Somewhat important
    • None
    • 6.4.2, 6.5.0
    • Build System: CMake
    • None
    • Windows

    Description

      Consider the following structure

      client
      --gui
      ----CMakeLists.txt <- static library "myproject_gui" created with qt_add_library, links Qt6::Quick and Qt6::QuickControls2 with PUBLIC scope
      ----...
      --main
      ----CMakeLists.txt <- application "myproject_main" created with qt_add_executable, links "myproject_gui"
      ----...

      With MSVC Qt 6.4.2 this just fails to configure:

      CMake Error at D:/Qt/6.4.2/msvc2019_64/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:617 (get_target_property):
        get_target_property() called with non-existent target
        "Qt6::QuickControls2".
      Call Stack (most recent call first):
        D:/Qt/6.4.2/msvc2019_64/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:705 (_qt_internal_finalize_executable)
        D:/Qt/6.4.2/msvc2019_64/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:562:EVAL:1 (qt6_finalize_target)
        client/main/CMakeLists.txt:DEFERRED

      With MSVC Qt 6.5.0 this gives warning:

      CMake Warning at D:/Qt/6.5.0/msvc2019_64/lib/cmake/Qt6/QtPublicWalkLibsHelpers.cmake:284 (message):
        When trying to collect dependencies of target 'myproject_main', the
        non-existent target 'Qt6::QuickControls2' was encountered.  This can likely
        be fixed by moving the find_package call that pulls in
        'Qt6::QuickControls2' to the scope of directory
        'D:/Users/Vladimir/src/qt-singleton-example/myproject/client/main' or
        higher.  This warning can be silenced by setting
        QT_SILENCE_MISSING_DEPENDENCY_TARGET_WARNING to ON.
      Call Stack (most recent call first):
        D:/Qt/6.5.0/msvc2019_64/lib/cmake/Qt6/QtPublicWalkLibsHelpers.cmake:320 (__qt_internal_print_missing_dependency_target_warning)
        D:/Qt/6.5.0/msvc2019_64/lib/cmake/Qt6/QtPublicPluginHelpers.cmake:347 (__qt_internal_collect_all_target_dependencies)
        D:/Qt/6.5.0/msvc2019_64/lib/cmake/Qt6/QtPublicPluginHelpers.cmake:432 (__qt_internal_collect_plugin_targets_from_dependencies)
        D:/Qt/6.5.0/msvc2019_64/lib/cmake/Qt6/QtPublicPluginHelpers.cmake:467 (__qt_internal_generate_plugin_deployment_info)
        D:/Qt/6.5.0/msvc2019_64/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:658 (__qt_internal_apply_plugin_imports_finalizer_mode)
        D:/Qt/6.5.0/msvc2019_64/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:709 (_qt_internal_finalize_executable)
        D:/Qt/6.5.0/msvc2019_64/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:564:EVAL:1 (qt6_finalize_target)
        client/main/CMakeLists.txt:DEFERRED

      Instead of following this nonsense advice I just reverted to CMake's standard add_library/add_executable and everything worked just fine, no warnings or errors with both 6.4.2 and 6.5.0.

      In our production code we had same problems when linking Boost::container target to myproject_gui, we had to use ${Boost_CONTAINER_LIBRARY} variable, but it didn't work with Quick Controls because Qt6::QuickControls2 CMake target doesn't provide useful variables.

      Full example project: myproject.zip

      Attachments

        Issue Links

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

          Activity

            People

              qtbuildsystem Qt Build System Team
              vserdyuk Vladimir Serdyuk
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes