blob: faedf781c78f875d7a6a8db7d1a44d2ad13bd776 [file] [log] [blame]
Marat Dukhan2dbdc2f2019-10-08 16:36:23 -07001#!/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/armeabi-v7a
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=armeabi-v7a")
53CMAKE_ARGS+=("-DANDROID_PLATFORM=android-14")
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/armeabi-v7a && 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