Ios build example
GitOrigin-RevId: fb1b29dbc054e6362272f4bda82a17866ee74770
This commit is contained in:
parent
34d46fb58c
commit
f8429cf2b4
@ -177,7 +177,6 @@ set (CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS su
|
|||||||
# set the architecture for iOS
|
# set the architecture for iOS
|
||||||
if (IOS_PLATFORM STREQUAL "OS")
|
if (IOS_PLATFORM STREQUAL "OS")
|
||||||
set (IOS_ARCH "armv7;armv7s;arm64")
|
set (IOS_ARCH "armv7;armv7s;arm64")
|
||||||
set (IOS_ARCH "armv7;arm64")
|
|
||||||
elseif (IOS_PLATFORM STREQUAL "SIMULATOR")
|
elseif (IOS_PLATFORM STREQUAL "SIMULATOR")
|
||||||
set (IOS_ARCH "i386;x86_64")
|
set (IOS_ARCH "i386;x86_64")
|
||||||
elseif (IOS_PLATFORM STREQUAL "WATCHOS")
|
elseif (IOS_PLATFORM STREQUAL "WATCHOS")
|
||||||
|
@ -123,6 +123,7 @@ elseif (CLANG OR GCC)
|
|||||||
if (APPLE)
|
if (APPLE)
|
||||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-dead_strip,-x,-S")
|
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-dead_strip,-x,-S")
|
||||||
else()
|
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_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")
|
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections -Wl,--exclude-libs,ALL")
|
||||||
endif()
|
endif()
|
||||||
|
26
example/ios/README.md
Normal file
26
example/ios/README.md
Normal file
@ -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.
|
||||||
|
|
||||||
|
|
21
example/ios/build-openssl.sh
Executable file
21
example/ios/build-openssl.sh
Executable file
@ -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
|
71
example/ios/build.sh
Executable file
71
example/ios/build.sh
Executable file
@ -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
|
Loading…
Reference in New Issue
Block a user