-
Notifications
You must be signed in to change notification settings - Fork 11
/
build.sh
executable file
·77 lines (67 loc) · 1.7 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
#!/bin/sh
# Helpful when copying and pasting functions and debuging.
if printf '%s' "$0" | grep -q '\.sh'; then
IN_SCRIPT=true
fi
# Fails the script if any of the commands error (Other than if and some others)
set -e
cd_safe() {
if (cd "$1"); then
cd "$1"
else
_dir="$1"
shift
die "${@:-Failed cd to $_dir.}"
fi
}
# Usage: build [test]
build() (
build_type=Release
echo "Create folder: build, build type: $build_type"
mkdir -p build > /dev/null 2>&1
cd_safe build
for file in *; do
rm -rf "$file"
done
cmake .. -DCMAKE_BUILD_TYPE="$build_type" $CMAKE_EXTRA_FLAGS "$@"
#cmake .. -DCMAKE_BUILD_TYPE="RelWithDebInfo" $CMAKE_EXTRA_FLAGS "$@"
if [ -f Makefile ]; then
# make -j
make install -j
fi
cd ..
)
check_executable() (
print_exec=false
while true; do
case "$1" in
-p) print_exec=true && shift ;;
*) break ;;
esac
done
[ -n "$1" ] && command_to_check="$1" || return 1
shift
if [ -e "$command_to_check" ]; then
$print_exec && printf '%s\n' "$command_to_check"
return 0
fi
for d in "$@" $(printf '%s ' "$PATH" | tr ':' ' '); do
if [ -e "$d/$command_to_check" ]; then
$print_exec && printf '%s\n' "$d/$command_to_check"
return 0
fi
done
return 127
)
if check_executable icpx; then
CXX=$(check_executable -p icpx)
elif check_executable clang++; then
CXX=$(check_executable -p clang++)
elif check_executable g++; then
CXX=$(check_executable -p g++)
else
die "No suitable cpp compiler found in path" \
"Please either install one or set it via cxx=*"
fi
export CXX
build $@