Enhance build_ios.sh to be consistent with build_android.sh (#18564)

Summary:
1, Enhance build_ios.sh to be consistent with build_android.sh;
2, Add docs for build_ios.sh.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/18564

Differential Revision: D14680752

Pulled By: soumith

fbshipit-source-id: 6d2667ed8a3c85a057a522838f5d0461dd4788cf
This commit is contained in:
Gemfield
2019-03-28 21:35:17 -07:00
committed by Facebook Github Bot
parent 3752916132
commit 1c3428af31
2 changed files with 24 additions and 2 deletions

View File

@ -21,3 +21,20 @@ You can also override the cmake flags via command line, e.g., following command
```bash
bash scripts/build_android.sh -DBUILD_BINARY=ON
```
## build_ios.sh
This script is to build PyTorch/Caffe2 library for iOS, and can only be performed on macOS. Take the following steps to start the build:
- Install Xcode from App Store, and configure "Command Line Tools" properly on Xcode.
- Install the dependencies:
```bash
brew install cmake automake libtool
```
- run build_ios.sh
```bash
#in your PyTorch root directory
bash scripts/build_ios.sh
```
If succeeded, the libraries and headers would be generated to build_ios/install directory. You can then copy these files to your Xcode project for further usage.

View File

@ -18,6 +18,7 @@ $CAFFE2_ROOT/scripts/build_host_protoc.sh --other-flags $BITCODE_FLAGS
# Now, actually build the iOS target.
BUILD_ROOT=${BUILD_ROOT:-"$CAFFE2_ROOT/build_ios"}
INSTALL_PREFIX=${BUILD_ROOT}/install
mkdir -p $BUILD_ROOT
cd $BUILD_ROOT
@ -79,12 +80,16 @@ fi
CMAKE_ARGS+=("-DCMAKE_C_FLAGS=-fembed-bitcode")
CMAKE_ARGS+=("-DCMAKE_CXX_FLAGS=-fembed-bitcode")
cmake "$CAFFE2_ROOT" \
-DCMAKE_INSTALL_PREFIX=../install \
-DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
${CMAKE_ARGS[@]} \
$@
cmake --build . -- "-j$(sysctl -n hw.ncpu)"
# copy headers and libs to install directory
echo "Will install headers and libs to $INSTALL_PREFIX for further Xcode project usage."
make install
echo "Installation completed, now you can copy the headers/libs from $INSTALL_PREFIX to your Xcode project directory."