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

CMake configuration fails when transitively linking Qt::Quick when package is found in a sibling scope

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.8.0
    • Build System: CMake
    • None
    • Ubuntu 22.04, GCC 12.3, CMake 3.22, Qt 6.8, ninja generator
    • Linux/X11

    Description

      General Description

      Publicly linking Qt::Quick transitively results in a CMake configuration error "Target "Qt6::QmlIntegration" not found." unless

      find_package(Qt6 COMPONENTS Quick REQUIRED)

      is called again.

      Example

      • The attached MWE is a CMake project with two subdirectories `qtlib` and `test`
      • The CMakeLists.txt in the root directory adds the two subdirectories:
      cmake_minimum_required(VERSION 3.17)
      project(qtquicktest)
      add_subdirectory(qtlib)
      add_subdirectory(test)
      • The CMakeLists.txt in `qtlib` creates a static library that links against Qt::Quick publicly:
      find_package(Qt6 COMPONENTS Quick REQUIRED)
      add_library(qtlib STATIC qtlib.cpp)
      target_link_libraries(qtlib PUBLIC Qt::Quick) 
      • The CMakeLists.txt in `test` is supposed to add unit tests for the static library and therefore links against it:
      add_executable(test_qtlib test_qtlib.cpp)
      target_link_libraries(test_qtlib PRIVATE qtlib) 
      • Trying to configure the project results in this output:
      ~/qtquicktest/build$ cmake .. -GNinja -DCMAKE_PREFIX_PATH=/opt/Qt/6.8.0/gcc_64
      -- The C compiler identification is GNU 12.3.0
      -- The CXX compiler identification is GNU 12.3.0
      -- Detecting C compiler ABI info
      -- Detecting C compiler ABI info - done
      -- Check for working C compiler: /usr/bin/cc - skipped
      -- Detecting C compile features
      -- Detecting C compile features - done
      -- Detecting CXX compiler ABI info
      -- Detecting CXX compiler ABI info - done
      -- Check for working CXX compiler: /usr/bin/c++ - skipped
      -- Detecting CXX compile features
      -- Detecting CXX compile features - done
      -- Looking for pthread.h
      -- Looking for pthread.h - found
      -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
      -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
      -- Found Threads: TRUE  
      -- Performing Test HAVE_STDATOMIC
      -- Performing Test HAVE_STDATOMIC - Success
      -- Found WrapAtomic: TRUE  
      -- Found OpenGL: /usr/lib/x86_64-linux-gnu/libGL.so   
      -- Found WrapOpenGL: TRUE  
      -- Found XKB: /usr/lib/x86_64-linux-gnu/libxkbcommon.so (found suitable version "1.4.0", minimum required is "0.5.0") 
      -- Found WrapVulkanHeaders: /usr/include  
      -- Configuring done
      CMake Error at test/CMakeLists.txt:3 (target_link_libraries):
        Error evaluating generator expression:    $<TARGET_PROPERTY:Qt6::QmlIntegration,_qt_module_has_private_headers>  Target "Qt6::QmlIntegration" not found.
      CMake Error:
        Error evaluating generator expression:    $<TARGET_PROPERTY:Qt6::QmlIntegration,_qt_module_has_private_headers>  Target "Qt6::QmlIntegration" not found.
      -- Generating done
      CMake Generate step failed.  Build files cannot be regenerated correctly. 
      • To make it work, I have to call the find_package command in the CMakeLists.txt of the `test` directory again. This is not necessary if, instead of Qt::Quick, the static library links against another component, e.g. Qt::Gui or Qt::Core
      • I could not reproduce this behavior on Windows using MSVC 2022

      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
              phernst Philipp Ernst
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes