James Conroy | 210897d | 2022-08-04 16:55:05 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright © 2022 Arm Ltd and Contributors. All rights reserved. |
| 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
| 7 | # Script which installs system-wide packages required by setup-armnn.sh and build-armnn.sh |
| 8 | # Downloads and builds CMake from source in the current directory from which this script is called |
| 9 | # CMake will be installed system-wide once this script has completed execution |
| 10 | # Requires sudo privileges |
| 11 | |
| 12 | set -o nounset # Catch references to undefined variables. |
| 13 | set -o pipefail # Catch non zero exit codes within pipelines. |
| 14 | set -o errexit # Catch and propagate non zero exit codes. |
| 15 | |
| 16 | # Host architecture e.g. x86_64, aarch64 |
| 17 | HOST_ARCH=$(uname -m) |
| 18 | |
| 19 | # Number of online cores on host |
| 20 | NUM_THREADS=$(getconf _NPROCESSORS_ONLN) |
| 21 | |
| 22 | # CMake is downloaded and built in the current directory from which this script is called |
| 23 | ROOT_DIR=$(pwd) |
| 24 | |
| 25 | # CMake |
| 26 | CMAKE_VERSION=3.19 |
| 27 | CMAKE_VERSION_FULL=3.19.0 |
| 28 | CMAKE_SRC="$ROOT_DIR"/cmake-"$CMAKE_VERSION_FULL" |
| 29 | CMAKE_BUILD="$ROOT_DIR"/cmake_build |
| 30 | |
| 31 | download_cmake() |
| 32 | { |
| 33 | cd "$ROOT_DIR" |
| 34 | |
| 35 | echo -e "\n***** Downloading CMake $CMAKE_VERSION *****" |
| 36 | wget -O cmake-"$CMAKE_VERSION_FULL".tar.gz https://cmake.org/files/v"$CMAKE_VERSION"/cmake-"$CMAKE_VERSION_FULL".tar.gz |
| 37 | |
| 38 | echo -e "\n***** Extracting archive *****" |
| 39 | tar -xzf cmake-"$CMAKE_VERSION_FULL".tar.gz |
| 40 | |
| 41 | echo -e "\n***** Removing archive *****" |
| 42 | rm cmake-"$CMAKE_VERSION_FULL".tar.gz |
| 43 | |
| 44 | echo -e "\n***** CMake $CMAKE_VERSION Downloaded *****" |
| 45 | } |
| 46 | |
| 47 | install_cmake() |
| 48 | { |
| 49 | mkdir -p "$CMAKE_BUILD" |
| 50 | cd "$CMAKE_BUILD" |
| 51 | |
| 52 | apt-get purge -y cmake |
| 53 | |
| 54 | echo -e "\n***** Building CMake $CMAKE_VERSION ***** " |
| 55 | "$CMAKE_SRC"/bootstrap |
| 56 | make |
| 57 | make install -j "$NUM_THREADS" |
| 58 | |
| 59 | if [[ "$(cmake --version 2> /dev/null | grep "$CMAKE_VERSION" )" == *"$CMAKE_VERSION"* ]]; then |
| 60 | echo -e "\n***** Built and Installed CMake $CMAKE_VERSION *****" |
| 61 | else |
| 62 | echo -e "\nERROR: CMake $CMAKE_VERSION not installed correctly after building from source" |
| 63 | exit 1 |
| 64 | fi |
| 65 | } |
| 66 | |
| 67 | install_apt_packages() |
| 68 | { |
| 69 | apt-get update && apt-get install -y --no-install-recommends \ |
| 70 | autoconf \ |
| 71 | automake \ |
| 72 | build-essential \ |
| 73 | curl \ |
| 74 | git \ |
| 75 | libssl-dev \ |
| 76 | libtool \ |
| 77 | make \ |
| 78 | scons \ |
| 79 | unzip \ |
| 80 | wget |
| 81 | |
| 82 | # Install cross compile toolchains if host is x86_64 |
| 83 | if [ "$HOST_ARCH" == "x86_64" ]; then |
| 84 | apt-get update && apt-get install -y --no-install-recommends \ |
James Conroy | e6f30ad | 2022-09-08 12:04:26 +0100 | [diff] [blame] | 85 | crossbuild-essential-arm64 |
James Conroy | 210897d | 2022-08-04 16:55:05 +0100 | [diff] [blame] | 86 | fi |
| 87 | |
| 88 | apt-get clean |
| 89 | rm -rf /var/lib/apt/lists/* |
| 90 | } |
| 91 | |
| 92 | name=$(basename "$0") |
| 93 | |
| 94 | if [ ! "$(id -u)" -eq 0 ]; then |
| 95 | echo -e "\nERROR: $name must be ran as root (i.e. sudo ./$name)" |
| 96 | exit 1 |
| 97 | fi |
| 98 | |
| 99 | echo -e "\n***** $name: Installing system-wide packages required by setup-armnn.sh and build-armnn.sh *****" |
| 100 | echo -e "\nINFO: This script downloads and builds CMake from source in the current directory from which this script is called" |
| 101 | echo -e "\nINFO: CMake and other apt packages will be installed system-wide once this script has completed execution" |
| 102 | echo -e "\nScript execution will begin in 10 seconds..." |
| 103 | |
| 104 | sleep 10 |
| 105 | |
| 106 | install_apt_packages |
| 107 | |
| 108 | # Download, Build and Install CMake if not already present |
| 109 | if [[ "$(cmake --version 2> /dev/null | grep "$CMAKE_VERSION" )" == *"$CMAKE_VERSION"* ]]; then |
| 110 | echo -e "\n***** CMake $CMAKE_VERSION already installed, skipping CMake install *****" |
| 111 | else |
| 112 | download_cmake |
| 113 | install_cmake |
| 114 | fi |
| 115 | |
| 116 | echo -e "\n***** $name: Successfully installed system-wide packages required by setup-armnn.sh and build-armnn.sh *****\n" |
| 117 | |
| 118 | exit 0 |