Skip to content

Instantly share code, notes, and snippets.

@lymieux
Last active April 12, 2022 15:00
Show Gist options
  • Save lymieux/8fc8d5eedde17a896a1e700bc59d0efd to your computer and use it in GitHub Desktop.
Save lymieux/8fc8d5eedde17a896a1e700bc59d0efd to your computer and use it in GitHub Desktop.
Simple bash file to run cmake and make in one convenient script
#!/bin/bash
# Simple build script that builds a cmake project
# no flags :(
# ~
if [ -d "`pwd`/build" ] ; then
echo -e "\e[1;35m[+] \`build\` folder already exists!\e[0m"
conflict=""
while [[ "$conflict" != "r" && "$conflict" != "s" ]]
do
read -p $'\e[1;35m[+] Make [s]ubfolder or [r]eplace?: \e[0m' conflict
done
fi
echo -e "\e[1;35m[+] Running \`cmake\` and \`make\`\e[0m"
if [[ "$conflict" == "s" ]]; then
num=1
while [ -d "`pwd`/build/build-$num" ]
do
num=$((num+1))
done
mkdir -p `pwd`/build/build-$num
cmake -S . -B `pwd`/build/build-$num
make -C `pwd`/build/build-$num
echo -e "\e[1;35m[+] Build to '`pwd`/build/build-$num'\e[0m"
else
rm -rf `pwd`/build
mkdir -p `pwd`/build
cmake -S . -B `pwd`/build
make -C `pwd`/build
echo -e "\e[1;35m[+] Build to '`pwd`/build'\e[0m"
fi
echo -e "\e[1;35m[+] Done!\e[0m"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment