CMake: Add risky workaround for archiving dSYMs with an Xcode project

CMake by default generates an Xcode project with an overridden
CONFIGURATION_BUILD_DIR Xcode attribute pointing to an absolute path
build dir.

Due to a bug in Xcode, that causes dSYMs not to be included in an
xcarchive after invoking the Xcode archiving task.

This can be worked around by re-setting the CONFIGURATION_BUILD_DIR
attribute to have the value "$(inherited)". That ensures that Xcode
places the dSYMs into an expected location, that can then be included
in an xcarchive.

Unfortunately overriding CONFIGURATION_BUILD_DIR breaks certain CMake
build path preconditions, which can result in broken behavior like
$<TARGET_FILE:app> genex evaluation not working, as well as ignoring
of the CMAKE_RUNTIME_OUTPUT_DIRECTORY property.

So modifying the CONFIGURATION_BUILD_DIR can only be done as an
opt-in, where the project developer knows the risks and can decide if
it will affect the project.

The project can opt into the risky fix by setting the
QT_USE_RISKY_DSYM_ARCHIVING_WORKAROUND cmake variable to ON before
creating any targets using qt_add_executable.

If Xcode fixes this bug in the future, we can make the variable a
no-op when we detect a new enough Xcode version.

Pick-to: 6.7 6.8
Task-number: QTBUG-126866
Change-Id: I37e8dee569fc45654f149219b8933769ed237fda
Reviewed-by:  Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
Alexandru Croitor 2024-07-11 13:56:36 +02:00
parent 7ccf30ae46
commit ff1ba4f1c9

View File

@ -535,6 +535,19 @@ function(_qt_internal_set_xcode_generate_debugging_symbols target)
endif()
endfunction()
# CMake generates a project where this setting is set to an absolute path build dir.
# Provide an opt-in to work around an Xcode issue where archiving does not find the project dSYMs
# unless the configuration build dir starts with $(BUILD_DIR) or is set to $(inherited).
# It is an opt-in, because it breaks certain CMake behavior like $<TARGET_FILE:${target}> genex
# evaluation as well as ignoring the value of CMAKE_RUNTIME_OUTPUT_DIRECTORY.
# So projects have to do it at their own risk.
function(_qt_internal_set_xcode_configuration_build_dir target)
if(QT_USE_RISKY_DSYM_ARCHIVING_WORKAROUND)
set_target_properties("${target}" PROPERTIES
XCODE_ATTRIBUTE_CONFIGURATION_BUILD_DIR "$(inherited)")
endif()
endfunction()
function(_qt_internal_set_xcode_bundle_display_name target)
# We want the value of CFBundleDisplayName to be ${PRODUCT_NAME}, but we can't put that
# into the Info.plist.in template file directly, because the implicit configure_file(Info.plist)