xref: /aosp_15_r20/external/cpuinfo/scripts/local-build.sh (revision 2b54f0db79fd8303838913b20ff3780cddaa909f)
1#!/usr/bin/env bash
2#
3# Copyright (c) Facebook, Inc. and its affiliates.
4# All rights reserved.
5#
6# This source code is licensed under the BSD-style license found in the
7# LICENSE file in the root directory of this source tree.
8
9set -e
10
11mkdir -p build/local
12
13CMAKE_ARGS=()
14
15# CMake-level configuration
16CMAKE_ARGS+=("-DCMAKE_BUILD_TYPE=Release")
17CMAKE_ARGS+=("-DCMAKE_POSITION_INDEPENDENT_CODE=ON")
18
19# If Ninja is installed, prefer it to Make
20if [ -x "$(command -v ninja)" ]
21then
22  CMAKE_ARGS+=("-GNinja")
23fi
24
25# Use-specified CMake arguments go last to allow overridding defaults
26CMAKE_ARGS+=($@)
27
28cd build/local && cmake ../.. \
29    "${CMAKE_ARGS[@]}"
30
31# Cross-platform parallel build
32if [ "$(uname)" == "Darwin" ]; then
33  cmake --build . -- "-j$(sysctl -n hw.ncpu)"
34elif [ "$(uname)" == "Linux" ]; then
35  cmake --build . -- "-j$(nproc)"
36else
37  cmake --build .
38fi
39