From 9fbb8e0090a1d8220479e776feae7c9c5bb8493e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 18 Feb 2025 17:20:06 +0100 Subject: [PATCH] iOS: Set LD_ENTRY_POINT for generated Xcode project We normally override the entrypoint to _qt_main_wrapper via the -e flag to the linker, but if a Swift file is added to the Xcode project, Xcode does some magic, building the app as a shared library, and wrapping it with the Swift code into a custom executable. The -e flag will then be a noop when linking our shared library. To work around this we set the custom LD_ENTRY_POINT Xcode build setting, which triggers Xcode to pass -e when linking the wrapper-executable. This works in practice, but produces a warning on the console that the entrypoint is not found, which has been reported as FB16519113. Fixes: QTBUG-133577 Pick-to: 6.8 Change-Id: I9d8310b39ac5a4900693df55c2e5bfa346c0300a Reviewed-by: Alexandru Croitor (cherry picked from commit 430ba7c0f826ee6f91fbfdc861525cb62b8e725c) Reviewed-by: Qt Cherry-pick Bot --- cmake/QtPublicAppleHelpers.cmake | 21 +++++++++++++++++++++ mkspecs/features/uikit/default_post.prf | 6 ++++++ 2 files changed, 27 insertions(+) diff --git a/cmake/QtPublicAppleHelpers.cmake b/cmake/QtPublicAppleHelpers.cmake index 7786fed8c60..9dccb10f55a 100644 --- a/cmake/QtPublicAppleHelpers.cmake +++ b/cmake/QtPublicAppleHelpers.cmake @@ -754,6 +754,25 @@ function(_qt_internal_set_ios_simulator_arch target) "x86_64") endfunction() +function(_qt_internal_set_xcode_entrypoint_attribute target entrypoint) + if(CMAKE_XCODE_ATTRIBUTE_LD_ENTRY_POINT + OR QT_NO_SET_XCODE_LD_ENTRY_POINT) + return() + endif() + + get_target_property(existing_entrypoint + "${target}" XCODE_ATTRIBUTE_LD_ENTRY_POINT) + if(NOT existing_entrypoint MATCHES "-NOTFOUND") + return() + endif() + + set_target_properties("${target}" + PROPERTIES + "XCODE_ATTRIBUTE_LD_ENTRY_POINT" + "${entrypoint}") +endfunction() + + # Export Apple platform sdk and xcode version requirements to Qt6ConfigExtras.cmake. # Always exported, even on non-Apple platforms, so that we can use them when building # documentation. @@ -1022,6 +1041,8 @@ function(_qt_internal_finalize_ios_app target) _qt_internal_set_xcode_targeted_device_family("${target}") _qt_internal_set_xcode_bitcode_enablement("${target}") _qt_internal_set_ios_simulator_arch("${target}") + + _qt_internal_set_xcode_entrypoint_attribute("${target}" "_qt_main_wrapper") endfunction() function(_qt_internal_finalize_macos_app target) diff --git a/mkspecs/features/uikit/default_post.prf b/mkspecs/features/uikit/default_post.prf index a731cd0cbe9..d330d3cdeae 100644 --- a/mkspecs/features/uikit/default_post.prf +++ b/mkspecs/features/uikit/default_post.prf @@ -48,6 +48,12 @@ macx-xcode { QMAKE_MAC_XCODE_SETTINGS += supported_platforms } + # Override the entry point explicitly, in case a Swift file is + # added to the Xcode project + ld_entry_point.name = LD_ENTRY_POINT + ld_entry_point.value = _qt_main_wrapper + QMAKE_MAC_XCODE_SETTINGS += ld_entry_point + # In a simulator specific build the device config will set the SDK # to the simulator SDK, but for Xcode we always want the SDKROOT # to be the device SDK.