• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
11set -e
12
13if [ -z "$ANDROID_NDK" ]
14then
15  echo "ANDROID_NDK not set; please set it to the Android NDK directory"
16  exit 1
17fi
18
19if [ ! -d "$ANDROID_NDK" ]
20then
21  echo "ANDROID_NDK not a directory; did you install it under ${ANDROID_NDK}?"
22  exit 1
23fi
24
25mkdir -p build/android/arm64-v8a
26
27CMAKE_ARGS=()
28
29# CMake-level configuration
30CMAKE_ARGS+=("-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake")
31CMAKE_ARGS+=("-DCMAKE_BUILD_TYPE=Release")
32CMAKE_ARGS+=("-DCMAKE_POSITION_INDEPENDENT_CODE=ON")
33
34# If Ninja is installed, prefer it to Make
35if [ -x "$(command -v ninja)" ]
36then
37  CMAKE_ARGS+=("-GNinja")
38fi
39
40CMAKE_ARGS+=("-DXNNPACK_LIBRARY_TYPE=static")
41
42CMAKE_ARGS+=("-DXNNPACK_BUILD_BENCHMARKS=ON")
43CMAKE_ARGS+=("-DXNNPACK_BUILD_TESTS=ON")
44
45# Cross-compilation options for Google Benchmark
46CMAKE_ARGS+=("-DHAVE_POSIX_REGEX=0")
47CMAKE_ARGS+=("-DHAVE_STEADY_CLOCK=0")
48CMAKE_ARGS+=("-DHAVE_STD_REGEX=0")
49
50# Android-specific options
51CMAKE_ARGS+=("-DANDROID_NDK=$ANDROID_NDK")
52CMAKE_ARGS+=("-DANDROID_ABI=arm64-v8a")
53CMAKE_ARGS+=("-DANDROID_PLATFORM=android-21")
54CMAKE_ARGS+=("-DANDROID_PIE=ON")
55CMAKE_ARGS+=("-DANDROID_STL=c++_static")
56CMAKE_ARGS+=("-DANDROID_CPP_FEATURES=exceptions")
57
58# Use-specified CMake arguments go last to allow overridding defaults
59CMAKE_ARGS+=($@)
60
61cd build/android/arm64-v8a && cmake ../../.. \
62    "${CMAKE_ARGS[@]}"
63
64# Cross-platform parallel build
65if [ "$(uname)" == "Darwin" ]
66then
67  cmake --build . -- "-j$(sysctl -n hw.ncpu)"
68else
69  cmake --build . -- "-j$(nproc)"
70fi
71