aboutsummaryrefslogtreecommitdiff
path: root/build.sh
blob: 58b846b2ea556d9174978c09552bfa1e89904229 (plain) (blame)
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
#!/bin/bash

build="release"
target="solvitaire"
error=false

if [ "$#" == 1 ]; then
    if [ "$1" == "--debug" ]; then
        build="debug"
    elif [ "$1" == "--release" ]; then
        build="release"
    elif [ "$1" == "--unit-tests" ]; then
        target="unit_tests"
    elif [ "$1" == "--solvitaire" ]; then
        target="solvitaire"
    else
        error=true
    fi
fi

if [ "$#" == 2 ]; then
    if [ "$1" == "--debug" ]; then
        build="debug"
    elif [ "$1" == "--release" ]; then
        build="release"
    else
        error=true
    fi

    if [ "$2" == "--unit-tests" ]; then
        target="unit_tests"
    elif [ "$2" == "--solvitaire" ]; then
        target="solvitaire"
    else
        error=true
    fi
fi

if [ "$#" -gt 2 ]; then
    error=true
fi

if [ "$error" = true ]; then
    echo "Usage: ./build.sh [--release|--debug] [--solvitaire|--unit-tests]"
    echo "(default args = --release --solvitaire)"
    exit 1
else
    cmake [-G "CodeBlocks - Unix Makefiles"] \
    "-DCMAKE_BUILD_TYPE=${build^^}" \
    "-Bcmake-build-$build" -H. 
    cmake --build "cmake-build-$build" -- "$target"
    exit 0
fi