cmvr-es/scripts/build.sh

32 lines
875 B
Bash
Raw Normal View History

#!/usr/bin/env bash
set -euo pipefail
usage() {
echo "Usage: $0 [Debug|Release|RelWithDebInfo] (default: Debug)"
}
if [[ $# -eq 1 && ( $1 == --help || $1 == -h ) ]]; then
usage
exit 0
fi
if [[ $# -gt 1 ]]; then
usage >&2
exit 1
fi
cmvr_build_type="${1:-Debug}"
case "$cmvr_build_type" in
Debug|Release|RelWithDebInfo) ;;
*) usage >&2; exit 1 ;;
esac
cmvr_root=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)
cmvr_build_dir="$cmvr_root/build/$cmvr_build_type"
cmake -S "$cmvr_root" -B "$cmvr_build_dir" -G "Unix Makefiles" \
-DCMAKE_BUILD_TYPE="$cmvr_build_type" \
-DCMAKE_INSTALL_PREFIX="$cmvr_root/output"
cmake --build "$cmvr_build_dir" --parallel "${CMAKE_BUILD_PARALLEL_LEVEL:-4}"
cmake --install "$cmvr_build_dir" --prefix "$cmvr_root/output"
printf 'Built %s and installed to %s\n' "$cmvr_build_type" "$cmvr_root/output"