diff --git a/CMake/iOS.cmake b/CMake/iOS.cmake index 5f748767c..238379b4c 100644 --- a/CMake/iOS.cmake +++ b/CMake/iOS.cmake @@ -177,7 +177,6 @@ set (CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS su # set the architecture for iOS if (IOS_PLATFORM STREQUAL "OS") set (IOS_ARCH "armv7;armv7s;arm64") - set (IOS_ARCH "armv7;arm64") elseif (IOS_PLATFORM STREQUAL "SIMULATOR") set (IOS_ARCH "i386;x86_64") elseif (IOS_PLATFORM STREQUAL "WATCHOS") diff --git a/CMakeLists.txt b/CMakeLists.txt index 1040f8a33..8b6ff53c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,6 +123,7 @@ elseif (CLANG OR GCC) if (APPLE) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-dead_strip,-x,-S") else() + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffunction-sections -fdata-sections") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections -Wl,--exclude-libs,ALL") endif() 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/`. 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