-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
59 lines (47 loc) · 1.47 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
#!/bin/bash
project_root=$(pwd)
vcpkg_root="$HOME/vcpkg"
# Check if vcpkg is installed
if [[ ! -d $vcpkg_root ]]; then
echo "Warning: vcpkg is not installed."
echo "Installing vcpkg..."
cd $HOME
# Download vcpkg using Git
git clone https://github.com/microsoft/vcpkg.git
# Run the vcpkg installation
cd vcpkg && ./bootstrap-vcpkg.sh
echo "vcpkg was successfully installed."
cd $project_root
fi
# Check if an argument is provided and validate it
if [[ "$#" -eq 1 ]]; then
# Convert the argument to lowercase
build_type=$(echo "$1" | tr '[:upper:]' '[:lower:]')
# Check if the provided argument is either Release or Debug
if [ $build_type == "release" ]; then
build_type="Release"
elif [ $build_type == "debug" ]; then
build_type="Debug"
else
echo "Error: Invalid build type '$build_type'."
echo "Please specify either 'Release' or 'Debug'."
exit 1
fi
elif [ "$#" -eq 0 ]; then
# If no arguments are provided, set build type to Debug
build_type="Debug"
fi
# Build type message
echo "Build type: $build_type"
# Set build directory
build_dir="build/$build_type/"
# Run cmake with the appropriate build type
cmake -S . -B $build_dir -G "Ninja" -DCMAKE_BUILD_TYPE=$build_type
# Build the targets
cmake --build $build_dir --parallel 4
if [ $build_type == "Release" ]; then
cmake --install $build_dir
fi
# Run tests
test_dir="$project_root/$build_dir/test/"
ctest --test-dir $test_dir --build-config Debug --output-on-failure --parallel 4