CMake: Add missing check for tool target promotion

We shouldn't try to promote tool targets if they were not created
when Qt6FooTools_FOUND is FALSE due to missing dependencies and
Qt6FooToolsTargets.cmake is not included.

Add a check for Qt6FooTools_FOUND to prevent errors like:

 CMake Error at lib/cmake/Qt6/QtPublicTargetHelpers.cmake:257
 (get_property):
  get_property could not find TARGET Qt6::qtprotobufgen.  Perhaps it
  has not yet been created.

Pick-to: 6.5 6.6
Change-Id: Ie26db637d4d8ef682a0ada5ea36ef0e8ceced008
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
Alexandru Croitor 2023-07-04 18:34:54 +02:00
parent 0e56dd2746
commit 3f6041a24f

View File

@ -348,7 +348,7 @@ function(qt_export_tools module_name)
string(REGEX REPLACE "_native$" "" tool_name ${tool_name})
endif()
set(extra_cmake_statements "${extra_cmake_statements}
if (NOT QT_NO_CREATE_TARGETS)
if(NOT QT_NO_CREATE_TARGETS AND ${INSTALL_CMAKE_NAMESPACE}${target}_FOUND)
__qt_internal_promote_target_to_global(${INSTALL_CMAKE_NAMESPACE}::${tool_name})
endif()
")