Enhance build_ios.sh to be consistent with build_android.sh (#18564)
authorGemfield <gemfield@civilnet.cn>
Fri, 29 Mar 2019 04:35:17 +0000 (21:35 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 29 Mar 2019 04:37:55 +0000 (21:37 -0700)
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

scripts/README.md
scripts/build_ios.sh

index 07e12e5..06b5eb2 100644 (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. 
\ No newline at end of file
index bc44a3a..194c54f 100755 (executable)
@@ -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."