Skip to content

Commit

Permalink
Add CLI arguments to build.sh, specify build type
Browse files Browse the repository at this point in the history
Adds CLI arguments to build.sh, and prints to stdout
the type of build being performed. Default build is
still Debug. Additonally supports a BUILD_DEBUG
environment variable, and respects previously set
values of CMAKE_BUILD_TYPE.

Add in help function

Signed-off-by: Michael Maurer <maurer.mi@northeastern.edu>
  • Loading branch information
maurermi authored and HalosGhost committed Apr 22, 2024
1 parent f805c64 commit fc96d88
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
#!/bin/bash

set -e

help() {
if [ $# -gt 0 ]; then
printf 'Unexpected Argument (%s)\n' "$1"
fi
printf 'HELP: Usage: %s [Debug|Release|Profiling]\n' "$0"
exit 0
}

# Note:
# CMAKE_BUILD_TYPE="Debug" adds "-O0 -g" flags by default
# CMAKE_BUILD_TYPE="Release" adds "-O3 -DNDEBUG" by default
if [[ "$BUILD_DEBUG" == "1" ]]; then
CMAKE_BUILD_TYPE="Debug"
elif [[ "$BUILD_RELEASE" == "1" ]]; then
CMAKE_BUILD_TYPE="Release"
elif [[ "$BUILD_PROFILING" == "1" ]]; then
CMAKE_BUILD_TYPE="Profiling"
fi

if [ $# -gt 0 ]; then
case "$1" in
Release|--release|-r) CMAKE_BUILD_TYPE="Release";;
Profiling|--profiling|-p) CMAKE_BUILD_TYPE="Profiling";;
Debug|--debug|-d) CMAKE_BUILD_TYPE="Debug";;
--help|-h) help;;
*) help $1;;
esac
fi

echo "Building..."

# see PREFIX in ./scripts/configure.sh
Expand All @@ -23,12 +53,12 @@ elif [[ "$OSTYPE" == "darwin"* ]]; then
CMAKE_FLAGS+=" -DCMAKE_C_COMPILER=${XCODE_CMDLINE_DIR}/usr/bin/clang -DCMAKE_CXX_COMPILER=${XCODE_CMDLINE_DIR}/usr/bin/clang++ -DCMAKE_CXX_FLAGS=-isystem\ /usr/local/include -DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
fi

CMAKE_BUILD_TYPE="Debug"
if [[ "$BUILD_RELEASE" == "1" ]]; then
CMAKE_BUILD_TYPE="Release"
elif [[ "$BUILD_PROFILING" == "1" ]]; then
CMAKE_BUILD_TYPE="Profiling"
if [[ -z $CMAKE_BUILD_TYPE ]]; then
echo "CMAKE_BUILD_TYPE not set, defaulting to debug"
CMAKE_BUILD_TYPE="Debug"
fi

echo "Building $CMAKE_BUILD_TYPE"
eval "cmake -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} ${CMAKE_FLAGS} .."
make -j$CPUS

0 comments on commit fc96d88

Please sign in to comment.