-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·94 lines (78 loc) · 2.14 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
# - Definitions
YELLOW='\033[1m\033[38;2;255;255;0m'
RED='\033[1m\033[38;2;255;0;0m'
RESET='\033[0m'
# - Log Terminal Messages
WARNING="${YELLOW}[WARNING]${RESET}"
FAILED="${RED}[FAILED]${RESET}"
# - Default Extensions List
EXTENSION_LIST=( "*.cpp" "*.hpp" "*.c" "*.h")
# - User Extensions List
USER_EXTENSION_LIST=()
if [ ! -d "../build" ]; then
mkdir ../build
else
echo -e "$WARNING Build Directory Already Exists. Clearing the Build Directory."
rm -rf ../build/*
fi
# - Copy Prepared CMakeLists.txt File to Root Directory
cp CMakeLists.txt ../
# - Go to Previous Directory
cd ..
# - Parse Input Options Using getopt
OPTS=$(getopt -o e:p: -l extensions:,packages: -n "$0" -- "$@")
eval set -- "$OPTS"
while true; do
case "$1" in
-e|--extensions)
USER_EXTENSION_LIST+=("$2")
shift 2
;;
-p|--packages)
PACKAGES="$2"
shift 2
;;
--)
shift
break
;;
*)
echo -e "$FAILED Invalid Option"
exit 1
esac
done
# Extracti Extensions from the Command Line Arguments
for extended in "$@"; do
if [[ "$extended" == *"."* ]]; then
USER_EXTENSION_LIST+=("$extended")
fi
done
# - Find All Files with Given Extensions
if [ ${#USER_EXTENSION_LIST[@]} -ne 0 ]; then
find_expression=()
for ext in "${USER_EXTENSION_LIST[@]}"; do
find_expression+=("-name" "$ext" "-o")
done
find_expression=("${find_expression[@]:0:$((${#find_expression[@]}-1))}")
else
find_expression=()
for ext in "${EXTENSION_LIST[@]}"; do
find_expression+=("-name" "$ext" "-o")
done
find_expression=("${find_expression[@]:0:$((${#find_expression[@]}-1))}")
fi
source_files=$(find . -type f \( "${find_expression[@]}" \))
# - Check if Source List is Empty
if [ -z "$source_files" ]; then
echo -e "$WARNING No Files with Used Extensions Found in the Project Directory."
exit 1
fi
# - Change directory to the build folder
cd build
# - Replace Spaces with Semicolons in the Source Files List
source_files=$(echo $source_files | tr ' ' ';')
echo -e "$source_files"
# - Run the CMake Command with the Modified File List
cmake -D_SRC="$source_files" -D_USE_PACKAGES="$PACKAGES" ..
make