generated from Deadpikle/WPFTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RunCMake.sh
140 lines (114 loc) · 3.75 KB
/
RunCMake.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
#!/bin/bash -e
# read arguments
opts=$(getopt \
--longoptions help,clang,setup,no-cmake,no-unity,build-type: \
--name "$(basename "$0")" \
--options "" \
-- "$@"
)
eval set --$opts
RunCMake=true
BuildType="Dev"
NoUnity=""
while [[ $# -gt 0 ]]; do
case "$1" in
--help)
echo "Usage: $(basename $0) [--setup] [--clang] [--no-cmake] [--build-type Debug|Dev|Shipping] [--no-unity]"
echo " --setup Run first time setup. This installs dependencies and makes sure the git repository is setup correctly."
echo " --clang Use clang instead of gcc"
echo " --no-cmake Do not invoke cmake (usefull when only --setup is needed)"
echo " --build-type Which build type cmake should be invoked with Debug|Dev|Shipping"
echo " --no-unity Disable unity builds. This might help to improve code completion in various editors"
exit 0
;;
--clang)
UseClang=true
shift 1
;;
--setup)
Setup=true
shift 1
;;
--no-cmake)
RunCMake=false
shift 1
;;
--no-unity)
NoUnity="-DNS_ENABLE_FOLDER_UNITY_FILES=OFF"
shift 1
;;
--build-type)
BuildType=$2
shift 2
;;
*)
break
;;
esac
done
if [ "$BuildType" != "Debug" -a "$BuildType" != "Dev" -a "$BuildType" != "Release" ]; then
>&2 echo "The build-type '${BuildType}' is not supported. Only Debug, Dev and Release are supported values."
exit 1
fi
if [ ! -f "/etc/issue" ]; then
>&2 echo "/etc/issue does not exist. Failed distribution detection"
exit 1
fi
Issue=$(cat /etc/issue)
UbuntuPattern="Ubuntu ([0-9][0-9])"
MintPattern="Linux Mint ([0-9][0-9])"
if [[ $Issue =~ $UbuntuPattern ]]; then
Distribution="Ubuntu"
Version=${BASH_REMATCH[1]}
elif [[ $Issue =~ $MintPattern ]]; then
Distribution="Mint"
Version=${BASH_REMATCH[1]}
fi
# This requires a 'sort' that supports '-V'
verlte() {
[ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ]
}
verlt() {
[ "$1" = "$2" ] && return 1 || verlte $1 $2
}
if [ "$Distribution" = "Ubuntu" -a "$Version" = "22" ] || [ "$Distribution" = "Mint" -a "$Version" = "21" ]; then
packages=(cmake build-essential ninja-build libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev uuid-dev mold libfreetype-dev libtinfo5)
if [ "$UseClang" = true ]; then
packages+=(clang-14 libstdc++-12-dev)
c_compiler=clang-14
cxx_compiler=clang++-14
else
packages+=(gcc-12 g++-12)
c_compiler=gcc-12
cxx_compiler=g++-12
fi
else
>&2 echo "Your Distribution or Distribution version is not supported by this script"
>&2 echo "Currently supported are:"
>&2 echo " * Ubuntu 22"
>&2 echo " * Linux Mint 21"
exit 1
fi
if [ "$Setup" = true ]; then
qtVer=$(apt list qt6-base-dev 2>/dev/null | grep -o "6\.[0-9]*\.[0-9]")
echo $qtVer
if verlt $qtVer "6.3.0"; then
>&2 echo -e "\033[0;33mYour distributions package manager does not provide Qt 6.3.0 or newer. Please install Qt manually."
>&2 echo -e "See https://ezengine.net/pages/docs/build/build-linux.html#automatic-setup for details.\033[0m"
else
packages+=(qt6-base-dev libqt6svg6-dev qt6-base-private-dev)
fi
git submodule update --init
echo "Attempting to install the following packages through the package manager:"
echo ${packages[@]}
sudo apt install ${packages[@]}
fi
CompilerShort=gcc
if [ "$UseClang" = true ]; then
CompilerShort=clang
fi
if [ "$RunCMake" = true ]; then
BuildDir="build-${BuildType}-${CompilerShort}"
cmake -B $BuildDir -S . -G Ninja -DCMAKE_CXX_COMPILER=$cxx_compiler -DCMAKE_C_COMPILER=$c_compiler -DNS_EXPERIMENTAL_EDITOR_ON_LINUX=ON -DNS_BUILD_EXPERIMENTAL_VULKAN=ON -DCMAKE_BUILD_TYPE=$BuildType -DCMAKE_EXPORT_COMPILE_COMMANDS=ON $NoUnity && \
echo -e "\nRun 'ninja -C ${BuildDir}' to build"
fi