templ-cpp/ch

107 lines
2.6 KiB
Text
Raw Normal View History

2024-02-04 12:23:19 +01:00
#!/usr/bin/env zsh
2024-01-28 16:35:30 +01:00
2024-02-04 12:23:19 +01:00
###########################################################
## edit thease variables to match your project structure ##
###########################################################
BUILD_FOLDER="build"
DEFAULT_BUILD_TYPE="debug" # "debug" or "release"
TARGETS=["{{project-name}}"]
2024-01-28 16:35:30 +01:00
2024-02-04 12:23:19 +01:00
##########################################################################################
## this is where the script starts you should not need to edit anything below this line ##
##########################################################################################
#
NC="\033[0m"
2024-02-04 11:04:41 +01:00
COLOR="\033[1;33m"
2024-01-28 16:35:30 +01:00
2024-02-04 12:23:19 +01:00
zparseopts -D -E -F -- d:=debug r:=release t+=target h:=help || exit 1
if (( $#help > 0 )); then
echo "Usage:"
echo " ./ch actions [options]"
echo ""
echo "Actions:"
echo " c - clean project"
echo " g - generate cmake files"
echo " b - build project"
echo " r - run project"
echo " s - strip executable"
echo " d - debug with gdb"
echo ""
echo "actions can be chained so gbr will first run generate then build and then run"
echo ""
echo "Options:"
echo " -d, --debug Builds cmake in debug mode"
echo " -r, --release Builds cmake in release mode"
echo " -t CMAKE_TARGET, --target CMAKE_TARGET"
echo " Builds specific target. Builds all targets specified in order that they are specified in. Clean action is not recomended when using multiple targets."
exit 0
2024-01-28 16:35:30 +01:00
fi
2024-02-04 12:23:19 +01:00
if [[ -z "$1" ]]; then
echo "no actions provided"
exit 1
fi
2024-01-28 16:35:30 +01:00
2024-02-04 12:23:19 +01:00
if (( $#debug > 0 )); then
BUILD_TYPE="debug"
elif (( $#release > 0 )); then
BUILD_TYPE="release"
2024-01-28 16:35:30 +01:00
else
2024-02-04 12:23:19 +01:00
BUILD_TYPE=$DEFAULT_BUILD_TYPE
fi
if (( $#target != 0 )); then
TARGETS=$#target
2024-01-28 16:35:30 +01:00
fi
2024-02-04 12:23:19 +01:00
2024-01-28 16:35:30 +01:00
echo() {
2024-02-04 12:23:19 +01:00
command echo -e "${COLOR}$@${NC}"
2024-01-28 16:35:30 +01:00
}
ARG=$1
2024-02-04 12:23:19 +01:00
BF="$BUILD_FOLDER/$BUILD_TYPE"
for TARGET in $TARGETS; do
for (( i=0; i<${#ARG}; i++ )); do
case ${ARG:$i:1} in
"c")
echo "cleaning project"
rm -rf $BUILD_FOLDER
;;
"g")
echo "generating cmake files"
2024-02-04 13:19:09 +01:00
CMAKE_BUILD_TYPE="$(tr '[:lower:]' '[:upper:]' <<< ${BUILD_TYPE:0:1})${BUILD_TYPE:1}"
2024-02-04 12:23:19 +01:00
cmake -S . -B $BF -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE
;;
"b")
echo "building project"
cmake --build $BF
;;
"r")
echo "running project"
if [[ -f "$BF/$TARGET" ]]; then
./$BF/$TARGET
fi
;;
"s")
echo "stripping executable"
strip -s $BF/$TARGET -o "$BF/$TARGET-stripped"
;;
"d")
echo "debug project"
if [[ $BUILD_TYPE == "release" ]]; then
echo "WARNING: debugging release build"
fi
gdb $BF/$TARGET
;;
*)
echo "unknown action ${1:$i:1}"
exit 1
;;
esac
done
2024-01-28 16:35:30 +01:00
done