Marat Dukhan | 2dbdc2f | 2019-10-08 16:36:23 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | # |
| 3 | # Copyright (c) Facebook, Inc. and its affiliates. |
| 4 | # All rights reserved. |
| 5 | # |
| 6 | # Copyright 2019 Google LLC |
| 7 | # |
| 8 | # This source code is licensed under the BSD-style license found in the |
| 9 | # LICENSE file in the root directory of this source tree. |
| 10 | |
| 11 | set -e |
| 12 | |
| 13 | if [ -z "$ANDROID_NDK" ] |
| 14 | then |
| 15 | echo "ANDROID_NDK not set; please set it to the Android NDK directory" |
| 16 | exit 1 |
| 17 | fi |
| 18 | |
| 19 | if [ ! -d "$ANDROID_NDK" ] |
| 20 | then |
| 21 | echo "ANDROID_NDK not a directory; did you install it under ${ANDROID_NDK}?" |
| 22 | exit 1 |
| 23 | fi |
| 24 | |
| 25 | mkdir -p build/android/arm64-v8a |
| 26 | |
| 27 | CMAKE_ARGS=() |
| 28 | |
| 29 | # CMake-level configuration |
| 30 | CMAKE_ARGS+=("-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake") |
| 31 | CMAKE_ARGS+=("-DCMAKE_BUILD_TYPE=Release") |
| 32 | CMAKE_ARGS+=("-DCMAKE_POSITION_INDEPENDENT_CODE=ON") |
| 33 | |
| 34 | # If Ninja is installed, prefer it to Make |
| 35 | if [ -x "$(command -v ninja)" ] |
| 36 | then |
| 37 | CMAKE_ARGS+=("-GNinja") |
| 38 | fi |
| 39 | |
| 40 | CMAKE_ARGS+=("-DXNNPACK_LIBRARY_TYPE=static") |
| 41 | |
| 42 | CMAKE_ARGS+=("-DXNNPACK_BUILD_BENCHMARKS=ON") |
| 43 | CMAKE_ARGS+=("-DXNNPACK_BUILD_TESTS=ON") |
| 44 | |
| 45 | # Cross-compilation options for Google Benchmark |
| 46 | CMAKE_ARGS+=("-DHAVE_POSIX_REGEX=0") |
| 47 | CMAKE_ARGS+=("-DHAVE_STEADY_CLOCK=0") |
| 48 | CMAKE_ARGS+=("-DHAVE_STD_REGEX=0") |
| 49 | |
| 50 | # Android-specific options |
| 51 | CMAKE_ARGS+=("-DANDROID_NDK=$ANDROID_NDK") |
| 52 | CMAKE_ARGS+=("-DANDROID_ABI=arm64-v8a") |
| 53 | CMAKE_ARGS+=("-DANDROID_PLATFORM=android-21") |
| 54 | CMAKE_ARGS+=("-DANDROID_PIE=ON") |
| 55 | CMAKE_ARGS+=("-DANDROID_STL=c++_static") |
| 56 | CMAKE_ARGS+=("-DANDROID_CPP_FEATURES=exceptions") |
| 57 | |
| 58 | # Use-specified CMake arguments go last to allow overridding defaults |
| 59 | CMAKE_ARGS+=($@) |
| 60 | |
| 61 | cd build/android/arm64-v8a && cmake ../../.. \ |
| 62 | "${CMAKE_ARGS[@]}" |
| 63 | |
| 64 | # Cross-platform parallel build |
| 65 | if [ "$(uname)" == "Darwin" ] |
| 66 | then |
| 67 | cmake --build . -- "-j$(sysctl -n hw.ncpu)" |
| 68 | else |
| 69 | cmake --build . -- "-j$(nproc)" |
| 70 | fi |