CMake: Fix adding generated resources on iOS with CMake and Xcode

When adding resources generated via a custom command, the project fails
to configure when targeting iOS with CMake and Xcode with the error:

CMake Error in src/CMakeLists.txt:
  The custom command generating
    src/.qsb/TestShader.frag.qsb
  is attached to multiple targets:
    TestApp_other_files
    TestApp
  but none of these is a common dependency of the other(s).  This is
  not allowed by the Xcode "new build system".

This happens e.g. when using qt6_add_shaders, which adds a custom
command to generate the qsb files. Or by simply adding resources via
qt6_add_resources, which depend on a custom command.

The problem is that qt6_add_resources also adds the resource to a
second "fake" target ${target}_other_files via
_qt_internal_process_resource and _qt_internal_expose_source_file_to_ide.
See c7d1874cd1.
Since these targets do not have a common dependency CMake fails to
configure the project.

So lets fix it similar to change 1bd0a5ce02352a600367beb5a5421c8f8332e1fe
and let the ${target}_other_files depend in the main ${target}.

Pick-to: 6.2
Task-number: QTBUG-95763
Change-Id: Iecdb40993a91da8bfbf6553892f9b0722d2e886c
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
bb10
Mike Achtelik 2021-09-30 20:54:16 +02:00
parent 8513bcd90c
commit 91d8443f6d
1 changed files with 8 additions and 0 deletions

View File

@ -1775,6 +1775,14 @@ function(_qt_internal_expose_source_file_to_ide target file)
set(ide_target ${target}_other_files)
if(NOT TARGET ${ide_target})
add_custom_target(${ide_target} SOURCES "${file}")
# The new Xcode build system requires a common target to drive the generation of files,
# otherwise project configuration fails.
# By adding ${target} as a dependency of ${target}_other_files,
# it becomes the common target, so project configuration succeeds.
if(CMAKE_GENERATOR STREQUAL "Xcode")
add_dependencies(${ide_target} ${target})
endif()
else()
set_property(TARGET ${ide_target} APPEND PROPERTY SOURCES "${file}")
endif()