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 12set -o nounset # Catch references to undefined variables. 13set -o pipefail # Catch non zero exit codes within pipelines. 14set -o errexit # Catch and propagate non zero exit codes. 15 16# Host architecture e.g. x86_64, aarch64 17HOST_ARCH=$(uname -m) 18 19# Number of online cores on host 20NUM_THREADS=$(getconf _NPROCESSORS_ONLN) 21 22# CMake is downloaded and built in the current directory from which this script is called 23ROOT_DIR=$(pwd) 24 25# CMake 26CMAKE_VERSION=3.19 27CMAKE_VERSION_FULL=3.19.0 28CMAKE_SRC="$ROOT_DIR"/cmake-"$CMAKE_VERSION_FULL" 29CMAKE_BUILD="$ROOT_DIR"/cmake_build 30 31download_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 47install_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 67install_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 xxd 82 83 # Install cross compile toolchains if host is x86_64 84 if [ "$HOST_ARCH" == "x86_64" ]; then 85 apt-get update && apt-get install -y --no-install-recommends \ 86 crossbuild-essential-arm64 87 fi 88 89 apt-get clean 90 rm -rf /var/lib/apt/lists/* 91} 92 93name=$(basename "$0") 94 95if [ ! "$(id -u)" -eq 0 ]; then 96 echo -e "\nERROR: $name must be ran as root (i.e. sudo ./$name)" 97 exit 1 98fi 99 100echo -e "\n***** $name: Installing system-wide packages required by setup-armnn.sh and build-armnn.sh *****" 101echo -e "\nINFO: This script downloads and builds CMake from source in the current directory from which this script is called" 102echo -e "\nINFO: CMake and other apt packages will be installed system-wide once this script has completed execution" 103echo -e "\nScript execution will begin in 10 seconds..." 104 105sleep 10 106 107install_apt_packages 108 109# Download, Build and Install CMake if not already present 110if [[ "$(cmake --version 2> /dev/null | grep "$CMAKE_VERSION" )" == *"$CMAKE_VERSION"* ]]; then 111 echo -e "\n***** CMake $CMAKE_VERSION already installed, skipping CMake install *****" 112else 113 download_cmake 114 install_cmake 115fi 116 117echo -e "\n***** $name: Successfully installed system-wide packages required by setup-armnn.sh and build-armnn.sh *****\n" 118 119exit 0