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.

Signed-off-by: Michael Maurer <[email protected]>
  • Loading branch information
maurermi committed Jan 8, 2024
1 parent 50a64dd commit 5b39449
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,33 @@ 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
# 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
if [ "$1" == "Release" ]; then
CMAKE_BUILD_TYPE="Release"
elif [ "$1" == "Profiling" ]; then
CMAKE_BUILD_TYPE="Profiling"
elif [ "$1" == "Debug" ]; then
CMAKE_BUILD_TYPE="Debug"
fi
fi

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 5b39449

Please sign in to comment.