1616#
1717# Builds and runs the tests, meant to be used on a bash environment.
1818
19- usage (){
19+ usage () {
2020 echo " Usage: $0 [options]
2121 options:
2222 -b, build path default: ios_unity
@@ -30,15 +30,20 @@ usage(){
3030
3131set -e
3232
33- readonly SUPPORTED_PLATFORMS=(device) # simulator) only support device arch for now
34- readonly SUPPORTED_ARCHITECTURES=" arm64;armv7" # ;x86_64;i386" only support device arch for now
35- # readonly DEVICE_ARCHITECTURES="arm64;armv7" only support device arch for now
36- # readonly SIMULATOR_ARCHITECTURES="arm64;x86_64;i386" only support device arch for now
33+ readonly SUPPORTED_PLATFORMS=(device simulator)
34+ readonly SUPPORTED_ARCHITECTURES=(arm64 armv7 x86_64 i386)
35+ readonly DEVICE_ARCHITECTURES=(arm64 armv7)
36+ readonly SIMULATOR_ARCHITECTURES=(arm64 x86_64 i386)
37+ readonly DEVICE_IOS_PLATFORM_LOCATION=" iPhoneOS.platform"
38+ readonly SIMULATOR_IOS_PLATFORM_LOCATION=" iPhoneSimulator.platform"
39+ readonly DEVICE_OSX_SYSROOT=" iphoneos"
40+ readonly SIMULATOR_OSX_SYSROOT=" iphonesimulator"
3741
3842# build default value
3943buildpath=" ios_unity"
4044sourcepath=" ."
4145platforms=(" ${SUPPORTED_PLATFORMS[@]} " )
46+ architectures=(" ${SUPPORTED_ARCHITECTURES[@]} " )
4247cmake_extra=" "
4348
4449# Enable utf8 output
@@ -48,57 +53,117 @@ export LANG=en_US.UTF-8
4853IFS=' ,' # split options on ',' characters
4954while getopts " hb:s:p:a:c:" opt; do
5055 case $opt in
51- h)
52- usage
53- exit 0
54- ;;
55- b)
56- buildpath=$OPTARG
57- ;;
58- s)
59- sourcepath=$OPTARG
60- if [[ ! -d " ${sourcepath} " ]]; then
61- echo " Source path ${sourcepath} not found."
56+ h)
57+ usage
58+ exit 0
59+ ;;
60+ b)
61+ buildpath=$OPTARG
62+ ;;
63+ s)
64+ sourcepath=$OPTARG
65+ if [[ ! -d " ${sourcepath} " ]]; then
66+ echo " Source path ${sourcepath} not found."
67+ exit 2
68+ fi
69+ ;;
70+ p)
71+ platforms=($OPTARG )
72+ for platform in ${platforms[@]} ; do
73+ if [[ ! " ${SUPPORTED_PLATFORMS[@]} " =~ " ${platform} " ]]; then
74+ echo " invalid platform: ${platform} "
75+ echo " Supported platforms are: ${SUPPORTED_PLATFORMS[@]} "
6276 exit 2
6377 fi
64- ;;
65- p)
66- platforms=($OPTARG )
67- for platform in ${platforms[@]} ; do
68- if [[ ! " ${SUPPORTED_PLATFORMS[@]} " =~ " ${platform} " ]]; then
69- echo " invalid platform: ${platform} "
70- echo " Supported platforms are: ${SUPPORTED_PLATFORMS[@]} "
71- exit 2
72- fi
73- done
74- ;;
75- a)
76- architectures=($OPTARG )
77- for arch in ${architectures[@]} ; do
78- if [[ ! " ${SUPPORTED_ARCHITECTURES[@]} " =~ " ${arch} " ]]; then
79- echo " invalid architecture: ${arch} "
80- echo " Supported architectures are: ${SUPPORTED_ARCHITECTURES[@]} "
81- exit 2
82- fi
83- done
84- ;;
85- c)
86- cmake_extra=$OPTARG
87- ;;
88- * )
89- echo " unknown parameter"
90- exit 2
91- ;;
78+ done
79+ ;;
80+ a)
81+ architectures=($OPTARG )
82+ for arch in ${architectures[@]} ; do
83+ if [[ ! " ${SUPPORTED_ARCHITECTURES[@]} " =~ " ${arch} " ]]; then
84+ echo " invalid architecture: ${arch} "
85+ echo " Supported architectures are: ${SUPPORTED_ARCHITECTURES[@]} "
86+ exit 2
87+ fi
88+ done
89+ ;;
90+ c)
91+ cmake_extra=$OPTARG
92+ ;;
93+ * )
94+ echo " unknown parameter"
95+ exit 2
96+ ;;
9297 esac
9398done
9499echo " *********************** Build Unity iOS SDK *******************************"
95100echo " build path: ${buildpath} "
96101echo " source path: ${sourcepath} "
97102echo " build platforms: ${platforms[@]} "
103+ echo " architectures: ${architectures[@]} "
98104echo " cmake extras: ${cmake_extra} "
99105echo " ***************************************************************************"
100- sourcepath=$( cd ${sourcepath} && pwd) # full path
101- buildpath=$( mkdir -p ${buildpath} && cd ${buildpath} && pwd) # full path
106+ sourcepath=$( cd ${sourcepath} && pwd) # full path
107+ buildpath=$( mkdir -p ${buildpath} && cd ${buildpath} && pwd) # full path
108+
109+ ios_location=" "
110+ osx_sysroot=" "
111+ xcode_platforms=" "
112+ cmake_archs=" "
113+ # build necessary cmake args
114+ if [[ " ${platforms[@]} " =~ " device " ]]; then
115+ echo " Build cmake args for device"
116+ ios_location=${DEVICE_IOS_PLATFORM_LOCATION}
117+ osx_sysroot=${DEVICE_OSX_SYSROOT}
118+ xcode_platforms=" -${DEVICE_OSX_SYSROOT} "
119+ for arch in ${architectures[@]} ; do
120+ if [[ " ${DEVICE_ARCHITECTURES[@]} " =~ " ${arch} " ]]; then
121+ if [ " $cmake_archs " == " " ]; then
122+ cmake_archs=${arch}
123+ else
124+ cmake_archs=" ${cmake_archs} ;${arch} "
125+ fi
126+ fi
127+ done
128+ fi
129+
130+ if [[ " ${platforms[@]} " =~ " simulator " ]]; then
131+ echo " Build cmake args for simulator"
132+ if [ " $ios_location " == " " ]; then
133+ ios_location=${SIMULATOR_IOS_PLATFORM_LOCATION}
134+ else
135+ ios_location=" ${ios_location} ;${SIMULATOR_IOS_PLATFORM_LOCATION} "
136+ fi
137+ if [ " $osx_sysroot " == " " ]; then
138+ osx_sysroot=${SIMULATOR_OSX_SYSROOT}
139+ else
140+ osx_sysroot=" ${osx_sysroot} ;${SIMULATOR_OSX_SYSROOT} "
141+ fi
142+ if [ " $xcode_platforms " == " " ]; then
143+ xcode_platforms=" -${SIMULATOR_OSX_SYSROOT} "
144+ else
145+ xcode_platforms=" ${xcode_platforms} ;-${SIMULATOR_OSX_SYSROOT} "
146+ fi
147+
148+ for arch in ${architectures[@]} ; do
149+ if [[ " ${SIMULATOR_ARCHITECTURES[@]} " =~ " ${arch} " ]]; then
150+ if [ " $cmake_archs " == " " ]; then
151+ cmake_archs=${arch}
152+ else
153+ if [[ ! " ${DEVICE_ARCHITECTURES[@]} " =~ " ${arch} " ]]; then
154+ cmake_archs=" ${cmake_archs} ;${arch} "
155+ fi
156+ fi
157+ fi
158+ done
159+ fi
160+
161+ echo " *********************** CMake Args *******************************"
162+ echo " ios_location: ${ios_location} "
163+ echo " osx_sysroot: ${osx_sysroot} "
164+ echo " xcode_platforms: ${xcode_platforms} "
165+ echo " cmake_archs: ${cmake_archs} "
166+ echo " ***************************************************************************"
102167
103168# Stop display commands being run.
104169set +x
@@ -107,17 +172,17 @@ set +x
107172FIRST_FAILED_EXITCODE=0
108173
109174function check_exit_code {
110- if [ " $1 " -ne " 0" ] && [ " $FIRST_FAILED_EXITCODE " -eq 0 ]; then
111- FIRST_FAILED_EXITCODE=$1
112- fi
175+ if [ " $1 " -ne " 0" ] && [ " $FIRST_FAILED_EXITCODE " -eq 0 ]; then
176+ FIRST_FAILED_EXITCODE=$1
177+ fi
113178}
114179
115180CMAKE_OPTIONS=" -DFIREBASE_UNITY_BUILD_TESTS=ON"
116181CMAKE_OPTIONS=" ${CMAKE_OPTIONS} -DFIREBASE_CPP_BUILD_STUB_TESTS=ON" # enable a stub gtest target to get abseil-cpp working.
117182
118183if [ -d " ../firebase-cpp-sdk" ]; then
119- REAL_PATH=` python -c " import os; print(os.path.realpath('../firebase-cpp-sdk'))" `
120- CMAKE_OPTIONS=" ${CMAKE_OPTIONS} -DFIREBASE_CPP_SDK_DIR=$REAL_PATH "
184+ REAL_PATH=$( python -c " import os; print(os.path.realpath('../firebase-cpp-sdk'))" )
185+ CMAKE_OPTIONS=" ${CMAKE_OPTIONS} -DFIREBASE_CPP_SDK_DIR=$REAL_PATH "
121186fi
122187
123188# Display commands being run.
@@ -128,25 +193,28 @@ mkdir -p "$buildpath"
128193
129194pushd " $buildpath "
130195
131- # Configure cmake with option value
132- cmake $sourcepath \
196+ # Configure cmake with option value
197+ cmake $sourcepath \
133198 -DCMAKE_TOOLCHAIN_FILE=$sourcepath /cmake/unity_ios.cmake \
134- -DCMAKE_OSX_ARCHITECTURES=$SUPPORTED_ARCHITECTURES \
199+ -DCMAKE_OSX_ARCHITECTURES=$cmake_archs \
200+ -DCMAKE_OSX_SYSROOT=$osx_sysroot \
201+ -DCMAKE_XCODE_EFFECTIVE_PLATFORMS=$xcode_platforms \
202+ -DIOS_PLATFORM_LOCATION=$ios_location \
135203 -DUNITY_ROOT_DIR=${UNITY_ROOT_DIR} \
136204 $CMAKE_OPTIONS \
137205 $cmake_extra
138- check_exit_code $?
206+ check_exit_code $?
139207
140- # Build the SDK
141- make
142- check_exit_code $?
208+ # Build the SDK
209+ make
210+ check_exit_code $?
143211
144- # Package build output into zip
145- cpack .
146- check_exit_code $?
212+ # Package build output into zip
213+ cpack .
214+ check_exit_code $?
147215
148- # Stop display commands being run.
149- set +x
216+ # Stop display commands being run.
217+ set +x
150218
151219popd
152220
0 commit comments