Skip to content

Instantly share code, notes, and snippets.

@TheBurnDoc
Last active December 26, 2015 02:58
Show Gist options
  • Save TheBurnDoc/7082060 to your computer and use it in GitHub Desktop.
Save TheBurnDoc/7082060 to your computer and use it in GitHub Desktop.
A simple CMake shell script wrapper script. The script performs an out-of-source build and is designed to cope with debug and release build configurations.
#!/bin/bash
usage ()
{
echo "CMake build script wrapper..."
echo " Usage: $0 [-h -t <debug/release> -c]"
echo
echo " -h : Display this message"
echo " -t : Specify build configuration (default: debug)"
echo " -c : Perform clean of configuration specified in the -r parameter"
}
# Default parameters
clean=false
build_type=debug
# Parse command line options
while getopts "ht:c" opt
do
case $opt in
h)
usage
exit 1
;;
t)
build_type=$OPTARG
;;
c)
clean=true
;;
esac
done
pwd=$PWD
name=$(basename $0)
build_type_lower=$(echo $build_type | awk '{print tolower($0)}')
build_type_upper=$(echo $build_type | awk '{print toupper($0)}')
build_dir=$pwd/build/$build_type_lower
if [[ $clean == true ]]; then
echo "$name: Cleaning '$build_dir'..."
rm -rf $build_dir
else
mkdir -p $build_dir
cd $build_dir
echo "$name: Configuring '$build_type_lower' (cmake)..."
cmake $pwd -Wdev -DCMAKE_BUILD_TYPE=$build_type_upper
echo; echo "$name: Building '$build_type_lower' (make)..."
make
fi
cd $pwd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment