feat: add option for creating XCFramework and configure minimum iOS target with a build parameter

pull/5648/head
AKosmachyov 2024-07-01 13:00:16 -04:00
parent 0b19b7d73b
commit b3632cd305
3 changed files with 84 additions and 4 deletions

View File

@ -0,0 +1,33 @@
// Export headers for Swift (iOS)
module libassimp {
header "ColladaMetaData.h"
header "GltfMaterial.h"
header "ObjMaterial.h"
header "anim.h"
header "camera.h"
header "cexport.h"
header "cfileio.h"
header "cimport.h"
header "color4.h"
header "commonMetaData.h"
header "config.h"
header "defs.h"
header "importerdesc.h"
header "light.h"
header "material.h"
header "matrix3x3.h"
header "matrix4x4.h"
header "mesh.h"
header "metadata.h"
header "pbrmaterial.h"
header "postprocess.h"
header "quaternion.h"
header "revision.h"
header "scene.h"
header "texture.h"
header "types.h"
header "vector2.h"
header "vector3.h"
header "version.h"
export *
}

View File

@ -1,7 +1,13 @@
# assimp for iOS
(deployment target 6.0+, 32/64bit)
Builds assimp libraries for several iOS CPU architectures at once, and outputs a fat binary from the result.
### Requirements
- cmake
- pkg-config
Note: all these packages can be installed with [brew](https://brew.sh)
Builds assimp libraries for several iOS CPU architectures at once, and outputs a fat binary / XCFramework from the result.
Run the **build.sh** script from the ```./port/iOS/``` directory. See **./build.sh --help** for information about command line options.
@ -15,11 +21,11 @@ shadeds-Mac:iOS arul$ ./build.sh --help
Example:
```bash
cd ./port/iOS/
./build.sh --stdlib=libc++ --archs="armv7 arm64 i386"
./build.sh --stdlib=libc++ --archs="arm64 x86_64" --no-fat --min-version="16.0"
```
Supported architectures/devices:
### Simulator
### Simulator [CPU Architectures](https://docs.elementscompiler.com/Platforms/Cocoa/CpuArchitectures/)
- i386
- x86_64

View File

@ -76,7 +76,7 @@ build_arch()
rm CMakeCache.txt
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 -DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS"
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 -DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS -DASSIMP_BUILD_ZLIB=ON"
echo "[!] Running CMake with -G 'Unix Makefiles' $CMAKE_CLI_INPUT"
@ -102,6 +102,7 @@ CPP_STD_LIB=${CPP_STD_LIB_LIST[0]}
CPP_STD=${CPP_STD_LIST[0]}
DEPLOY_ARCHS=${BUILD_ARCHS_ALL[*]}
DEPLOY_FAT=1
DEPLOY_XCFramework=1
for i in "$@"; do
case $i in
@ -117,6 +118,11 @@ for i in "$@"; do
DEPLOY_ARCHS=`echo $i | sed 's/[-a-zA-Z0-9]*=//'`
echo "[!] Selecting architectures: $DEPLOY_ARCHS"
;;
--min-version=*)
MIN_IOS_VERSION=`echo $i | sed 's/[-a-zA-Z0-9]*=//'`
IOS_SDK_TARGET=$MIN_IOS_VERSION
echo "[!] Selecting minimum iOS version: $MIN_IOS_VERSION"
;;
--debug)
BUILD_TYPE=Debug
echo "[!] Selecting build type: Debug"
@ -129,11 +135,17 @@ for i in "$@"; do
DEPLOY_FAT=0
echo "[!] Fat binary will not be created."
;;
--no-xcframework)
DEPLOY_XCFramework=0
echo "[!] XCFramework will not be created."
;;
-h|--help)
echo " - don't build fat library (--no-fat)."
echo " - don't build XCFramework (--no-xcframework)."
echo " - Include debug information and symbols, no compiler optimizations (--debug)."
echo " - generate dynamic libraries rather than static ones (--shared-lib)."
echo " - supported architectures (--archs): $(echo $(join , ${BUILD_ARCHS_ALL[*]}) | sed 's/,/, /g')"
echo " - minimum iOS version (--min-version): 16.0"
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')"
exit
@ -196,3 +208,32 @@ if [[ "$DEPLOY_FAT" -eq 1 ]]; then
echo "[!] Done! The fat binaries can be found at $BUILD_DIR"
fi
make_xcframework()
{
LIB_NAME=$1
FRAMEWORK_PATH=$BUILD_DIR/$LIB_NAME.xcframework
ARGS = ""
for ARCH_TARGET in $DEPLOY_ARCHS; do
if [[ "$BUILD_SHARED_LIBS" =~ "ON" ]]; then
ARGS="$ARGS -library $BUILD_DIR/$ARCH_TARGET/$LIB_NAME.dylib -headers ./include "
else
ARGS="$ARGS -library $BUILD_DIR/$ARCH_TARGET/$LIB_NAME.a -headers ./include "
fi
done
xcodebuild -create-xcframework $ARGS -output $FRAMEWORK_PATH
}
if [[ "$DEPLOY_XCFramework" -eq 1 ]]; then
echo '[+] Creating XCFramework ...'
if [[ "$BUILD_TYPE" =~ "Debug" ]]; then
make_xcframework 'libassimpd'
else
make_xcframework 'libassimp'
fi
echo "[!] Done! The XCFramework can be found at $BUILD_DIR"
fi