Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.8.0
-
None
-
Ubuntu 22.04, GCC 12.3, CMake 3.22, Qt 6.8, ninja generator
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
- relates to
-
QTBUG-130757 Calling find_pacakge(Qt) in a specific directory scope and using the targets in sibling scopes can lead to issues
- Open