#!/bin/bash # relative path to the cmake source tree directory (contains "CMakeLists.txt") SRCDIR="." # relative path to the cmake build tree directory BUILDDIR="build" DIR=$(pwd) if [[ ! -f "$DIR"/"$SRCDIR"/CMakeLists.txt ]] then echo "$SRCDIR/CMakeLists.txt not found" >&2 SCRIPTNAME=$(basename "$0" 2>/dev/null || echo "$0") echo "please run '$SCRIPTNAME' from its containing directory" >&2 exit 1 fi # note: NCORES may be too large on systems with hyperthreading NCORES=$(grep -c "^processor" /proc/cpuinfo 2>/dev/null) if [[ ! $NCORES -ge 1 ]] then NCORES=1 fi mkdir -p "$BUILDDIR" cd "$BUILDDIR" cmake "$DIR"/"$SRCDIR"/ && make clean && make -j $NCORES cd "$DIR"