Skip to content

Commit

Permalink
Build liblz4.a for iphone
Browse files Browse the repository at this point in the history
  • Loading branch information
wsvn53 committed May 30, 2022
1 parent c9f3dfb commit 2f1dd72
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
android-tools/build
output
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[submodule "android-tools"]
path = android-tools
url = https://github.com/nmeum/android-tools.git
[submodule "ios-cmake"]
path = ios-cmake
url = https://github.com/leetal/ios-cmake.git
[submodule "external/lz4"]
path = external/lz4
url = https://android.googlesource.com/platform/external/lz4
1 change: 1 addition & 0 deletions external/lz4
Submodule lz4 added at baf8b2
1 change: 1 addition & 0 deletions ios-cmake
Submodule ios-cmake added at ab8607
8 changes: 8 additions & 0 deletions porting/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
iphone: lz4
@echo "|-> Making liblz4 ..."

lz4: lz4/iphoneos/arm64 lz4/iphonesimulator/x86_64

lz4/%:
@echo "|-> Making $@ ..."
TARGET=$@ OUTPUT=../output bash ./scripts/make-lz4.sh
28 changes: 28 additions & 0 deletions porting/scripts/defines.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Common Supports:
# - TARGET=lz4/iphoneos/arm64
# - OUTPUT=...

[[ -z "$TARGET" ]] && echo "** ERROR: TARGET is REQUIRED." && exit 1;
[[ -z "$OUTPUT" ]] && echo "** ERROR: OUTPUT is REQUIRED." && exit 1;

LIB_NAME=$(echo "$TARGET" | cut -d/ -f1);
SDK_NAME=$(echo "$TARGET" | cut -d/ -f2);
ARCH_NAME=$(echo "$TARGET" | cut -d/ -f3);

# Src root
SOURCE_ROOT=$(cd $(dirname $0)/../.. && pwd);

# Prepare output path
FULL_OUTPUT=$(cd $OUTPUT && pwd)/$SDK_NAME/$ARCH_NAME;
[[ ! -d $FULL_OUTPUT ]] && mkdir -p $FULL_OUTPUT;

# For iphone, change to platform
PLATFORM=$([[ $SDK_NAME == iphoneos ]] && echo "OS64" || echo "SIMULATOR64");

# Setup iphone deploy target
DEPLOYMENT_TARGET=10.0;

# Setup toolchains
if [[ $SDK_NAME == *iphone* ]]; then
CMAKE_TOOLCHAIN_FILE=$SOURCE_ROOT/ios-cmake/ios.toolchain.cmake;
fi
21 changes: 21 additions & 0 deletions porting/scripts/make-lz4.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

. $(dirname $0)/defines.sh;

echo " - Lib Name: $LIB_NAME";
echo " - SDK Name: $SDK_NAME";
echo " - Arch Name: $ARCH_NAME";
echo " - CMake Toolchain: $CMAKE_TOOLCHAIN_FILE";

cmake_root=$SOURCE_ROOT/external/lz4/contrib/cmake_unofficial/out;

# Clean built products
[[ -d "$cmake_root" ]] && rm -rfv "$cmake_root";
mkdir -pv "$cmake_root";

cd "$cmake_root";

cmake .. -G Xcode -DCMAKE_TOOLCHAIN_FILE=$CMAKE_TOOLCHAIN_FILE -DPLATFORM=$PLATFORM \
-DDEPLOYMENT_TARGET=$DEPLOYMENT_TARGET -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF;
cmake --build . --config Release --target lz4_static;
find . -name "*.a" -exec cp -av {} $FULL_OUTPUT \;

0 comments on commit 2f1dd72

Please sign in to comment.