Repository navigation
Expand file tree
/
Copy pathRunCMake.sh
More file actions
executable file
·208 lines (174 loc) · 6.08 KB
/
Copy pathRunCMake.sh
File metadata and controls
executable file
·208 lines (174 loc) · 6.08 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/bin/bash -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# read arguments
opts=$(getopt \
--longoptions help,target:,setup,force,no-unity,solution-name:,workspace-dir: \
--name "$(basename "$0")" \
--options "" \
-- "$@"
)
eval set --$opts
Target="linux-gcc-debug"
NoUnity=""
SolutionName=""
WorkspaceDir=""
while [[ $# -gt 0 ]]; do
case "$1" in
--help)
echo "Usage: $(basename $0) [--setup] [--target <preset>] [--no-unity] [--solution-name <name>] [--workspace-dir <dir>]"
echo " --setup Run first time setup. This installs dependencies and makes sure the git repository is setup correctly."
echo " --force Auto confirm any prompts during setup"
echo " --target CMake preset to use (e.g., linux-gcc-debug, linux-clang-dev). Default: linux-gcc-debug"
echo " --no-unity Disable unity builds. This might help to improve code completion in various editors"
echo " --solution-name Custom solution name"
echo " --workspace-dir Custom workspace directory (outputs to Workspace/<dir> and Workspace/<dir>-output)"
exit 0
;;
--target)
Target=$2
shift 2
;;
--setup)
Setup=true
shift 1
;;
--force)
Force=true
shift 1
;;
--no-unity)
NoUnity="-DW_ENABLE_FOLDER_UNITY_FILES=OFF"
shift 1
;;
--solution-name)
SolutionName=$2
shift 2
;;
--workspace-dir)
WorkspaceDir=$2
shift 2
;;
*)
break
;;
esac
done
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])"
DebianPattern="Debian GNU/Linux ([0-9][0-9])"
if [[ $Issue =~ $UbuntuPattern ]]; then
Distribution="Ubuntu"
Version=${BASH_REMATCH[1]}
elif [[ $Issue =~ $MintPattern ]]; then
Distribution="Mint"
Version=${BASH_REMATCH[1]}
elif [[ $Issue =~ $DebianPattern ]]; then
Distribution="Debian"
Version=${BASH_REMATCH[1]}
else
ISSUE=$(cat /etc/os-release | grep ^NAME | cut -d'"' -f2)
if [[ $ISSUE = "Arch Linux" ]]; then
Distribution="Arch"
Version="Rolling-Release"
fi
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
}
PACKAGE_MANAGER=apt
INSTALL_COMMAND=install
FORCE_INSTALL=-y
if [ "$Distribution" = "Ubuntu" -a \( "$Version" = "22" -o "$Version" = "24" -o "$Version" = "25" -o "$Version" = "26" \) ] || [ "$Distribution" = "Mint" -a \( "$Version" = "21" -o "$Version" = "22" \) ] || [ "$Distribution" = "Debian" -a "$Version" = "13" ]; then
packages=(cmake build-essential ninja-build libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev uuid-dev mold libfreetype-dev libxkbcommon-dev liblttng-ust-dev lttng-tools)
if [ "$Distribution" = "Ubuntu" -a \( "$Version" = "24" -o "$Version" = "25" -o "$Version" = "26" \) ] || [ "$Distribution" = "Mint" -a "$Version" = "22" ] || [ "$Distribution" = "Debian" -a "$Version" = "13" ]; then
packages+=(libtinfo6)
else
packages+=(libtinfo5)
fi
if [ "$Distribution" = "Ubuntu" -a "$Version" = "26" ]; then
packages+=(libxxf86vm-dev)
fi
elif [[ $Distribution = "Arch" ]]; then
PACKAGE_MANAGER=pacman
INSTALL_COMMAND=-Sy
FORCE_INSTALL=--noconfirm
packages=(ncurses cmake ninja libxrandr libxinerama libxi mold base-devel freetype2 lttng-ust libxkbcommon)
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 " * Ubuntu 24"
>&2 echo " * Ubuntu 26"
>&2 echo " * Linux Mint 21"
>&2 echo " * Linux Mint 22"
>&2 echo " * Arch Linux"
>&2 echo "Yours is: $Issue"
exit 1
fi
if [ "$Setup" = true ]; then
if [[ $PACKAGE_MANAGER = "apt" ]]; then
qtVer=$(apt list qt6-base-dev 2>/dev/null | grep -o "6\.[0-9]*\.[0-9]")
else
qtVer=$(pacman -Ss qt6-base 2>/dev/null | grep -o "6\.[0-9]*\.[0-9]")
fi
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
if [[ $Distribution = "Arch" ]]; then
packages+=(qt6-base)
else
packages+=(qt6-base-dev libqt6svg6-dev qt6-base-private-dev)
fi
fi
# Determine compiler from target for package installation
if [[ "$Target" == *"clang"* ]]; then
packages+=(clang-14 libomp-14-dev libstdc++-12-dev)
elif [[ ! $Distribution = "Arch" ]]; then
# Arch already supplies new versions by default
packages+=(gcc-12 g++-12)
fi
git submodule update --init
echo "Attempting to install the following packages through the package manager:"
echo ${packages[@]}
if [ "$Force" = true ]; then
sudo $PACKAGE_MANAGER $INSTALL_COMMAND $FORCE_INSTALL ${packages[@]}
else
sudo $PACKAGE_MANAGER $INSTALL_COMMAND ${packages[@]}
fi
echo -e "\nSetup complete. Run the script again without --setup to configure CMake."
exit 0
fi
CMAKE_ARGS=("--preset" "${Target}" $NoUnity)
if [ -n "$SolutionName" ]; then
CMAKE_ARGS+=("-DW_SOLUTION_NAME:STRING=${SolutionName}")
fi
# Set custom output directories to avoid conflicts between different workspaces
if [ -n "$WorkspaceDir" ]; then
echo "Using custom workspace directory: Workspace/$WorkspaceDir"
CMAKE_ARGS+=("-B" "$SCRIPT_DIR/Workspace/$WorkspaceDir")
CMAKE_ARGS+=("-DW_OUTPUT_DIRECTORY_DLL:PATH=$SCRIPT_DIR/Workspace/$WorkspaceDir-output/Bin")
CMAKE_ARGS+=("-DW_OUTPUT_DIRECTORY_LIB:PATH=$SCRIPT_DIR/Workspace/$WorkspaceDir-output/Lib")
echo "Custom output directories: Workspace/$WorkspaceDir-output/"
fi
echo ""
echo "Running cmake ${CMAKE_ARGS[@]}"
echo ""
cmake "${CMAKE_ARGS[@]}"
# Determine build directory for ninja hint
if [ -n "$WorkspaceDir" ]; then
BUILD_DIR="Workspace/$WorkspaceDir"
else
BUILD_DIR="Workspace/${Target}"
fi
echo -e "\nRun 'ninja -C $BUILD_DIR' to build"