-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·125 lines (95 loc) · 2.58 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
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
#!/bin/bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2023 - Present Romain Augier
# All rights reserved.
BUILDTYPE="Release"
RUNTESTS=0
REMOVEOLDDIR=0
EXPORTCOMPILECOMMANDS=0
VERSION="0.0.0"
INSTALLDIR="$PWD/install"
# Little function to parse command line arguments
parse_args()
{
[ "$1" == "--debug" ] && BUILDTYPE="Debug"
[ "$1" == "--reldebug" ] && BUILDTYPE="RelWithDebInfo"
[ "$1" == "--tests" ] && RUNTESTS=1
[ "$1" == "--clean" ] && REMOVEOLDDIR=1
[ "$1" == "--export-compile-commands" ] && EXPORTCOMPILECOMMANDS=1
[ "$1" == *"version"* ] && parse_version $1
[ "$1" == *"installdir"* ] && parse_install_dir $1
}
# Little function to parse the version from a command line argument
parse_version()
{
VERSION="$( cut -d ':' -f 2- <<< "$s" )"
log_info "Version specified by user: $VERSION"
}
# Little function to parse the installation dir from a command line argument
parse_install_dir()
{
INSTALLDIR="$( cut -d ':' -f 2- <<< "$s" )"
log_info "Install directory specified by user: $INSTALLDIR"
}
# Little function to log an information message to the console
log_info()
{
echo "[INFO] : $1"
}
# Little function to log a warning message to the console
log_warning()
{
echo "[WARNING] : $1"
}
# Little function to log an error message to the console
log_error()
{
echo "[ERROR] : $1"
}
log_info "Building libromano"
for arg in "$@"
do
parse_args "$arg"
done
log_info "Build type: $BUILDTYPE"
log_info "Build version: $VERSION"
if [[ -d "build" && $REMOVEOLDDIR -eq 1 ]]; then
log_info "Removing old build directory"
rm -rf build
fi
if [[ -d "install" && $REMOVEOLDDIR -eq 1 ]]; then
log_info "Removing old install directory"
rm -rf install
fi
cmake -S . -B build -DRUN_TESTS=$RUNTESTS -DCMAKE_EXPORT_COMPILE_COMMANDS=$EXPORTCOMPILECOMMANDS -DCMAKE_BUILD_TYPE=$BUILDTYPE -DVERSION=$VERSION
if [[ $? -ne 0 ]]; then
log_error "Error during CMake configuration"
exit 1
fi
cd build
cmake --build . -- -j $(nproc)
if [[ $? -ne 0 ]]; then
log_error "Error during CMake build"
cd ..
exit 1
fi
if [[ $RUNTESTS -eq 1 ]]; then
ctest --output-on-failure
if [[ $? -ne 0 ]]; then
log_error "Error during CMake testing"
cd ..
exit 1
fi
fi
cmake --install . --config %BUILDTYPE% --prefix $INSTALLDIR
if [[ $? -ne 0 ]]; then
log_error "Error during CMake installation"
cd ..
exit 1
fi
cd ..
if [[ $EXPORTCOMPILECOMMANDS -eq 1 ]]
then
cp ./build/compile_commands.json ./compile_commands.json
log_info "Copied compile_commands.json to root directory"
fi