Skip to content

Commit

Permalink
Refactor iOS builds to facilitate tvOS port
Browse files Browse the repository at this point in the history
- moved prf files to shared location (uikit, added to QMAKE_PLATFORM)
- prepare some formatting (unconditional blocks mostly) to add conditions later
- make device detection script more generic, passing filter strings
  as a parameter and returning non-os specific variables

Change-Id: I61f2b77093304ff985bec9da04fda57ff296b16b
Reviewed-by: Oswald Buddenhagen <[email protected]>
Reviewed-by: Tor Arne Vestbø <[email protected]>
  • Loading branch information
mkrus authored and jakepetroules committed May 5, 2016
1 parent 6fb56a7 commit 7c7d8f8
Show file tree
Hide file tree
Showing 15 changed files with 139 additions and 125 deletions.
2 changes: 1 addition & 1 deletion mkspecs/common/ios.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# qmake common configuration for iOS
#

QMAKE_PLATFORM += ios
QMAKE_PLATFORM += ios uikit
QMAKE_MAC_SDK = iphoneos

simulator.sdk = iphonesimulator
Expand Down
101 changes: 101 additions & 0 deletions mkspecs/features/uikit/default_post.prf
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
equals(TEMPLATE, app):qt {
# If the application uses Qt, it needs to be an application bundle
# to be able to deploy and run on iOS. The only exception to this
# is if you're working with a jailbroken device and can run the
# resulting binary from the console/over SSH, but that's not a
# use-case we care about, so no need to complicate the logic.
CONFIG *= app_bundle

# For Qt applications we want Xcode project files as the generated output,
# but since qmake doesn't handle the transition between makefiles and Xcode
# project files (which happens when using subdirs), we can't just override
# MAKEFILE_GENERATOR. Instead, we generate the Xcode project by spawning a
# child qmake process with -spec macx-xcode and let the top level qmake
# process generate a wrapper makefile that forwards everything to xcodebuild.
equals(MAKEFILE_GENERATOR, UNIX): \
CONFIG = xcodebuild $$CONFIG
}

load(default_post)

macx-xcode {
device_family.name = TARGETED_DEVICE_FAMILY
device_family.value = $$QMAKE_IOS_TARGETED_DEVICE_FAMILY
QMAKE_MAC_XCODE_SETTINGS += device_family

{
# If QMAKE_BUNDLE_DATA contains an asset catalog that includes an
# AppIcon.appiconset, we configure Xcode to use it for app icons.
for(bundle_data, QMAKE_BUNDLE_DATA) {
for(bundle_file, $${bundle_data}.files) {
!contains(bundle_file, .*\.xcassets$): next()
!exists($$absolute_path($$bundle_file/AppIcon.appiconset, $$_PRO_FILE_PWD_)): next()

asset_catalog_appicon.name = "ASSETCATALOG_COMPILER_APPICON_NAME"
asset_catalog_appicon.value = "AppIcon"
QMAKE_MAC_XCODE_SETTINGS += asset_catalog_appicon
break()
}
!isEmpty(asset_catalog_appicon.name): break()
}

# Set up default 4-inch iPhone/iPod launch image so that our apps
# support the full screen resolution of those devices.
qmake_launch_image = [email protected]
qmake_copy_image.input = $$QMAKESPEC/$$qmake_launch_image
qmake_copy_image.output = $$OUT_PWD/$${TARGET}.xcodeproj/$$qmake_launch_image
qmake_copy_image.CONFIG = verbatim
QMAKE_SUBSTITUTES += qmake_copy_image
qmake_launch_images.files = $$qmake_copy_image.output
QMAKE_BUNDLE_DATA += qmake_launch_images

lessThan(QMAKE_XCODE_VERSION, "6.0") {
warning("You need to update Xcode to version 6 or newer to fully support iPhone6/6+")
} else {
# Set up default LaunchScreen to support iPhone6/6+
qmake_launch_screen = LaunchScreen.xib
qmake_copy_launch_screen.input = $$QMAKESPEC/$$qmake_launch_screen
qmake_copy_launch_screen.output = $$OUT_PWD/$${TARGET}.xcodeproj/$$qmake_launch_screen
QMAKE_SUBSTITUTES += qmake_copy_launch_screen
qmake_launch_screens.files = $$qmake_copy_launch_screen.output
QMAKE_BUNDLE_DATA += qmake_launch_screens
}
}
}

macx-xcode {
arch_device.name = "ARCHS[sdk=$${device.sdk}*]"
arch_simulator.name = "ARCHS[sdk=$${simulator.sdk}*]"
{
arch_device.value = $$QMAKE_IOS_DEVICE_ARCHS
arch_simulator.value = $$QMAKE_IOS_SIMULATOR_ARCHS
QMAKE_XCODE_ARCHS = $$QMAKE_IOS_DEVICE_ARCHS $$QMAKE_IOS_SIMULATOR_ARCHS
}

QMAKE_MAC_XCODE_SETTINGS += arch_device arch_simulator

only_active_arch.name = ONLY_ACTIVE_ARCH
only_active_arch.value = YES
only_active_arch.build = debug
QMAKE_MAC_XCODE_SETTINGS += only_active_arch
} else {
# Be more specific about which architecture we're targeting
contains(QT_ARCH, arm.*) {
VALID_ARCHS = $$QMAKE_IOS_DEVICE_ARCHS
} else {
VALID_ARCHS = $$QMAKE_IOS_SIMULATOR_ARCHS
}

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))

QMAKE_EXTRA_VARIABLES += VALID_ARCHS ACTIVE_ARCHS ARCH_ARGS

arch_flags = $(EXPORT_ARCH_ARGS)

QMAKE_CFLAGS += $$arch_flags
QMAKE_CXXFLAGS += $$arch_flags
QMAKE_LFLAGS += $$arch_flags
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
##
#############################################################################

booted_simulator=$(xcrun simctl list devices | grep -E "iPhone|iPad" | grep -v unavailable | grep Booted | perl -lne 'print $1 if /\((.*?)\)/')
echo "IPHONESIMULATOR_DEVICES = $booted_simulator"
booted_simulator=$(xcrun simctl list devices | grep -E '$1' | grep -v unavailable | grep Booted | perl -lne 'print $2 if /\((.*?)\)/')
echo "SIMULATOR_DEVICES = $booted_simulator"

xcodebuild test -scheme $1 -destination 'id=0' -destination-timeout 1 2>&1| sed -n 's/{ \(platform:.*\) }/\1/p' | while read destination; do
xcodebuild test -scheme $2 -destination 'id=0' -destination-timeout 1 2>&1| sed -n 's/{ \(platform:.*\) }/\1/p' | while read destination; do
id=$(echo $destination | sed -n -E 's/.*id:([^ ,]+).*/\1/p')
echo $destination | tr ',' '\n' | while read keyval; do
key=$(echo $keyval | cut -d ':' -f 1 | tr '[:lower:]' '[:upper:]')
Expand All @@ -51,9 +51,9 @@ xcodebuild test -scheme $1 -destination 'id=0' -destination-timeout 1 2>&1| sed

if [ $key = 'PLATFORM' ]; then
if [ "$val" = "iOS" ]; then
echo "IPHONEOS_DEVICES += $id"
echo "HARDWARE_DEVICES += $id"
elif [ "$val" = "iOS Simulator" -a "$id" != "$booted_simulator" ]; then
echo "IPHONESIMULATOR_DEVICES += $id"
echo "SIMULATOR_DEVICES += $id"
fi
fi
done
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ equals(TEMPLATE, app):contains(qt_depends, gui(-private)?) {
lib_path_and_base = $$[QT_INSTALL_PLUGINS/get]/platforms/lib$${lib_name}$$qtPlatformTargetSuffix()
LIBS += -l$${lib_name}$$qtPlatformTargetSuffix() $$fromfile($${lib_path_and_base}.prl, QMAKE_PRL_LIBS)

# By marking qt_registerPlatformPlugin as undefined, we ensure that
# the plugin.o translation unit is considered for inclusion in
# the final binary, which in turn ensures that the plugin's
# static initializer is included and run.
QMAKE_LFLAGS += -u _qt_registerPlatformPlugin
{
# By marking qt_registerPlatformPlugin as undefined, we ensure that
# the plugin.o translation unit is considered for inclusion in
# the final binary, which in turn ensures that the plugin's
# static initializer is included and run.
QMAKE_LFLAGS += -u _qt_registerPlatformPlugin

# We do link and dependency resolution for the platform plugin
# manually, since we know we always need the plugin, so we don't
# need to generate an import for it.
QTPLUGIN.platforms = -
# We do link and dependency resolution for the platform plugin
# manually, since we know we always need the plugin, so we don't
# need to generate an import for it.
QTPLUGIN.platforms = -
}

!no_main_wrapper {
# The LC_MAIN load command available in iOS 6.0 and above allows dyld to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ isEmpty(QT_ARCH) {
# means we fail to pass -arch to the compiler, resulting in broke tests.
# As the Xcode toolchain doesn't seem to have a way to auto-detect the
# arch based on the SDK, we have to hard-code the arch for configure.
contains(QMAKE_MAC_SDK, $${device.sdk}.*): \
contains(QMAKE_MAC_SDK, $${device.sdk}.*) {
QT_ARCH = arm
else: \ # Simulator
} else { # Simulator
QT_ARCH = i386
}

# Prevent the arch/config tests from building as multi-arch binaries,
# as we only want the lowest common denominator features.
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# In case the user sets the SDK manually
contains(QMAKE_MAC_SDK, ^$${simulator.sdk}.*) {
simulator_and_device: \
error("iOS simulator is handled automatically for simulator_and_device")
error("Simulator is handled automatically for simulator_and_device")

CONFIG += simulator $${simulator.sdk}
}
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ simulator-install: ACTION = build
%-simulator-check: check-simulator ;

# SDK
%-device: SDK = iphoneos
%-simulator: SDK = iphonesimulator
%-device: SDK = $(DEVICE_SDK)
%-simulator: SDK = $(SIMULATOR_SDK)

# Configuration
release-%: CONFIGURATION = Release
Expand All @@ -61,19 +61,20 @@ ifneq ($(filter check%,$(MAKECMDGOALS)),)
ifeq ($(DEVICES),)
$(info Enumerating test destinations (you may override this by setting DEVICES explicitly), please wait...)
SPECDIR := $(dir $(lastword $(MAKEFILE_LIST)))
DESTINATIONS_INCLUDE = /tmp/ios_destinations.mk
$(shell $(SPECDIR)/ios_destinations.sh $(TARGET) > $(DESTINATIONS_INCLUDE))
DESTINATIONS_INCLUDE = /tmp/device_destinations.mk
$(shell $(SPECDIR)/../features/uikit/device_destinations.sh '$(EXPORT_DEVICE_FILTER)' $(TARGET) > $(DESTINATIONS_INCLUDE))
include $(DESTINATIONS_INCLUDE)
endif
endif

%-simulator: DEVICES = $(firstword $(IPHONESIMULATOR_DEVICES))
%-device: DEVICES = $(IPHONEOS_DEVICES)
%-simulator: DEVICES = $(firstword $(SIMULATOR_DEVICES))
%-device: DEVICES = $(HARDWARE_DEVICES)

IPHONEOS_GENERIC_DESTINATION := "generic/platform=iOS"
IPHONESIMULATOR_GENERIC_DESTINATION := "id=$(shell xcrun simctl list devices | grep -E 'iPhone|iPad' | grep -v unavailable | perl -lne 'print $$1 if /\((.*?)\)/' | tail -n 1)"
GENERIC_DEVICE_DESTINATION := $(EXPORT_GENERIC_DEVICE_DESTINATION)
GENERIC_SIMULATOR_DESTINATION := "id=$(shell xcrun simctl list devices | grep -E '$(EXPORT_DEVICE_FILTER)' | grep -v unavailable | perl -lne 'print $$1 if /\((.*?)\)/' | tail -n 1)"

DESTINATION = $(if $(DESTINATION_ID),"id=$(DESTINATION_ID)",$(value $(call toupper,$(call basesdk,$(SDK)))_GENERIC_DESTINATION))
%-simulator: DESTINATION = $(if $(DESTINATION_ID),"id=$(DESTINATION_ID)",$(GENERIC_SIMULATOR_DESTINATION))
%-device: DESTINATION = $(if $(DESTINATION_ID),"id=$(DESTINATION_ID)",$(GENERIC_DEVICE_DESTINATION))

# Xcodebuild

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ QMAKE_EXTRA_VARIABLES += SUBTARGETS

CONFIG += no_default_goal_deps

QMAKE_EXTRA_INCLUDES += $$shell_quote($$QMAKESPEC/xcodebuild.mk)
DEVICE_SDK = $${device.sdk}
SIMULATOR_SDK = $${simulator.sdk}
DEVICE_FILTER = "iPhone|iPad"
GENERIC_DEVICE_DESTINATION = "generic/platform=iOS"
QMAKE_EXTRA_VARIABLES += DEVICE_SDK SIMULATOR_SDK DEVICE_FILTER GENERIC_DEVICE_DESTINATION

QMAKE_EXTRA_INCLUDES += $$shell_quote($$PWD/xcodebuild.mk)

# Distclean

Expand Down
97 changes: 0 additions & 97 deletions mkspecs/macx-ios-clang/features/default_post.prf

This file was deleted.

0 comments on commit 7c7d8f8

Please sign in to comment.