Skip to content

Instantly share code, notes, and snippets.

@4brunu
Created February 17, 2021 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 4brunu/a1f9078c3b4947331f9e4e17524ca89e to your computer and use it in GitHub Desktop.
Save 4brunu/a1f9078c3b4947331f9e4e17524ca89e to your computer and use it in GitHub Desktop.
#! /usr/bin/env bash
# IOS.cmake
# Architectures: i386 armv7 armv7s x86_64 arm64
# declare -a ABIs=("SIMULATOR" "OS")
# declare -a ABIs=("SIMULATOR")
# declare -a ABIs=("OS")
# declare -a BUILD_TYPES=("Debug" "Release")
# declare -a BUILD_TYPES=("Debug")
# declare -a BUILD_TYPES=("Release")
while [[ $# -gt 1 ]]
do
key="$1"
case $key in
-a|--abis)
IFS=';' read -ra ABIs <<< "$2"
shift # past argument
;;
-b|--build_types)
IFS=';' read -ra BUILD_TYPES <<< "$2"
shift # past argument
;;
-l|--lipo_static_libraries)
IFS=';' read -ra LIPO_STATIC_LIBRARIES <<< "$2"
shift # past argument
;;
-s|--source_dir_cmake)
IFS=';' read -ra SOURCE_DIR_CMAKE <<< "$2"
shift # past argument
;;
*)
# unknown option
;;
esac
shift # past argument or value
done
echo BUILD_TYPES = "${BUILD_TYPES}"
echo ABIs = "${ABIs}"
echo LIPO_STATIC_LIBRARIES = "${LIPO_STATIC_LIBRARIES}"
echo SOURCE_DIR_CMAKE = "${SOURCE_DIR_CMAKE}"
if [ ! "$ABIs" ] || [ ! "$BUILD_TYPES" ] || [ ! "$LIPO_STATIC_LIBRARIES" ]
then
echo "Usage: sh run_cmake_ios.sh --source_dir_cmake <path/to/cmake/source/dir> --build_types <Debug;Release> --abis <OS;SIMULATOR> --lipo_static_libraries <json11;sqlite3;SQLiteCpp>"
exit 1
fi
#http://stackoverflow.com/a/38843585/976628
r=$(git rev-parse --git-dir) && r=$(cd "$r" && pwd)/
git_root_dir="${r%%/.git/*}"
echo git_root_dir = "${git_root_dir}"
if [ ! "$git_root_dir" ]
then
echo "Unable to get git root directory... Are you inside a git repository? Run the following command to check the error: git rev-parse --show-toplevel"
exit 1
fi
begin=$(date +"%s")
echo "##################"
echo "Clean up"
echo "##################"
rm -rf "$git_root_dir/tools/cmake/build/ios"
for ABI in "${ABIs[@]}"
do
echo ABI = "$ABI"
for BUILD_TYPE in "${BUILD_TYPES[@]}"
do
echo BUILD_TYPE = "$BUILD_TYPE"
for LIPO_STATIC_LIBRARY in "${LIPO_STATIC_LIBRARIES[@]}"
do
echo LIPO_STATIC_LIBRARY = "$LIPO_STATIC_LIBRARY"
#Remove old library
for ABI in "${ABIs[@]}"
do
rm -rf "$git_root_dir/tools/cmake/bin/ios/$BUILD_TYPE/$ABI/lib${LIPO_STATIC_LIBRARY}.a"
done
echo "---"
done
echo "-----"
done
echo "----------"
done
echo "##################"
echo "Build libraries"
echo "##################"
for ABI in "${ABIs[@]}"
do
echo ABI = "$ABI"
mkdir -p "$git_root_dir/tools/cmake/build/ios/$ABI"
cmake -G"Xcode" \
-DSOURCE_DIR_CMAKE=$SOURCE_DIR_CMAKE \
-DCMAKE_TOOLCHAIN_FILE="$git_root_dir/deps/ios-cmake/ios.toolchain.cmake" \
-DPLATFORM=$ABI \
-B"$git_root_dir/tools/cmake/build/ios/$ABI" -H.
for BUILD_TYPE in "${BUILD_TYPES[@]}"
do
echo BUILD_TYPE = "$BUILD_TYPE"
cmake --build "$git_root_dir/tools/cmake/build/ios/$ABI" \
--target ALL_BUILD --config $BUILD_TYPE
echo "---"
done
echo "----------"
done
echo "##################"
# Put all librarues in the fat file.
echo "Create FAT library!"
echo "##################"
for BUILD_TYPE in "${BUILD_TYPES[@]}"
do
echo BUILD_TYPE = "$BUILD_TYPE"
mkdir -p "$git_root_dir/tools/cmake/bin/ios/$BUILD_TYPE/UNIVERSAL"
for LIPO_STATIC_LIBRARY in "${LIPO_STATIC_LIBRARIES[@]}"
do
echo LIPO_STATIC_LIBRARY = "$LIPO_STATIC_LIBRARY"
LIPO_LIBRARIES=$(
for ABI in "${ABIs[@]}"
do
echo "$git_root_dir/tools/cmake/bin/ios/$BUILD_TYPE/$ABI/lib${LIPO_STATIC_LIBRARY}.a"
done
)
echo LIPO_LIBRARIES = $LIPO_LIBRARIES
rm -rf "$git_root_dir/tools/cmake/bin/ios/$BUILD_TYPE/UNIVERSAL/lib${LIPO_STATIC_LIBRARY}.a"
lipo -create -output "$git_root_dir/tools/cmake/bin/ios/$BUILD_TYPE/UNIVERSAL/lib${LIPO_STATIC_LIBRARY}.a" \
$LIPO_LIBRARIES
lipo -info "$git_root_dir/tools/cmake/bin/ios/$BUILD_TYPE/UNIVERSAL/lib${LIPO_STATIC_LIBRARY}.a"
echo "-----"
done
echo "----------"
done
termin=$(date +"%s")
difftimelps=$(($termin-$begin))
echo "##################"
echo "Done in $(($difftimelps / 60)) minutes and $(($difftimelps % 60)) seconds"
echo "##################"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment