2021-12-31 12:12:40 +08:00
#!/bin/bash
# exit this script if any commmand fails
set -e
DIR = " $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd ) "
2022-07-10 09:47:41 +08:00
AXIS_ROOT = " $DIR " /../..
2021-12-31 12:12:40 +08:00
CPU_CORES = 4
function do_retry( )
{
cmd = $@
retry_times = 5
retry_wait = 3
c = 0
while [ $c -lt $(( retry_times+1)) ] ; do
c = $(( c+1))
echo " Executing \" $cmd \", try $c "
$cmd && return $?
if [ ! $c -eq $retry_times ] ; then
echo " Command failed, will retry in $retry_wait secs "
sleep $retry_wait
else
echo "Command failed, giving up."
return 1
fi
done
}
function build_linux( )
{
# source ../environment.sh
2022-07-10 09:47:41 +08:00
cd $AXIS_ROOT
2021-12-31 12:12:40 +08:00
set -x
2022-02-17 17:11:17 +08:00
cmake . -G "Unix Makefiles" -Bbuild -DCMAKE_BUILD_TYPE= Release -DAX_ENABLE_EXT_IMGUI= ON
2022-05-23 21:55:30 +08:00
cmake --build build --target cpp_tests -- -j ` nproc`
2021-12-31 12:12:40 +08:00
set +x
}
function build_osx( )
{
NUM_OF_CORES = ` getconf _NPROCESSORS_ONLN`
2022-07-10 09:47:41 +08:00
cd $AXIS_ROOT
2021-12-31 12:12:40 +08:00
mkdir -p build
2022-02-17 17:11:17 +08:00
cmake -S . -B build -GXcode -DAX_ENABLE_EXT_IMGUI= ON -DAX_USE_ALSOFT= ON
2022-05-23 21:55:30 +08:00
cmake --build build --config Release --target cpp_tests -- -quiet
2021-12-31 12:12:40 +08:00
exit 0
}
function build_ios( )
{
NUM_OF_CORES = ` getconf _NPROCESSORS_ONLN`
2022-07-10 09:47:41 +08:00
cd $AXIS_ROOT
2021-12-31 12:12:40 +08:00
2022-02-17 17:11:17 +08:00
cmake -S . -B build -GXcode -DCMAKE_TOOLCHAIN_FILE= cmake/ios.mini.cmake -DCMAKE_OSX_ARCHITECTURES= x86_64 -DAX_USE_ALSOFT= ON
2021-12-31 12:12:40 +08:00
# cmake .. -GXcode -DCMAKE_TOOLCHAIN_FILE=../cmake/ios.toolchain.cmake -DCMAKE_SYSTEM_NAME=iOS -DPLATFORM=OS -DENABLE_ARC=0 # too much logs on console when "cmake --build ."
2022-05-23 21:55:30 +08:00
cmake --build build --config Release --target cpp_tests -- -quiet -jobs $NUM_OF_CORES -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)"
2021-12-31 12:12:40 +08:00
exit 0
}
function build_android( )
{
2022-01-28 15:01:42 +08:00
# print jdk detail
echo " JAVA_HOME= $JAVA_HOME "
java -version
2021-12-31 12:12:40 +08:00
# Build all samples
echo "Building Android samples ..."
source ../environment.sh
2022-05-23 21:55:30 +08:00
# build fairygui_tests
2022-07-10 09:47:41 +08:00
pushd $AXIS_ROOT /tests/fairygui-tests/proj.android
2022-01-08 00:08:12 +08:00
do_retry ./gradlew assembleRelease -PPROP_BUILD_TYPE= cmake -PPROP_APP_ABI= $BUILD_ARCH --parallel --info
popd
2022-05-23 21:55:30 +08:00
# build cpp_tests
2022-07-10 09:47:41 +08:00
pushd $AXIS_ROOT /tests/cpp-tests/proj.android
2021-12-31 12:12:40 +08:00
do_retry ./gradlew assembleRelease -PPROP_BUILD_TYPE= cmake -PPROP_APP_ABI= $BUILD_ARCH --parallel --info
popd
}
function run_build( )
{
echo "Building..."
if [ $BUILD_TARGET = = 'osx' ] ; then
set -x
build_osx
exit 0
fi
if [ $BUILD_TARGET = = 'ios' ] ; then
set -x
build_ios
exit 0
fi
# linux
if [ $BUILD_TARGET = = 'linux' ] ; then
build_linux
fi
# android
if [ $BUILD_TARGET = = 'android' ] ; then
build_android
fi
}
run_build