2014-03-20 23:21:28 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2014-03-21 00:15:09 +00:00
|
|
|
#
|
|
|
|
# Written and maintained by the.arul@gmail.com (2014)
|
|
|
|
#
|
2014-03-20 23:21:28 +00:00
|
|
|
|
|
|
|
BUILD_DIR="./lib/iOS"
|
|
|
|
|
2018-03-19 11:17:18 +00:00
|
|
|
###################################
|
|
|
|
# SDK Version
|
|
|
|
###################################
|
|
|
|
IOS_SDK_VERSION=$(xcodebuild -version -sdk iphoneos | grep SDKVersion | cut -f2 -d ':' | tr -d '[[:space:]]')
|
|
|
|
###################################
|
2014-03-20 23:21:28 +00:00
|
|
|
|
2018-05-28 14:36:43 +00:00
|
|
|
###################################
|
|
|
|
# BUILD Configuration
|
|
|
|
###################################
|
|
|
|
|
2018-03-20 11:46:03 +00:00
|
|
|
BUILD_SHARED_LIBS=OFF
|
2018-05-30 06:21:28 +00:00
|
|
|
BUILD_TYPE=Release
|
2018-03-19 13:49:16 +00:00
|
|
|
|
2018-03-19 11:17:18 +00:00
|
|
|
################################################
|
|
|
|
# Minimum iOS deployment target version
|
|
|
|
################################################
|
2018-05-28 14:36:43 +00:00
|
|
|
MIN_IOS_VERSION="6.0"
|
2014-03-20 23:21:28 +00:00
|
|
|
|
2018-03-19 11:17:18 +00:00
|
|
|
IOS_SDK_TARGET=$MIN_IOS_VERSION
|
|
|
|
XCODE_ROOT_DIR=$(xcode-select --print-path)
|
|
|
|
TOOLCHAIN=$XCODE_ROOT_DIR/Toolchains/XcodeDefault.xctoolchain
|
|
|
|
|
2018-06-27 08:39:14 +00:00
|
|
|
CMAKE_C_COMPILER=$(xcrun -find cc)
|
|
|
|
CMAKE_CXX_COMPILER=$(xcrun -find c++)
|
|
|
|
|
2018-05-30 06:40:18 +00:00
|
|
|
BUILD_ARCHS_DEVICE="arm64 armv7s armv7"
|
2018-03-20 15:09:50 +00:00
|
|
|
BUILD_ARCHS_SIMULATOR="x86_64 i386"
|
2018-05-30 06:40:18 +00:00
|
|
|
BUILD_ARCHS_ALL=($BUILD_ARCHS_DEVICE $BUILD_ARCHS_SIMULATOR)
|
2014-03-20 23:21:28 +00:00
|
|
|
|
|
|
|
CPP_DEV_TARGET_LIST=(miphoneos-version-min mios-simulator-version-min)
|
|
|
|
CPP_DEV_TARGET=
|
|
|
|
CPP_STD_LIB_LIST=(libc++ libstdc++)
|
|
|
|
CPP_STD_LIB=
|
2017-01-25 07:38:20 +00:00
|
|
|
CPP_STD_LIST=(c++11 c++14)
|
2018-06-27 08:39:14 +00:00
|
|
|
CPP_STD=c++11
|
2014-03-20 23:21:28 +00:00
|
|
|
|
|
|
|
function join { local IFS="$1"; shift; echo "$*"; }
|
|
|
|
|
|
|
|
build_arch()
|
|
|
|
{
|
|
|
|
IOS_SDK_DEVICE=iPhoneOS
|
|
|
|
CPP_DEV_TARGET=${CPP_DEV_TARGET_LIST[0]}
|
|
|
|
|
|
|
|
if [[ "$BUILD_ARCHS_SIMULATOR" =~ "$1" ]]
|
|
|
|
then
|
|
|
|
echo '[!] Target SDK set to SIMULATOR.'
|
|
|
|
IOS_SDK_DEVICE=iPhoneSimulator
|
|
|
|
CPP_DEV_TARGET=${CPP_DEV_TARGET_LIST[1]}
|
|
|
|
else
|
|
|
|
echo '[!] Target SDK set to DEVICE.'
|
|
|
|
fi
|
|
|
|
|
2018-06-27 10:04:49 +00:00
|
|
|
unset DEVROOT SDKROOT CFLAGS LDFLAGS CPPFLAGS CXXFLAGS CMAKE_CLI_INPUT
|
2018-05-30 06:21:28 +00:00
|
|
|
|
2018-05-30 06:40:18 +00:00
|
|
|
#export CC="$(xcrun -sdk iphoneos -find clang)"
|
|
|
|
#export CPP="$CC -E"
|
2018-03-19 11:17:18 +00:00
|
|
|
export DEVROOT=$XCODE_ROOT_DIR/Platforms/$IOS_SDK_DEVICE.platform/Developer
|
2014-03-20 23:21:28 +00:00
|
|
|
export SDKROOT=$DEVROOT/SDKs/$IOS_SDK_DEVICE$IOS_SDK_VERSION.sdk
|
2018-05-30 06:21:28 +00:00
|
|
|
export CFLAGS="-arch $1 -pipe -no-cpp-precomp -stdlib=$CPP_STD_LIB -isysroot $SDKROOT -I$SDKROOT/usr/include/ -miphoneos-version-min=$IOS_SDK_TARGET"
|
2018-06-27 10:26:01 +00:00
|
|
|
if [[ "$BUILD_TYPE" =~ "Debug" ]]; then
|
|
|
|
export CFLAGS="$CFLAGS -Og"
|
|
|
|
else
|
|
|
|
export CFLAGS="$CFLAGS -O3"
|
|
|
|
fi
|
2018-05-30 06:21:28 +00:00
|
|
|
export LDFLAGS="-arch $1 -isysroot $SDKROOT -L$SDKROOT/usr/lib/"
|
2018-06-27 10:04:49 +00:00
|
|
|
export CPPFLAGS="$CFLAGS"
|
2016-06-24 09:17:36 +00:00
|
|
|
export CXXFLAGS="$CFLAGS -std=$CPP_STD"
|
2014-03-20 23:21:28 +00:00
|
|
|
|
|
|
|
rm CMakeCache.txt
|
2018-06-27 10:04:49 +00:00
|
|
|
|
|
|
|
CMAKE_CLI_INPUT="-DCMAKE_C_COMPILER=$CMAKE_C_COMPILER -DCMAKE_CXX_COMPILER=$CMAKE_CXX_COMPILER -DCMAKE_TOOLCHAIN_FILE=./port/iOS/IPHONEOS_$(echo $1 | tr '[:lower:]' '[:upper:]')_TOOLCHAIN.cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DENABLE_BOOST_WORKAROUND=ON -DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS"
|
|
|
|
|
|
|
|
echo "[!] Running CMake with -G 'Unix Makefiles' $CMAKE_CLI_INPUT"
|
|
|
|
|
|
|
|
cmake -G 'Unix Makefiles' ${CMAKE_CLI_INPUT}
|
2014-03-20 23:21:28 +00:00
|
|
|
|
|
|
|
echo "[!] Building $1 library"
|
|
|
|
|
2018-06-27 08:39:14 +00:00
|
|
|
xcrun -run make clean
|
2018-06-27 10:26:01 +00:00
|
|
|
xcrun -run make assimp -j 8 -l
|
2018-05-30 06:21:28 +00:00
|
|
|
|
2018-06-27 10:26:01 +00:00
|
|
|
if [[ "$BUILD_SHARED_LIBS" =~ "ON" ]]; then
|
|
|
|
echo "[!] Moving built dynamic libraries into: $BUILD_DIR/$1/"
|
|
|
|
mv ./lib/*.dylib $BUILD_DIR/$1/
|
2018-07-01 11:48:20 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "[!] Moving built static libraries into: $BUILD_DIR/$1/"
|
|
|
|
mv ./lib/*.a $BUILD_DIR/$1/
|
2014-03-20 23:21:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo "[!] $0 - assimp iOS build script"
|
|
|
|
|
|
|
|
CPP_STD_LIB=${CPP_STD_LIB_LIST[0]}
|
2016-06-24 09:17:36 +00:00
|
|
|
CPP_STD=${CPP_STD_LIST[0]}
|
2014-03-20 23:21:28 +00:00
|
|
|
DEPLOY_ARCHS=${BUILD_ARCHS_ALL[*]}
|
|
|
|
DEPLOY_FAT=1
|
|
|
|
|
|
|
|
for i in "$@"; do
|
|
|
|
case $i in
|
2016-06-24 09:17:36 +00:00
|
|
|
-s=*|--std=*)
|
|
|
|
CPP_STD=`echo $i | sed 's/[-a-zA-Z0-9]*=//'`
|
|
|
|
echo "[!] Selecting c++ standard: $CPP_STD"
|
|
|
|
;;
|
2014-03-20 23:21:28 +00:00
|
|
|
-l=*|--stdlib=*)
|
|
|
|
CPP_STD_LIB=`echo $i | sed 's/[-a-zA-Z0-9]*=//'`
|
2014-03-21 00:25:35 +00:00
|
|
|
echo "[!] Selecting c++ std lib: $CPP_STD_LIB"
|
2014-03-20 23:21:28 +00:00
|
|
|
;;
|
|
|
|
-a=*|--archs=*)
|
|
|
|
DEPLOY_ARCHS=`echo $i | sed 's/[-a-zA-Z0-9]*=//'`
|
|
|
|
echo "[!] Selecting architectures: $DEPLOY_ARCHS"
|
|
|
|
;;
|
2018-07-01 11:48:20 +00:00
|
|
|
--debug)
|
2018-05-30 06:21:28 +00:00
|
|
|
BUILD_TYPE=Debug
|
|
|
|
echo "[!] Selecting build type: Debug"
|
2018-05-28 14:36:43 +00:00
|
|
|
;;
|
2018-07-01 11:48:20 +00:00
|
|
|
--shared-lib)
|
2018-05-28 14:36:43 +00:00
|
|
|
BUILD_SHARED_LIBS=ON
|
|
|
|
echo "[!] Will generate dynamic libraries"
|
|
|
|
;;
|
2014-03-20 23:21:28 +00:00
|
|
|
-n|--no-fat)
|
|
|
|
DEPLOY_FAT=0
|
|
|
|
echo "[!] Fat binary will not be created."
|
|
|
|
;;
|
|
|
|
-h|--help)
|
2014-03-21 00:15:09 +00:00
|
|
|
echo " - don't build fat library (--no-fat)."
|
2018-05-30 06:21:28 +00:00
|
|
|
echo " - Include debug information and symbols, no compiler optimizations (--debug)."
|
2018-05-28 14:36:43 +00:00
|
|
|
echo " - generate dynamic libraries rather than static ones (--shared-lib)."
|
2014-03-21 00:15:09 +00:00
|
|
|
echo " - supported architectures (--archs): $(echo $(join , ${BUILD_ARCHS_ALL[*]}) | sed 's/,/, /g')"
|
2016-06-24 09:17:36 +00:00
|
|
|
echo " - supported C++ STD libs (--stdlib): $(echo $(join , ${CPP_STD_LIB_LIST[*]}) | sed 's/,/, /g')"
|
|
|
|
echo " - supported C++ standards (--std): $(echo $(join , ${CPP_STD_LIST[*]}) | sed 's/,/, /g')"
|
2014-03-20 23:21:28 +00:00
|
|
|
exit
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
cd ../../
|
|
|
|
rm -rf $BUILD_DIR
|
|
|
|
|
|
|
|
for ARCH_TARGET in $DEPLOY_ARCHS; do
|
2018-05-30 06:40:18 +00:00
|
|
|
echo "Creating folder: $BUILD_DIR/$ARCH_TARGET"
|
2014-03-20 23:21:28 +00:00
|
|
|
mkdir -p $BUILD_DIR/$ARCH_TARGET
|
2018-05-30 06:40:18 +00:00
|
|
|
echo "Building for arc: $ARCH_TARGET"
|
2014-03-20 23:21:28 +00:00
|
|
|
build_arch $ARCH_TARGET
|
|
|
|
#rm ./lib/libassimp.a
|
|
|
|
done
|
|
|
|
|
2018-03-19 20:51:52 +00:00
|
|
|
|
2018-07-01 11:48:20 +00:00
|
|
|
make_fat_static_or_shared_binary()
|
2018-05-15 10:38:50 +00:00
|
|
|
{
|
|
|
|
LIB_NAME=$1
|
|
|
|
LIPO_ARGS=''
|
2018-03-19 20:51:52 +00:00
|
|
|
for ARCH_TARGET in $DEPLOY_ARCHS; do
|
2018-05-28 13:27:00 +00:00
|
|
|
if [[ "$BUILD_SHARED_LIBS" =~ "ON" ]]; then
|
|
|
|
LIPO_ARGS="$LIPO_ARGS-arch $ARCH_TARGET $BUILD_DIR/$ARCH_TARGET/$LIB_NAME.dylib "
|
|
|
|
else
|
|
|
|
LIPO_ARGS="$LIPO_ARGS-arch $ARCH_TARGET $BUILD_DIR/$ARCH_TARGET/$LIB_NAME.a "
|
|
|
|
fi
|
2018-03-19 20:51:52 +00:00
|
|
|
done
|
2018-07-01 11:48:20 +00:00
|
|
|
if [[ "$BUILD_SHARED_LIBS" =~ "ON" ]]; then
|
|
|
|
LIPO_ARGS="$LIPO_ARGS -create -output $BUILD_DIR/$LIB_NAME-fat.dylib"
|
|
|
|
else
|
|
|
|
LIPO_ARGS="$LIPO_ARGS -create -output $BUILD_DIR/$LIB_NAME-fat.a"
|
|
|
|
fi
|
|
|
|
lipo $LIPO_ARGS
|
|
|
|
}
|
|
|
|
|
|
|
|
make_fat_static_binary()
|
|
|
|
{
|
|
|
|
LIB_NAME=$1
|
|
|
|
LIPO_ARGS=''
|
|
|
|
for ARCH_TARGET in $DEPLOY_ARCHS; do
|
|
|
|
LIPO_ARGS="$LIPO_ARGS-arch $ARCH_TARGET $BUILD_DIR/$ARCH_TARGET/$LIB_NAME.a "
|
|
|
|
done
|
|
|
|
LIPO_ARGS="$LIPO_ARGS -create -output $BUILD_DIR/$LIB_NAME-fat.a"
|
2018-03-19 20:51:52 +00:00
|
|
|
lipo $LIPO_ARGS
|
2018-05-15 10:38:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if [[ "$DEPLOY_FAT" -eq 1 ]]; then
|
|
|
|
echo '[+] Creating fat binaries ...'
|
2018-03-19 20:51:52 +00:00
|
|
|
|
2018-07-01 11:53:05 +00:00
|
|
|
if [[ "$BUILD_TYPE" =~ "Debug" ]]; then
|
|
|
|
make_fat_static_or_shared_binary 'libassimpd'
|
|
|
|
make_fat_static_binary 'libIrrXMLd'
|
|
|
|
make_fat_static_binary 'libzlibstaticd'
|
|
|
|
else
|
|
|
|
make_fat_static_or_shared_binary 'libassimp'
|
|
|
|
make_fat_static_binary 'libIrrXML'
|
|
|
|
make_fat_static_binary 'libzlibstatic'
|
|
|
|
fi
|
2018-05-15 10:38:50 +00:00
|
|
|
|
|
|
|
echo "[!] Done! The fat binaries can be found at $BUILD_DIR"
|
2014-03-20 23:21:28 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
2018-05-15 10:38:50 +00:00
|
|
|
|