CMake: Fix Xcode common dependency issues for translations
CMake add_custom_command documentation says: Do not list the output in more than one independent target that may build in parallel or the two instances of the rule may conflict (instead use the add_custom_target() command to drive the command and make the other targets depend on that one) This applies to all generators, but only Xcode's new build system enforces it. So Xcode does not allow a custom command output file to be depended on by multiple targets if they don't have a common target dependency. This causes an issue when calling qt_add_translations() on a static iOS library because two targets depend on the output qm file: the _lrelease custom target and the _resources_N object library that we use to propagate resources for static libraries. We can fix the issue by saving the _lrelease custom target in a source file property of the qm file, which is then used in _qt_internal_process_resource to make the resource object library depend on the _lrelease target, rather than on the actual qm file. This ensures a common target ancestor, without forcing developers to to modify the project. _qt_internal_process_resource already reads the QT_RESOURCE_TARGET_DEPENDENCY source file property, but we will rename it to _qt_resource_target_dependency to keep it internal, which is why the change sets both. Pick-to: 6.3 Fixes: QTBUG-103470 Change-Id: I0b7b77b9f4d4c05954cca488bde5537eee724cef Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
@@ -267,6 +267,19 @@ function(qt6_add_lrelease target)
|
||||
DEPENDS ${QT_CMAKE_EXPORT_NAMESPACE}::lrelease "${ts_file}"
|
||||
VERBATIM)
|
||||
list(APPEND qm_files "${qm}")
|
||||
|
||||
# QTBUG-103470: Save the target responsible for driving the build of the custom command
|
||||
# into an internal source file property. It will be added as a dependency for targets
|
||||
# created by _qt_internal_process_resource, to avoid the Xcode issue of not allowing
|
||||
# multiple targets depending on the output, without having a common target ancestor.
|
||||
set(scope_args)
|
||||
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.18")
|
||||
set(scope_args TARGET_DIRECTORY ${target})
|
||||
endif()
|
||||
set_source_files_properties("${qm}" ${scope_args} PROPERTIES
|
||||
_qt_resource_target_dependency "${target}_lrelease"
|
||||
QT_RESOURCE_TARGET_DEPENDENCY "${target}_lrelease" # TODO: remove once qtbase is updated
|
||||
)
|
||||
endforeach()
|
||||
|
||||
add_custom_target(${target}_lrelease DEPENDS ${qm_files})
|
||||
|
||||
Reference in New Issue
Block a user