Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ios simulator arm64 and arm64e support #1086

Merged
merged 18 commits into from
Jan 28, 2023
Merged
23 changes: 13 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ if(APPLE)
# iOS build options
option(BUILD_IOS "Build for iOS" NO)
option(FORCE_RESET_OSX_DEPLOYMENT_TARGET "Clear the OSX Deployment Target Set" YES)
if (DEFINED FORCE_RESET_DEPLOYMENT_TARGET)
set(FORCE_RESET_OSX_DEPLOYMENT_TARGET ${FORCE_RESET_DEPLOYMENT_TARGET})
endif()

if(BUILD_IOS)
set(TARGET_ARCH "APPLE")
Expand All @@ -34,14 +37,14 @@ if(APPLE)

if(FORCE_RESET_OSX_DEPLOYMENT_TARGET)
set(CMAKE_OSX_DEPLOYMENT_TARGET "" CACHE STRING "Force unset of the deployment target for iOS" FORCE)
endif()

if((${IOS_PLAT} STREQUAL "iphonesimulator") AND (${IOS_ARCH} STREQUAL "arm64"))
# iOS arm64 simulator is supported starting BigSur
# Unfortunately, CMAKE produces a device binary (not simulator) when providing -miphoneos-version-min flag when building iOS arm64 simulator
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -miphoneos-version-min=${IOS_DEPLOYMENT_TARGET}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -miphoneos-version-min=${IOS_DEPLOYMENT_TARGET}")
if((${IOS_PLAT} STREQUAL "iphonesimulator") AND ((${IOS_ARCH} STREQUAL "arm64") OR (${IOS_ARCH} STREQUAL "arm64e")))
# iOS arm64 simulator is supported starting BigSur
# Unfortunately, CMAKE produces a device binary (not simulator) when providing -miphoneos-version-min flag when building iOS arm64 simulator
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -miphoneos-version-min=${IOS_DEPLOYMENT_TARGET}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -miphoneos-version-min=${IOS_DEPLOYMENT_TARGET}")
endif()
endif()

if((${IOS_PLAT} STREQUAL "iphoneos") OR (${IOS_PLAT} STREQUAL "iphonesimulator"))
Expand All @@ -54,12 +57,12 @@ if(APPLE)
set(IOS_PLATFORM "iphonesimulator")
set(CMAKE_SYSTEM_PROCESSOR x86_64)
elseif(${IOS_ARCH} STREQUAL "arm64")
set(IOS_PLATFORM "iphoneos")
set(IOS_PLATFORM ${IOS_PLAT})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch arm64")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -arch arm64")
set(CMAKE_SYSTEM_PROCESSOR arm64)
elseif(${IOS_ARCH} STREQUAL "arm64e")
set(IOS_PLATFORM "iphoneos")
set(IOS_PLATFORM ${IOS_PLAT})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch arm64e")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -arch arm64e")
set(CMAKE_SYSTEM_PROCESSOR arm64e)
Expand Down
14 changes: 11 additions & 3 deletions build-ios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,22 @@ IOS_ARCH="x86_64"
fi

# Set Platform: device or simulator
if [ "$2" == "device" ] || [ "$3" == "device" ]; then
if [ "$2" == "device" ] || [ "$3" == "device" ] || [ "$4" == "device" ]; then
lalitb marked this conversation as resolved.
Show resolved Hide resolved
IOS_PLAT="iphoneos"
else
IOS_PLAT="iphonesimulator"
fi

# Set target iOS minver
IOS_DEPLOYMENT_TARGET=10.0
default_ios_target=10.0
if [ -z $IOS_DEPLOYMENT_TARGET ]; then
export IOS_DEPLOYMENT_TARGET=${default_ios_target}
export FORCE_RESET_DEPLOYMENT_TARGET=YES
else
export FORCE_RESET_DEPLOYMENT_TARGET=NO
fi
echo "ios deployment target="$IOS_DEPLOYMENT_TARGET
echo "force reset deployment target="$FORCE_RESET_DEPLOYMENT_TARGET

# Install build tools and recent sqlite3
FILE=.buildtools
Expand All @@ -54,7 +62,7 @@ cd out

CMAKE_PACKAGE_TYPE=tgz

cmake_cmd="cmake -DBUILD_IOS=YES -DIOS_ARCH=$IOS_ARCH -DIOS_PLAT=$IOS_PLAT -DIOS_DEPLOYMENT_TARGET=$IOS_DEPLOYMENT_TARGET -DBUILD_UNIT_TESTS=YES -DBUILD_FUNC_TESTS=YES -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_PACKAGE_TYPE=$CMAKE_PACKAGE_TYPE $CMAKE_OPTS .."
cmake_cmd="cmake -DCMAKE_OSX_SYSROOT=$IOS_PLAT -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_IOS_ARCH_ABI=$IOS_ARCH -DCMAKE_OSX_DEPLOYMENT_TARGET=$IOS_DEPLOYMENT_TARGET -DBUILD_IOS=YES -DIOS_ARCH=$IOS_ARCH -DIOS_PLAT=$IOS_PLAT -DIOS_DEPLOYMENT_TARGET=$IOS_DEPLOYMENT_TARGET -DBUILD_UNIT_TESTS=YES -DBUILD_FUNC_TESTS=YES -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_PACKAGE_TYPE=$CMAKE_PACKAGE_TYPE -DFORCE_RESET_DEPLOYMENT_TARGET=$FORCE_RESET_DEPLOYMENT_TARGET $CMAKE_OPTS .."
echo $cmake_cmd
eval $cmake_cmd

Expand Down
10 changes: 4 additions & 6 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ while getopts "h?vl:D:" opt; do
echo "Environment variables: "
echo "CMAKE_OPTS - any additional cmake options. "
echo "GIT_PULL_TOKEN - authorization token for Microsoft-proprietary modules. "
echo "MACOSX_DEPLOYMENT_TARGET - optional parameter for setting macosx deployment target "
echo "Plus any other environment variables respected by CMake build system. "
exit 0
;;
Expand All @@ -91,12 +92,9 @@ if [ "$LINK_TYPE" == "shared" ]; then
fi

# Set target MacOS minver
if [ "$MAC_ARCH" == "arm64" ]; then
export MACOSX_DEPLOYMENT_TARGET=11.10
else
export MACOSX_DEPLOYMENT_TARGET=10.10
fi

default_mac_os_target=$([ "$MAC_ARCH" == "arm64" ] && echo "11.10" || echo "10.10")
[ -z $MACOSX_DEPLOYMENT_TARGET ] && export MACOSX_DEPLOYMENT_TARGET=${default_mac_os_target}
echo "macosx deployment target="$MACOSX_DEPLOYMENT_TARGET

# Install build tools and recent sqlite3
FILE=.buildtools
Expand Down