-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulti-build.sh
executable file
·176 lines (144 loc) · 4.06 KB
/
multi-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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/usr/bin/env bash
# Reset
RESTORE='\e[0m'
YELLOW='\e[0;33m'
BLUE='\e[0;34m'
GREEN='\e[0;32m'
PURPLE='\e[0;35m'
RED='\e[0;31m'
CYAN='\e[0;36m'
#WHITE="\e[0;37m"
#BLACK="\e[0;30m"
DEFAULT_COMPILERS=(g++ clang++)
DEFAULT_CMAKE=$(command -v cmake)
DEFAULT_BUILDGENERATOR="Unix Makefiles"
DEFAULT_JOBS=$(($(nproc)/2))
DEFAULT_BUILDTYPE=Debug
VERBOSE=0
usage() {
echo -e "
${BLUE}USAGE${RESTORE}: ${BASH_SOURCE##*/} -p path/to/project/source [-v] [-j jobs] [-g generator] [-m path/to/cmake] [-b build_typeA,build_typeB] [-c compilerA,compilerB,... ]
Required Arguments
-p Path to the source that will be built
Optional Arguments:
-v Show the cmake & make output, use as ON/OFF flag [default: OFF]
-j How many jobs to spawn during the build (ignored for ninja builds) [default: ${DEFAULT_JOBS}]
-g The build system to use [default: ${DEFAULT_BUILDGENERATOR}]
-m The version of cmake to use [default: ${DEFAULT_CMAKE}]
-b Comma ',' separated list of build type to use with cmake [default: ${DEFAULT_BUILDTYPE}]
-c Comma ',' separated list of compilers to create builds for [default: ${DEFAULT_COMPILERS[*]}]
"
exit 1
}
RunCmake() {
${CMAKE} \
-G "${BUILDGENERATOR}" \
-DCMAKE_CXX_COMPILER="${1}" \
-DCMAKE_BUILD_TYPE="${2}" \
"${PROJECT}" > "${3}"
}
while getopts ":hvm:j:g:b:p:c:" OPTIONS
do
case "${OPTIONS}" in
h | \? | : )
usage
;;
v )
VERBOSE=1
;;
m )
CMAKE=${OPTARG}
;;
j )
JOBS=${OPTARG}
;;
g )
BUILDGENERATOR=${OPTARG}
;;
b )
IFS=',' read -ra BUILDTYPE <<< "${OPTARG}"
;;
p )
PROJECT=$(readlink -f "${OPTARG}")
[ -d "${PROJECT}" ] || usage
;;
c )
IFS=',' read -ra COMPILERS <<< "${OPTARG}"
;;
esac
done
shift $((OPTIND-1))
if [[ ${#COMPILERS[@]} -eq 0 ]]
then
COMPILERS=( "${DEFAULT_COMPILERS[@]}" )
fi
CMAKE=${CMAKE:-${DEFAULT_CMAKE}}
BUILDGENERATOR=${BUILDGENERATOR:-${DEFAULT_BUILDGENERATOR}}
JOBS=${JOBS:-${DEFAULT_JOBS}}
if [[ ${#BUILDTYPE[@]} -eq 0 ]]
then
BUILDTYPE=( "${DEFAULT_BUILDTYPE}" )
fi
if [[ -z ${PROJECT} ]]
then
usage
fi
echo -e "
Running builds with
Compilers: ${GREEN}${COMPILERS[*]}${RESTORE}
Build types: ${BLUE}${BUILDTYPE[*]}${RESTORE}
Build system: ${YELLOW}${BUILDGENERATOR}${RESTORE}"
declare -A COMPILE_TIMES
for COMPILER in "${COMPILERS[@]}"
do
echo -e "\\nUsing ${PURPLE}${COMPILER}${RESTORE}"
if ! command -v "${COMPILER}" > /dev/null
then
echo -e "${RED}WARNING${RESTORE}: ${COMPILER} not found in your PATH"
continue
fi
EXE=$(command -v "${COMPILER}")
for BUILD in "${BUILDTYPE[@]}"
do
BUILDDIR="${COMPILER##*/}-${BUILD}-build"
if [[ ! -d "${BUILDDIR}" ]]
then
echo -e "Creating build directory: ${CYAN}${BUILDDIR}${RESTORE}"
mkdir "${BUILDDIR}" || continue
else
echo -e "Using existing directory: ${CYAN}${BUILDDIR}${RESTORE}"
fi
pushd "${BUILDDIR}" > /dev/null || continue
outfile=/dev/null
if [[ ${VERBOSE} -eq 1 ]]
then
outfile=/dev/stdout
fi
if ! RunCmake "${EXE}" "${BUILD}" "${outfile}"
then
echo "cmake failed"
continue
fi
if [[ ${BUILDGENERATOR} != "Ninja" ]]
then
ADDITIONALFLAGS=-j${JOBS}
fi
exec 3>${outfile}
# Don't double quote ADDITIONALFLAGS, it can be empty
# shellcheck disable=SC2086
TIME=$(TIMEFORMAT="%R"; { time cmake --build . -- ${ADDITIONALFLAGS} 1>&3 ; } 2>&1 )
exec 3>&-
echo "Run time: ${TIME}"
COMPILE_TIMES["${COMPILER##*/}-${BUILD}"]=${TIME}
popd > /dev/null || continue
done
done
echo ""
echo "Sorted compile times:"
for TIMES in "${!COMPILE_TIMES[@]}"
do
echo "$TIMES | ${COMPILE_TIMES[$TIMES]}"
done |
sort -n -k3 | column -t
echo ""
exit $?