From f9c850cc42a5591c096e1b0d547efb93ad18f1f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 21 May 2021 12:01:26 +0200 Subject: [PATCH] qmake: Pick default architecture on macOS based on uname When dealing with a universal build of Qt, we would end up using the QT_ARCH as the architecture for user projects, but this architecture is always the primary one that Qt was configured with. Instead of relying on QT_ARCH, we start writing QT_ARCHS (plural) to qconfig.pri, based on CMAKE_OSX_ARCHITECTURES, and then use that to initialize QMAKE_APPLE_DEVICE_ARCHS. We then resolve the active arch using uname -m, matching what CMake does. We still feed all the available architectures to the Makefile or Xcode project, so that the user can build for any of the available architectures without needing a reconfigure. Fixes: QTBUG-93760 Change-Id: I0d338241ba4d944ca36d85371e9c4df7dbc4f269 Reviewed-by: Alexandru Croitor --- cmake/QtPriHelpers.cmake | 7 +++++++ mkspecs/features/mac/default_post.prf | 18 ++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/cmake/QtPriHelpers.cmake b/cmake/QtPriHelpers.cmake index 36f455bfa11..a44d3e8a081 100644 --- a/cmake/QtPriHelpers.cmake +++ b/cmake/QtPriHelpers.cmake @@ -598,6 +598,13 @@ QT_PATCH_VERSION = ${PROJECT_VERSION_PATCH} list(APPEND extra_statements "QT_MAC_SDK_VERSION = ${QT_MAC_SDK_VERSION}") list(APPEND extra_statements "QMAKE_MACOSX_DEPLOYMENT_TARGET = ${CMAKE_OSX_DEPLOYMENT_TARGET}") + if (CMAKE_OSX_ARCHITECTURES) + list(APPEND architectures "${CMAKE_OSX_ARCHITECTURES}") + string (REPLACE ";" " " architectures "${architectures}") + else() + set(architectures "$$QT_ARCH") + endif() + list(APPEND extra_statements "QT_ARCHS = ${architectures}") endif() list(APPEND extra_statements "QT_EDITION = Open Source") diff --git a/mkspecs/features/mac/default_post.prf b/mkspecs/features/mac/default_post.prf index 0fcb1a55b96..18a451aaf57 100644 --- a/mkspecs/features/mac/default_post.prf +++ b/mkspecs/features/mac/default_post.prf @@ -95,10 +95,11 @@ app_extension_api_only { QMAKE_LFLAGS += $$QMAKE_CFLAGS_APPLICATION_EXTENSION } -# Non-universal builds do not set QMAKE_APPLE_DEVICE_ARCHS, -# so we pick it up from what the arch test resolved instead. +# Pick up available architectures from what Qt was built with, +# so that our Makefile or Xcode project is set up to build for +# any of the available architectures. isEmpty(QMAKE_APPLE_DEVICE_ARCHS): \ - QMAKE_APPLE_DEVICE_ARCHS = $$QT_ARCH + QMAKE_APPLE_DEVICE_ARCHS = $$QT_ARCHS macx-xcode { qmake_pkginfo_typeinfo.name = QMAKE_PKGINFO_TYPEINFO @@ -157,10 +158,15 @@ macx-xcode { single_arch: VALID_ARCHS = $$first(VALID_ARCHS) - ACTIVE_ARCHS = $(filter $(EXPORT_VALID_ARCHS), $(ARCHS)) - ARCH_ARGS = $(foreach arch, $(if $(EXPORT_ACTIVE_ARCHS), $(EXPORT_ACTIVE_ARCHS), $(EXPORT_VALID_ARCHS)), -arch $(arch)) + macos: ACTIVE_ARCH = $$system("uname -m") - QMAKE_EXTRA_VARIABLES += VALID_ARCHS ACTIVE_ARCHS ARCH_ARGS + ARCHS = $(filter $(EXPORT_VALID_ARCHS), \ + $(if $(ARCHS), $(ARCHS), \ + $(if $(EXPORT_ACTIVE_ARCH), $(EXPORT_ACTIVE_ARCH), \ + $(EXPORT_VALID_ARCHS)))) + ARCH_ARGS = $(foreach arch, $(if $(EXPORT_ARCHS), $(EXPORT_ARCHS), $(EXPORT_VALID_ARCHS)), -arch $(arch)) + + QMAKE_EXTRA_VARIABLES += VALID_ARCHS ACTIVE_ARCH ARCHS ARCH_ARGS arch_flags = $(EXPORT_ARCH_ARGS)