From 1d28119f4a6156ff30023f19ff6bbd69e5a9942c Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 15 Feb 2018 00:41:26 +0300 Subject: [PATCH] Update iOS example README.md. GitOrigin-RevId: df6d7bd81c1d1fdb915cb4bdc6edc80d93bcfed0 --- README.md | 5 +++- example/ios/README.md | 44 ++++++++++++++++++++++-------------- example/ios/build-openssl.sh | 23 ++++++++++--------- example/ios/build.sh | 28 +++++++++++------------ 4 files changed, 57 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index a3787ad77..327caac61 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,8 @@ cmake --build . ### Installing dependencies -#### OS X + +#### macOS * Install the latest Xcode command line tools. * Install other dependencies, for example, using [Homebrew](https://brew.sh): ``` @@ -71,6 +72,7 @@ brew install gperf cmake openssl cmake -DCMAKE_BUILD_TYPE=Release -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl/ .. ``` + #### Windows * Download and install [gperf](https://sourceforge.net/projects/gnuwin32/files/gperf/3.0.1/). Add the path to gperf to the PATH environment variable. * Install [vcpkg](https://github.com/Microsoft/vcpkg#quick-start). @@ -83,6 +85,7 @@ C:\src\vcpkg> .\vcpkg install openssl zlib cmake -DCMAKE_TOOLCHAIN_FILE=C:\src\vcpkg\scripts\buildsystems\vcpkg.cmake .. ``` + #### Linux * Install all dependencies using your package manager. diff --git a/example/ios/README.md b/example/ios/README.md index efc21004a..e44eec0b8 100644 --- a/example/ios/README.md +++ b/example/ios/README.md @@ -1,29 +1,39 @@ # Build for iOS -Bellow are instructions for building TdLib for iOS, watchOS and also macOS. +Below are instructions for building TDLib for iOS, watchOS, tvOS, and also macOS. -If you need just macOS build take a look [here](https://github.com/tdlib/td#os-x). +If you need only a macOS build, take a look at our build instructions for [macOS](https://github.com/tdlib/td#macos). -For example of usage take a look [here](https://github.com/tdlib/td/tree/master/example/swift). +For example of usage take a look at our [Swift example](https://github.com/tdlib/td/tree/master/example/swift). -## Build OpenSSL -First, you should build OpenSSL library for ios +To compile `TDLib` you will need to: +* Install the latest Xcode command line tools. +* Install other build dependencies, for example, using [Homebrew](https://brew.sh): ``` +brew install gperf cmake +``` +* If you don't want to build `TDLib` for macOS, you can pregenerate required source code files using CMake prepare_cross_compiling target: +``` +cd +mkdir native-build +cd native-build +cmake .. +cmake --build . --target prepare_cross_compiling +``` +* Build OpenSSL for iOS, watchOS, tvOS and macOS: +``` +cd /example/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/`. The next script will rely on this location. - -## Build TdLib -Run: +Here we use scripts from [Python Apple support](https://github.com/pybee/Python-Apple-support), but any other OpenSSL builds should work too. +Built libraries should be stored in `third_party/openssl/`, because the next script will rely on this location. +* Build TDLib for iOS, watchOS, tvOS and macOS: ``` +cd /example/ios ./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. - +This may take a while, because TDLib will be built about 10 times. +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. +Built libraries will be store in `tdjson` directory. diff --git a/example/ios/build-openssl.sh b/example/ios/build-openssl.sh index 8e6c53435..2ad9dbcfe 100755 --- a/example/ios/build-openssl.sh +++ b/example/ios/build-openssl.sh @@ -1,21 +1,22 @@ #!/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 + 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 index 0843bcd3a..b179c946b 100755 --- a/example/ios/build.sh +++ b/example/ios/build.sh @@ -10,12 +10,14 @@ for platform in $platforms; do echo "Platform = ${platform} Simulator = ${simulator}" openssl_path=$(realpath ../third_party/openssl/${platform}) - echo $openssl_path + echo "OpenSSL path = ${openssl_path}" + openssl_crypto_library="${openssl_path}/lib/libcrypto.a" + openssl_ssl_library="${openssl_path}/lib/libssl.a" 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_CRYPTO_LIBRARY=${openssl_crypto_library}" + #options="$options -DOPENSSL_SSL_LIBRARY=${openssl_ssl_library}" options="$options -DOPENSSL_INCLUDE_DIR=${openssl_path}/include" - options="$options -DOPENSSL_LIBRARIES=${openssl_path}/lib/libcrypto.a;${openssl_path}/lib/libssl.a" + options="$options -DOPENSSL_LIBRARIES=${openssl_crypto_library};${openssl_ssl_library}" options="$options -DCMAKE_BUILD_TYPE=Release" if [[ $platform = "macOS" ]]; then build="build-${platform}" @@ -38,13 +40,13 @@ do install="install-${platform}" if [[ $simulator = "1" ]]; then build="${build}-simulator" - install="${install}-simulator" - ios_platform="SIMULATOR" + install="${install}-simulator" + ios_platform="SIMULATOR" else ios_platform="OS" fi if [[ $platform = "watchOS" ]]; then - ios_platform="WATCH${ios_platform}" + ios_platform="WATCH${ios_platform}" fi if [[ $platform = "tvOS" ]]; then ios_platform="TV${ios_platform}" @@ -54,9 +56,7 @@ do 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 @@ -65,10 +65,10 @@ do mkdir -p $platform lipo -create $lib $lib_simulator -o $platform/libtdjson.dylib install_name_tool -id @rpath/libtdjson.dylib $platform/libtdjson.dylib - fi + 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/ + 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