-
Notifications
You must be signed in to change notification settings - Fork 4
/
generate
executable file
·135 lines (116 loc) · 2.88 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
127
128
129
130
131
132
133
134
#!/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)"
}
######################
# Global Variables #
######################
TARGET_BUILD=all
GENERATE_DEBUG=true
GENERATE_RELEASE=true
BUILD_PROJECTS=false
PROJECT_DIR_REL="`dirname \"$0\"`"
PROJECT_DIR=`python -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"
;;
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
#####################################
# Extra Optimization Compiler Flags #
#####################################
if [[ "$CROSS_COMPILE" == "" ]]
then
TARGET_ARCH=$(uname --m)
echo "Detected build for native machine (${TARGET_ARCH}), setting machine optimization flags accordingly..."
if [[ $TARGET_ARCH == x86* ]]
then
X86_OPT_FLAGS="-mfpmath=sse -msse4.2"
export CFLAGS="$CFLAGS $X86_OPT_FLAGS"
export CXXFLAGS="$CXXFLAGS $X86_OPT_FLAGS"
elif [[ $TARGET_ARCH == arm* ]]
then
ARM_OPT_FLAGS="-mfpu=neon -mfloat-abi=hard"
export CFLAGS="$CFLAGS $ARM_OPT_FLAGS"
export CXXFLAGS="$CXXFLAGS $ARM_OPT_FLAGS"
fi
else
echo "Detected cross compile build. Not setting any machine optimization flags..."
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
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
if $BUILD_PROJECTS; then
make
fi
fi
cd $OLD_DIR