aboutsummaryrefslogtreecommitdiffhomepage
path: root/example/ios
diff options
context:
space:
mode:
authorArseny Smirnov <arseny30@gmail.com>2018-02-14 13:19:12 +0300
committerArseny Smirnov <arseny30@gmail.com>2018-02-14 13:19:12 +0300
commitf8429cf2b4493c954ed2662802655fdd3ffc8bbd (patch)
tree63634c720f28f4cefa59820f227f8918e5c3c130 /example/ios
parent34d46fb58c03c72a4aed1d4410ec2f415dc65885 (diff)
Ios build example
GitOrigin-RevId: fb1b29dbc054e6362272f4bda82a17866ee74770
Diffstat (limited to 'example/ios')
-rw-r--r--example/ios/README.md26
-rwxr-xr-xexample/ios/build-openssl.sh21
-rwxr-xr-xexample/ios/build.sh71
3 files changed, 118 insertions, 0 deletions
diff --git a/example/ios/README.md b/example/ios/README.md
new file mode 100644
index 000000000..8fdb59b27
--- /dev/null
+++ b/example/ios/README.md
@@ -0,0 +1,26 @@
+# Build for iOS
+
+Bellow are instructions for building TdLib for iOS, watchOS and also macOS.
+If you need just macOS build take a look [here](https://github.com/tdlib/td#os-x)
+
+## Build OpenSSL
+First, you should build OpenSSL library for ios
+```
+./build-openssl.sh
+```
+In this example we are using scripts from [Python Apple support](https://github.com/pybee/Python-Apple-support), but any other OpenSSL builds should work too.
+Libraries will be stored in `third_party/openssl/<platfrom>`. The next script will rely on this location.
+
+## Build TdLib
+Run:
+```
+./build.sh
+```
+This may take a while, because TdLib will be build about 8 times.
+As an upside resulting library for iOS will work on any architecture (arv7, armv7s, arm64) and even on a simulator.
+We use [CMake/iOS.cmake](https://github.com/tdlib/td/blob/master/CMake/iOS.cmake) toolchain, other toolchains
+may work too.
+
+Libraries will be store in `tdjson` directory.
+
+
diff --git a/example/ios/build-openssl.sh b/example/ios/build-openssl.sh
new file mode 100755
index 000000000..8e6c53435
--- /dev/null
+++ b/example/ios/build-openssl.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+git clone https://github.com/pybee/Python-Apple-support
+cd Python-Apple-support
+git checkout 2.7
+cd ..
+#TODO: change openssl version
+platforms="macOS iOS watchOS tvOS"
+#platforms="macOS"
+for platform in $platforms;
+do
+echo $platform
+cd Python-Apple-support
+#NB: -j will fail
+make OpenSSL-$platform
+cd ..
+rm -rf third_party/openssl/$platform
+mkdir -p third_party/openssl/$platform/lib
+cp ./Python-Apple-support/build/$platform/libcrypto.a third_party/openssl/$platform/lib/
+cp ./Python-Apple-support/build/$platform/libssl.a third_party/openssl/$platform/lib/
+cp -r ./Python-Apple-support/build/$platform/Support/OpenSSL/Headers/ third_party/openssl/$platform/include
+done
diff --git a/example/ios/build.sh b/example/ios/build.sh
new file mode 100755
index 000000000..8f65c2001
--- /dev/null
+++ b/example/ios/build.sh
@@ -0,0 +1,71 @@
+#/bin/sh
+td_path=$(realpath ../..)
+
+rm -rf build
+mkdir -p build
+cd build
+
+platforms="watchOS iOS macOS"
+for platform in $platforms;
+do
+ echo "Platform = ${platform} Simulator = ${simulator}"
+ openssl_path=$(realpath ../third_party/openssl/${platform})
+ echo $openssl_path
+ options="$options -DOPENSSL_FOUND=1"
+ options="$options -DOPENSSL_CRYPTO_LIBRARY=${openssl_path}/lib/libcrypto.a"
+ #options="$options -DOPENSSL_SSL_LIBRARY=${openssl_path}/lib/libssl.a"
+ options="$options -DOPENSSL_INCLUDE_DIR=${openssl_path}/include"
+ options="$options -DOPENSSL_LIBRARIES=${openssl_path}/lib/libcrypto.a;${openssl_path}/lib/libssl.a"
+ options="$options -DCMAKE_BUILD_TYPE=Release"
+ if [[ $platform = "macOS" ]]; then
+ build="build-${platform}"
+ install="install-${platform}"
+ rm -rf $build
+ mkdir -p $build
+ mkdir -p $install
+ cd $build
+ cmake $td_path $options -DCMAKE_INSTALL_PREFIX=../${install}
+ make -j3 install || exit
+ cd ..
+ mkdir -p $platform
+ cp $build/libtdjson.dylib $platform/libtdjson.dylib
+ install_name_tool -id @rpath/libtdjson.dylib $platform/libtdjson.dylib
+ else
+ simulators="0 1"
+ for simulator in $simulators;
+ do
+ build="build-${platform}"
+ install="install-${platform}"
+ if [[ $simulator = "1" ]]; then
+ build="${build}-simulator"
+ install="${install}-simulator"
+ ios_platform="SIMULATOR"
+ else
+ ios_platform="OS"
+ fi
+ if [[ $platform = "watchOS" ]]; then
+ ios_platform="WATCH${ios_platform}"
+ fi
+ echo $ios_platform
+ rm -rf $build
+ mkdir -p $build
+ mkdir -p $install
+ cd $build
+ echo "A"
+ cmake $td_path $options -DIOS_PLATFORM=${ios_platform} -DCMAKE_TOOLCHAIN_FILE=${td_path}/CMake/iOS.cmake -DCMAKE_INSTALL_PREFIX=../${install}
+ echo "B"
+ make -j3 install || exit
+ cd ..
+ done
+ lib="install-${platform}/lib/libtdjson.dylib"
+ lib_simulator="install-${platform}-simulator/lib/libtdjson.dylib"
+ mkdir -p $platform
+ lipo -create $lib $lib_simulator -o $platform/libtdjson.dylib
+ install_name_tool -id @rpath/libtdjson.dylib $platform/libtdjson.dylib
+ fi
+
+ mkdir -p ../tdjson/$platform/include
+ rsync --recursive ${install}/include/ ../tdjson/${platform}/include/
+ mkdir -p ../tdjson/$platform/lib
+ cp $platform/libtdjson.dylib ../tdjson/$platform/lib/
+done