1#!/bin/sh 2# 3# Copyright 2020, Data61, CSIRO (ABN 41 687 119 230) 4# 5# SPDX-License-Identifier: BSD-2-Clause 6# 7 8# This script is intended to be symlinked into the same location as your root 9# CMakeLists.txt file and then invoked from a clean build directory. 10 11set -eu 12 13# Determine path to this script (fast, cheap "dirname"). 14SCRIPT_PATH=${0%/*} 15# Save script name for diagnostic messages (fast, cheap "basename"). 16SCRIPT_NAME=${0##*/} 17 18# Ensure script path and current working directory are not the same. 19if [ "$PWD" = "$SCRIPT_PATH" ] 20then 21 echo "\"$SCRIPT_NAME\" should not be invoked from top-level directory" >&2 22 exit 1 23fi 24 25# Try and make sure we weren't invoked from a source directory by checking for a 26# CMakeLists.txt file. 27if [ -e CMakeLists.txt ] 28then 29 echo "\"$SCRIPT_NAME\" should be invoked from a build directory and not" \ 30 "source directories containing a CMakeLists.txt file" >&2 31 exit 1 32fi 33 34if [ -d "$HOME/.sel4_cache" ] 35then 36 CACHE_DIR="$HOME/.sel4_cache" 37else 38 CACHE_DIR="$SCRIPT_PATH/.sel4_cache" 39fi 40 41if [ -e "$SCRIPT_PATH/CMakeLists.txt" ] 42then 43 # If we have a CMakeLists.txt in the top level project directory, 44 # initialize CMake. 45 cmake -DCMAKE_TOOLCHAIN_FILE="$SCRIPT_PATH"/kernel/gcc.cmake -G Ninja "$@" \ 46 -DSEL4_CACHE_DIR="$CACHE_DIR" -C "$SCRIPT_PATH/settings.cmake" "$SCRIPT_PATH" 47else 48 # If we don't have a CMakeLists.txt in the top level project directory then 49 # assume we use the project's directory tied to easy-settings.cmake and resolve 50 # that to use as the CMake source directory. 51 real_easy_settings="$(realpath $SCRIPT_PATH/easy-settings.cmake)" 52 project_dir="$(dirname $real_easy_settings)" 53 # Initialize CMake. 54 cmake -G Ninja "$@" -DSEL4_CACHE_DIR="$CACHE_DIR" -C "$project_dir/settings.cmake" "$project_dir" 55fi 56