#
# Helper to set CPU architecture flags for iOS configurations
#
# Depends on:
#
#   QMAKE_IPHONEOS_DEPLOYMENT_TARGET - set in mkspecs/common/ios/versions.conf
#
# Note:
#
#   Must be included after load(qt_config) in mkspec for auto-detection based
#   on GL/ES version (GL/ES 2.x implies armv7 on iOS).
#

# Target architecture for iOS devices (armv6, armv7 or leave blank for default)
QMAKE_IOS_TARGET_ARCH   =

###########################################################################

# Device?
!*simulator* {
    # Let mkspec specify archictecture
    *armv6*: QMAKE_IOS_TARGET_ARCH = armv6
    else:*armv7*: QMAKE_IOS_TARGET_ARCH = armv7

    # ARMv7 architecture device (see below) is required for OpenGL/ES 2.x
    isEmpty(QMAKE_IOS_TARGET_ARCH):contains(QT_CONFIG, opengles2): QMAKE_IOS_TARGET_ARCH = armv7

    # No target architecture specified?
    isEmpty(QMAKE_IOS_TARGET_ARCH) {
        # iOS versions < 4.3 can be armv6 or armv7, so need armv6 for max. compatibility,
        # assume that building for OpenGL/ES 1.x is targeting armv6
        lessThan(QMAKE_IPHONEOS_DEPLOYMENT_TARGET, "4.3")|contains(QT_CONFIG, opengles1) {
            QMAKE_IOS_TARGET_ARCH = armv6
        } else: QMAKE_IOS_TARGET_ARCH = armv7
    }

    # Samsung S5PC100, Apple A4, A5, A5X
    equals(QMAKE_IOS_TARGET_ARCH, "armv7") {
        # iOS CPU architecture (armv7)
        QMAKE_IOS_ARM_ARCH = __ARM_ARCH_7__

        # Thumb2 instructions
        QMAKE_IOS_ARM_FLAGS = -mthumb
        QMAKE_IOS_ARM_ARCH += __MARM_THUMB__

        # NEON instructions
        *-g++*: QMAKE_IOS_ARM_FLAGS += -mfloat-abi=softfp -mfpu=neon
        QMAKE_IOS_ARM_ARCH += __ARM_NEON__
    } else {
        # Samsung S5L8900
        if(equals(QMAKE_IOS_TARGET_ARCH, "armv6")) {
            # iOS CPU architecture (armv6)
            QMAKE_IOS_ARM_ARCH = __ARM_ARCH_6__

            # ARM instructions
            QMAKE_IOS_ARM_FLAGS = -marm -mcpu=arm1176jzf-s
            !*clang*: QMAKE_IOS_ARM_FLAGS += -march=armv6
        } else {
            # Unsupported architecture
            error("Invalid iOS target $${QMAKE_IOS_TARGET_ARCH}! Edit mkspecs/common/ios/arch.conf to specify target architecture.")
        }
    }
# Simulator is i386 only
} else: QMAKE_IOS_TARGET_ARCH = i386

# iOS architecture build flags
QMAKE_IOS_ARCH_FLAGS    = -arch $$QMAKE_IOS_TARGET_ARCH
QMAKE_CFLAGS           += $$QMAKE_IOS_ARCH_FLAGS
QMAKE_CXXFLAGS         += $$QMAKE_IOS_ARCH_FLAGS
QMAKE_OBJECTIVE_CFLAGS += $$QMAKE_IOS_ARCH_FLAGS
QMAKE_LFLAGS           += $$QMAKE_IOS_ARCH_FLAGS
QMAKE_IOS_TARGET_ARCH   =
QMAKE_IOS_ARCH_FLAGS    =

# Architecture specific defines/flags
!*simulator* {
    DEFINES            += $$QMAKE_IOS_ARM_ARCH
    QMAKE_IOS_ARM_ARCH  =

    QMAKE_CFLAGS       += $$QMAKE_IOS_ARM_FLAGS
    QMAKE_CXXFLAGS     += $$QMAKE_IOS_ARM_FLAGS
    QMAKE_OBJECTIVE_CFLAGS += $$QMAKE_IOS_ARM_FLAGS
    QMAKE_IOS_ARM_FLAGS =
}
