CMake: Fix warning about ShaderTools not being found when building examples

When building examples in-tree in a prefix build, we set QT_NO_CREATE_TARGETS
to TRUE and that causes find_package(QtFoo) calls in example projects
not to define targets.

If the targets were not found previously as part of the find_package calls
in qtdeclarative/CMakeLists.txt, this generates warnings like

 CMake Warning at lib/cmake/Qt6/Qt6Config.cmake:176 (find_package):
   Found package configuration file:
     lib/cmake/Qt6ShaderTools/Qt6ShaderToolsConfig.cmake
   but it set Qt6ShaderTools_FOUND to FALSE so package "Qt6ShaderTools" is
   considered to be NOT FOUND.  Reason given by package:
   Target "Qt6::ShaderTools" was not found.  Possibly due to
   QT_NO_CREATE_TARGETS being set to TRUE and thus
    lib/cmake/Qt6ShaderTools/Qt6ShaderToolsTargets.cmake
   was not included to define the target.

To avoid the warnings, search for the target ShaderTools package as an
optional component.

Amends 0d517b553b

Pick-to: 6.2
Fixes: QTBUG-96358
Change-Id: I50c2f1516ca26c099559001e74b7e25c625be6e6
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
Alexandru Croitor 2021-09-27 14:12:25 +02:00
parent 29946505a3
commit 828cbe57a1
1 changed files with 5 additions and 0 deletions

View File

@ -35,6 +35,11 @@ if(NOT "${QT_HOST_PATH}" STREQUAL "")
set(CMAKE_FIND_ROOT_PATH ${_qt_backup_qtdeclarative_CMAKE_FIND_ROOT_PATH})
endif()
# Optionally look for the target ShaderTools package to avoid warnings
# when configuring the project to build examples in-tree in a prefix Qt build.
# See QTBUG-96358 for details.
find_package(Qt6 ${PROJECT_VERSION} CONFIG OPTIONAL_COMPONENTS ShaderTools)
# special case begin
# export QT6_ADD_QML_MODULE to this project
include(src/qml/Qt6QmlMacros.cmake)