CMake: Fix Xcode common dependency issues for other_files IDE target

A generated file can be added to a resource target, which in turn
adds it to the other_files target. With the Xcode generator, this can
lead to errors like

 The custom command generating foo.txt is attached to multiple
 targets:
      foo_other_files
      foo_resources_1
 but none of these is a common dependency of the other(s).  This is
      not allowed by the Xcode "new build system".

Neither of the targets depend on each other because logically
they shouldn't depend on each other.
And yet XCode wants that each generated file is attached only to one
target, which will be a common dependency for the other targets.

Make sure _qt_internal_expose_source_file_to_ide extracts and uses
that common target dependency just like
qt_add_resources -> _qt_internal_process_resource already does.

One case of a common target dependency is the _lrelease target
in qttools which was added in 5b0e765ab0dddba86662925cb44aeac748a286b7

Another case is in qt_add_shaders in qtshadertools.

I expect we might encounter other cases where we need to introduce a
common driving target.

Pick-to: 6.2 6.3 6.4
Task-number: QTBUG-103723
Change-Id: Ideff023718a6ce109a4b3eefa01bffa79d1c6a3e
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
Alexandru Croitor 2022-06-14 17:28:54 +02:00
parent fa814fcfea
commit 20dd4a43f0

View File

@ -2020,6 +2020,19 @@ function(_qt_internal_expose_source_file_to_ide target file)
else()
set_property(TARGET ${ide_target} APPEND PROPERTY SOURCES "${file}")
endif()
set(scope_args)
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.18")
set(scope_args TARGET_DIRECTORY "${target}")
endif()
get_source_file_property(
target_dependency "${file}" ${scope_args} _qt_resource_target_dependency)
if(target_dependency)
if(NOT TARGET "${target_dependency}")
message(FATAL_ERROR "Target dependency on source file ${file} is not a cmake target.")
endif()
add_dependencies(${ide_target} ${target_dependency})
endif()
endfunction()
#