blob: dea138be338eccdb65ef77a29ae130cc9f5925b8 [file] [log] [blame]
James Conroy210897d2022-08-04 16:55:05 +01001#!/bin/bash
2#
Tracy Narine2883a862024-02-26 15:05:11 +00003# Copyright © 2022, 2024 Arm Ltd and Contributors. All rights reserved.
James Conroy210897d2022-08-04 16:55:05 +01004# 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 \
Kevin Mayce8c0632022-12-16 12:43:13 +000080 wget \
Nikhil Rajba6dcb22023-11-24 16:25:10 +000081 xxd \
82 llvm
James Conroy210897d2022-08-04 16:55:05 +010083
84 # Install cross compile toolchains if host is x86_64
85 if [ "$HOST_ARCH" == "x86_64" ]; then
86 apt-get update && apt-get install -y --no-install-recommends \
James Conroye6f30ad2022-09-08 12:04:26 +010087 crossbuild-essential-arm64
James Conroy210897d2022-08-04 16:55:05 +010088 fi
89
90 apt-get clean
91 rm -rf /var/lib/apt/lists/*
92}
93
Tracy Narine2883a862024-02-26 15:05:11 +000094usage_darwin()
95{
96 cat <<EOF
97The $osname platform requires manual setup:
980) Install the command line developer tools (at a minimum)
991) Install homebrew and then run the following in a terminal:
100 1) brew install cmake
101 2) brew install scons
102 3) brew install gnu-getopt
103 4) brew install wget
104EOF
105}
106
107osname=$(uname)
108if [ "$osname" == "Darwin" ]; then
109 usage_darwin
110 exit 1
111fi
112
James Conroy210897d2022-08-04 16:55:05 +0100113name=$(basename "$0")
114
115if [ ! "$(id -u)" -eq 0 ]; then
116 echo -e "\nERROR: $name must be ran as root (i.e. sudo ./$name)"
117 exit 1
118fi
119
120echo -e "\n***** $name: Installing system-wide packages required by setup-armnn.sh and build-armnn.sh *****"
121echo -e "\nINFO: This script downloads and builds CMake from source in the current directory from which this script is called"
122echo -e "\nINFO: CMake and other apt packages will be installed system-wide once this script has completed execution"
James Conroy210897d2022-08-04 16:55:05 +0100123
124install_apt_packages
125
126# Download, Build and Install CMake if not already present
127if [[ "$(cmake --version 2> /dev/null | grep "$CMAKE_VERSION" )" == *"$CMAKE_VERSION"* ]]; then
128 echo -e "\n***** CMake $CMAKE_VERSION already installed, skipping CMake install *****"
129else
130 download_cmake
131 install_cmake
132fi
133
134echo -e "\n***** $name: Successfully installed system-wide packages required by setup-armnn.sh and build-armnn.sh *****\n"
135
136exit 0