-
Notifications
You must be signed in to change notification settings - Fork 4
/
generate
executable file
·127 lines (109 loc) · 2.63 KB
/
generate
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
######################
# Helper Functions #
######################
help() {
echo "Generate Cmake build directories for project"
echo ""
echo "Usage:"
echo ""
echo "$(basename $0) [options]"
echo ""
echo "Options:"
echo ""
echo " -t : one of debug, release, all (default=all)"
echo " -b : build projects after launching CMake (default=false)"
echo " -o : base output directory (default=\$PROJECT_DIR/build)"
echo " --cmake-args : argument string to pass to CMake"
echo " (use --cmake-args=\"-LH\" to list available options)"
}
######################
# Global Variables #
######################
TARGET_BUILD=all
GENERATE_DEBUG=true
GENERATE_RELEASE=true
BUILD_PROJECTS=false
CMAKE_EXTRA_ARGS=""
PROJECT_DIR_REL="`dirname \"$0\"`"
PROJECT_DIR=`python3 -c "import os; print(os.path.abspath(\"$PROJECT_DIR_REL\"))"`
BUILD_DIR=$PROJECT_DIR/build
######################
# Argument parsing #
######################
while getopts ":t:o:bh:-:" opt; do
case $opt in
t)
TARGET_BUILD=$OPTARG
;;
b)
BUILD_PROJECTS=true
;;
o)
BUILD_DIR="$OPTARG"
;;
-)
case "${OPTARG}" in
cmake-args=*)
CMAKE_EXTRA_ARGS=${OPTARG#*=}
;;
*)
echo "Invalid option: --$OPTARG" >&2
help
exit 1
;;
esac;;
h)
help
exit 1
;;
\?)
echo "Invalid option: -$OPTARG" >&2
help
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
help
exit 1
;;
esac
done
if [[ "$TARGET_BUILD" == "debug" ]]
then
GENERATE_RELEASE=false
elif [[ "$TARGET_BUILD" == "release" ]]
then
GENERATE_DEBUG=false
elif [[ "$TARGET_BUILD" != "all" ]]
then
help
exit 0
fi
######################
# Script Processing #
######################
mkdir -p $BUILD_DIR
OLD_DIR=$PWD
cd $BUILD_DIR
if $GENERATE_RELEASE
then
echo "Generating Release build directory:"
mkdir -p $BUILD_DIR/release
cd $BUILD_DIR/release
cmake -DCMAKE_BUILD_TYPE=Release $PROJECT_DIR $CMAKE_EXTRA_ARGS
if $BUILD_PROJECTS; then
make
fi
fi
if $GENERATE_DEBUG
then
echo "Generating Debug build directory:"
mkdir -p $BUILD_DIR/debug
cd $BUILD_DIR/debug
cmake -DCMAKE_BUILD_TYPE=Debug $PROJECT_DIR $CMAKE_EXTRA_ARGS
if $BUILD_PROJECTS; then
make
fi
fi
cd $OLD_DIR