CMake: Skip walking empty targets in __qt_internal_walk_libs()

If one of the interface link libraries of a target is
  "$<LINK_ONLY:$<BUILD_LOCAL_INTERFACE:Foo>>"
this will be exported by cmake as
  "$<LINK_ONLY:>"
in the exported INTERFACE_LINK_LIBRARIES property.

When walking the dependent libraries of a target using
__qt_internal_walk_libs(), this value will become empty after
unwrapping the LINK_ONLY genex.

In such a case, we should skip further processing of the library.

Otherwise in some weird unknown conditions, CMake might consider the
empty name to be a valid target, and cause errors when trying to read
properties from it.

Amends ad7b94e163ac5c3959a7e38d7f48536be288a187

Fixes: QTBUG-136039
Change-Id: I143dec697e10530379486462697cd299940ee463
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
(cherry picked from commit 9bc8ce6608eff2bd07b0044be80db4e9b6d8f5cd)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Alexandru Croitor 2025-04-24 18:14:25 +02:00 committed by Qt Cherry-pick Bot
parent b7ad2f3a9f
commit c3eaa283c3

View File

@ -186,9 +186,19 @@ function(__qt_internal_walk_libs
# Unwrap targets like $<LINK_ONLY:$<BUILD_INTERFACE:Qt6::CorePrivate>>
while(lib_target
MATCHES "^\\$<(LINK_ONLY|BUILD_INTERFACE|BUILD_LOCAL_INTERFACE):(.*)>$")
set(lib_target ${CMAKE_MATCH_2})
set(lib_target "${CMAKE_MATCH_2}")
endwhile()
# If one of the values is "$<LINK_ONLY:$<BUILD_LOCAL_INTERFACE:Foo>>", this will be
# exported by cmake as "$<LINK_ONLY:>", which will become an empty value after the
# unwrapping above.
# In that case, skip the processing. Otherwise in some weird unknown conditions,
# CMake might consider the empty name to be a valid target, and cause errors further
# down.
if("${lib_target}" STREQUAL "")
continue()
endif()
# Skip CMAKE_DIRECTORY_ID_SEP. If a target_link_libraries is applied to a target
# that was defined in a different scope, CMake appends and prepends a special directory
# id separator. Filter those out.