Repository navigation
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·527 lines (488 loc) · 21.5 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·527 lines (488 loc) · 21.5 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
#!/usr/bin/env bash
#
# UTV Build Script
# Matches CI/CD execution for local development.
# Copyright (C) 2026 Makai Systems. All Rights Reserved.
#
set -e
# Default settings
BUILD_TYPE="Release"
CLEAN_BUILD=0
INSTALL=0
PACKAGE=0
INSTALL_DEPS=0
LOG_FILE=""
BMD_SDK=""
PRORES_SDK=""
CUSTOM_VERSION=""
# Must match the Python that Homebrew's pyside formula is built for (python@3.15 since pyside 6.12.0_1).
# Homebrew's unversioned python3 can move ahead of pyside, so never build against it.
PYTHON_VERSION="3.15"
GCC_VERSION="15"
# Parse arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
--debug) BUILD_TYPE="Debug"; shift ;;
--release) BUILD_TYPE="Release"; shift ;;
--clean) CLEAN_BUILD=1; shift ;;
--install) INSTALL=1; shift ;;
--package) PACKAGE=1; shift ;;
--install-deps) INSTALL_DEPS=1; shift ;;
--bmd-sdk) BMD_SDK="$2"; shift 2 ;;
--prores-sdk) PRORES_SDK="$2"; shift 2 ;;
--version) CUSTOM_VERSION="$2"; shift 2 ;;
--log)
if [[ -n "$2" && "$2" != -* ]]; then
LOG_FILE="$2"
shift 2
else
mkdir -p logs
LOG_FILE="logs/build_$(date +%Y%m%d_%H%M%S).log"
shift 1
fi
;;
-h|--help)
echo "Usage: ./build.sh [OPTIONS]"
echo "Options:"
echo " --debug Build in Debug mode"
echo " --release Build in Release mode (default)"
echo " --clean Remove build directory and virtual environment before building"
echo " --install Install the build to the _install directory"
echo " --package Generate native installers (RPM/DEB/ZIP) via CPack"
echo " --install-deps Install core system build dependencies via dnf/apt/brew"
echo " --log [f] Log output to a file (default: logs/build_TIMESTAMP.log)"
echo " --bmd-sdk Path to the Blackmagic Decklink SDK zip file"
echo " --prores-sdk Path to the Apple ProRes SDK zip file"
echo " --version Custom semantic version (e.g. 2026.1)"
exit 0
;;
*) echo "Unknown parameter: $1"; exit 1 ;;
esac
done
if [ -n "$LOG_FILE" ]; then
mkdir -p "$(dirname "$LOG_FILE")"
echo "Logging build output to: $LOG_FILE"
exec > >(tee -a "$LOG_FILE") 2>&1
fi
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BUILD_DIR="${PROJECT_ROOT}/_build"
INST_DIR="${PROJECT_ROOT}/_install"
VENV_DIR="${PROJECT_ROOT}/.venv-$OSTYPE"
echo "=== UTV Build Script ==="
echo "Build Type: ${BUILD_TYPE}"
if [ "${CLEAN_BUILD}" -eq 1 ]; then
echo "Cleaning build and environment directories..."
rm -rf "${BUILD_DIR}"
rm -rf "${VENV_DIR}"
fi
if [ "${INSTALL_DEPS}" -eq 1 ]; then
echo "--- Installing System Dependencies ---"
SUDO="sudo"
if [ "$(id -u)" -eq 0 ] || ! command -v sudo >/dev/null 2>&1; then
SUDO=""
fi
# Install specific CMake version natively on Linux if not present or too old
if [[ "$OSTYPE" != "darwin"* ]] && [[ "$OSTYPE" != "msys"* ]]; then
# CMAKE_REQ_VER="4.2.3"
CMAKE_REQ_VER="3.31.12"
# Check if cmake exists and its version
CURRENT_CMAKE_VER=$(cmake --version 2>/dev/null | head -n1 | awk '{print $3}')
if [[ "$CURRENT_CMAKE_VER" != "$CMAKE_REQ_VER" ]]; then
echo "--- Installing CMake ${CMAKE_REQ_VER} (Linux x86_64) ---"
curl -L -o /tmp/cmake.tar.gz "https://github.com/Kitware/CMake/releases/download/v${CMAKE_REQ_VER}/cmake-${CMAKE_REQ_VER}-linux-x86_64.tar.gz"
$SUDO tar -zxvf /tmp/cmake.tar.gz -C /usr/local --strip-components=1
rm /tmp/cmake.tar.gz
fi
fi
# macOS setup
if [[ "$OSTYPE" == "darwin"* ]]; then
if command -v brew >/dev/null 2>&1; then
brew install cmake ninja python@${PYTHON_VERSION}
else
echo "WARNING: Homebrew not found. Please install it first."
fi
# Linux with Homebrew setup
elif command -v brew >/dev/null 2>&1 || [ -x "/home/linuxbrew/.linuxbrew/bin/brew" ]; then
if [ -x "/home/linuxbrew/.linuxbrew/bin/brew" ] && ! command -v brew >/dev/null 2>&1; then
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
fi
echo "--- Installing Linux dependencies via Homebrew ---"
if command -v apt-get >/dev/null 2>&1; then
$SUDO apt-get update && DEBIAN_FRONTEND=noninteractive $SUDO apt-get install -y \
build-essential bison curl flex git patchelf mold tcsh \
libgl1-mesa-dev libglu1-mesa-dev libegl1-mesa-dev libosmesa6-dev libudev-dev libaio-dev libreadline-dev \
libx11-dev libxcursor-dev libxext-dev libxi-dev libxinerama-dev \
libxrandr-dev libxrender-dev libxcomposite-dev libxdamage-dev libxtst-dev libxxf86vm-dev \
libxkbcommon-dev libxkbcommon-x11-dev libffi-dev \
libasound2-dev libpulse-dev libvulkan-dev
fi
brew install --formula \
ninja pkg-config ccache glew doctest qt pyside \
ffmpeg openexr imath opencolorio libraw libtiff libpng libspng boost \
openimageio openjpeg webp yaml-cpp spdlog openjph jpeg-turbo \
vulkan-headers vulkan-loader
# RHEL / Rocky Setup
elif command -v dnf >/dev/null 2>&1; then
# CRB (CodeReady Builder; "powertools" on EL8) and EPEL provide ninja-build and other -devel
# packages. CRB needs dnf-plugins-core for config-manager; enable it before installing EPEL.
$SUDO dnf install -y dnf-plugins-core
$SUDO dnf config-manager --set-enabled crb || $SUDO dnf config-manager --set-enabled powertools
$SUDO dnf install -y epel-release
$SUDO dnf makecache
dnf repolist --enabled
$SUDO dnf install -y --nogpgcheck https://mirrors.rpmfusion.org/free/el/rpmfusion-free-release-$(rpm -E %rhel).noarch.rpm || true
$SUDO dnf groupinstall -y "Development Tools"
$SUDO dnf install -y --allowerasing \
alsa-lib-devel \
curl \
doctest-devel \
gh \
git \
glew-devel \
libdav1d-devel \
libicu-devel \
libjpeg-turbo-devel \
libpng-devel \
LibRaw-devel \
libtiff-devel \
libwebp-devel \
libX11-devel \
libXcursor-devel \
libXext-devel \
libXi-devel \
libxkbcommon-devel \
libXrandr-devel \
libXrender-devel \
mesa-libGLU-devel \
ninja-build \
openjpeg2-devel \
openssl-devel \
perl \
pkgconf-pkg-config \
qt6-qt5compat-devel \
qt6-qtbase-devel \
qt6-qtdeclarative-devel \
qt6-qtsvg-devel \
qt6-qtwebchannel-devel \
qt6-qtwebengine-devel \
rpm-build \
spdlog-devel \
tar \
unzip \
yaml-cpp-devel \
zip
# --- Install custom pre-compiled dependencies from utv-dependencies ---
if [ -n "$GITHUB_TOKEN" ] || [ -n "$GH_TOKEN" ] || [ -n "$GH_TOKEN_DEPS_READ" ]; then
export GH_TOKEN="${GH_TOKEN_DEPS_READ:-${GH_TOKEN:-$GITHUB_TOKEN}}"
echo "--- Fetching pre-compiled RPM dependencies from GitHub Releases ---"
mkdir -p /tmp/utv_deps && cd /tmp/utv_deps
gh release download rocky-9 --repo OpenUTV/utv-dependencies -p "*.rpm" || echo "No custom RPMs found."
if ls *.rpm 1> /dev/null 2>&1; then
$SUDO dnf install -y ./*.rpm
fi
cd - > /dev/null
else
echo "WARNING: GITHUB_TOKEN or GH_TOKEN not set! Cannot fetch custom dependencies from private repository."
fi
# Ubuntu Setup
elif command -v apt-get >/dev/null 2>&1; then
$SUDO apt-get update
DEBIAN_FRONTEND=noninteractive $SUDO apt-get install -y \
bison \
build-essential \
ca-certificates \
curl \
mold \
doctest-dev \
flex \
gh \
git \
glew-utils \
libaio-dev \
libasound2-dev \
libdav1d-dev \
libfreetype-dev \
libgl1-mesa-dev \
libglew-dev \
libglew-dev \
libglu1-mesa-dev \
libicu-dev \
libopencv-dev \
libopenjp2-7-dev \
libosmesa6-dev \
libpng-dev \
libraw-dev \
libspdlog-dev \
libssl-dev \
libtiff-dev \
libturbojpeg0-dev \
libwebp-dev \
libx11-dev \
libxcursor-dev \
libxext-dev \
libxi-dev \
libxkbcommon-dev \
libxrandr-dev \
libxrender-dev \
libyaml-cpp-dev \
ninja-build \
pkg-config \
qt6-5compat-dev \
qt6-base-dev \
qt6-base-private-dev \
qt6-declarative-dev \
qt6-multimedia-dev \
qt6-shadertools-dev \
qt6-svg-dev \
qt6-tools-dev \
qt6-webchannel-dev \
qt6-webengine-dev \
rpm \
unzip \
zip
## GCC Install code below - currently not used but retained for potential future use
# $SUDO apt install software-properties-common
# $SUDO add-apt-repository -y ppa:ubuntu-toolchain-r/test
# $SUDO apt-get update && apt-get upgrade -y
# $SUDO apt-get install -y gcc-${GCC_VERSION} g++-${GCC_VERSION}
# $SUDO update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${GCC_VERSION} 100 --slave /usr/bin/g++ g++ /usr/bin/g++-${GCC_VERSION}
# --- Install custom pre-compiled dependencies from utv-dependencies ---
if [ -n "$GITHUB_TOKEN" ] || [ -n "$GH_TOKEN" ] || [ -n "$GH_TOKEN_DEPS_READ" ]; then
export GH_TOKEN="${GH_TOKEN_DEPS_READ:-${GH_TOKEN:-$GITHUB_TOKEN}}"
echo "--- Fetching pre-compiled DEB dependencies from GitHub Releases ---"
mkdir -p /tmp/utv_deps && cd /tmp/utv_deps
gh release download ubuntu-24.04 --repo OpenUTV/utv-dependencies -p "*.deb" || echo "No custom DEBs found."
if ls *.deb 1> /dev/null 2>&1; then
$SUDO apt-get install -y ./*.deb
fi
cd - > /dev/null
else
echo "WARNING: GITHUB_TOKEN or GH_TOKEN not set! Cannot fetch custom dependencies from private repository."
fi
else
echo "WARNING: Unsupported package manager for --install-deps."
fi
fi
# 1. Setup Python Environment
echo "--- Setting up Python Environment ---"
# Packages without a wheel for this Python are compiled from source, and uv reuses those builds when
# staging the app. Without a deployment target they require the build host's macOS instead of the app's
# minimum (CMAKE_OSX_DEPLOYMENT_TARGET in CMakeLists.txt).
if [[ "$OSTYPE" == "darwin"* ]] && [ -z "${MACOSX_DEPLOYMENT_TARGET:-}" ]; then
MACOSX_DEPLOYMENT_TARGET=$(sed -n '/SET(CMAKE_OSX_DEPLOYMENT_TARGET/{n;s/[^0-9.]//gp;}' "${PROJECT_ROOT}/CMakeLists.txt")
export MACOSX_DEPLOYMENT_TARGET
fi
if ! command -v uv >/dev/null 2>&1; then
echo "uv not found. Installing astral uv..."
curl -LsSf https://astral.sh/uv/install.sh | sh
export PATH="$HOME/.cargo/bin:$HOME/.local/bin:$PATH"
fi
if [ ! -d "${VENV_DIR}" ]; then
if [[ "$OSTYPE" == "darwin"* ]] && [ -x "/opt/homebrew/opt/python@${PYTHON_VERSION}/bin/python${PYTHON_VERSION}" ]; then
uv venv "${VENV_DIR}" --python "/opt/homebrew/opt/python@${PYTHON_VERSION}/bin/python${PYTHON_VERSION}" --system-site-packages
elif [ -x "/home/linuxbrew/.linuxbrew/opt/python@${PYTHON_VERSION}/bin/python${PYTHON_VERSION}" ]; then
uv venv "${VENV_DIR}" --python "/home/linuxbrew/.linuxbrew/opt/python@${PYTHON_VERSION}/bin/python${PYTHON_VERSION}" --system-site-packages
elif command -v python3 >/dev/null 2>&1; then
uv venv "${VENV_DIR}" --python "$(command -v python3)" --system-site-packages
else
uv venv "${VENV_DIR}" --python ${PYTHON_VERSION} --system-site-packages
fi
fi
source "${VENV_DIR}/bin/activate"
uv pip install -r "${PROJECT_ROOT}/requirements.txt"
if [ -d ".git" ]; then
git config --global --add safe.directory '*'
fi
# 2. Locate Qt6
echo "--- Locating Qt6 ---"
if [ -z "$QT_HOME" ]; then
if [[ "$OSTYPE" == "linux"* ]]; then
if command -v brew >/dev/null 2>&1 || [ -x "/home/linuxbrew/.linuxbrew/bin/brew" ]; then
if [ -x "/home/linuxbrew/.linuxbrew/bin/brew" ] && ! command -v brew >/dev/null 2>&1; then
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
fi
BREW_PREFIX=$(brew --prefix 2>/dev/null || echo "")
if [ -n "$BREW_PREFIX" ]; then
if [ -d "${BREW_PREFIX}/opt/qtbase/lib/cmake/Qt6" ]; then
QT_HOME="${BREW_PREFIX}/opt/qtbase"
elif [ -d "${BREW_PREFIX}/opt/qt/lib/cmake/Qt6" ]; then
QT_HOME="${BREW_PREFIX}/opt/qt"
elif [ -d "${BREW_PREFIX}/opt/qt@6/lib/cmake/Qt6" ]; then
QT_HOME="${BREW_PREFIX}/opt/qt@6"
fi
fi
fi
if [ -z "$QT_HOME" ]; then
QT_HOME=$(find /usr/lib64/qt6 /usr/lib/qt6 /usr/lib/x86_64-linux-gnu/qt6 ~/Qt*/6.* -maxdepth 4 -type d -path '*/gcc_64' 2>/dev/null | sort -V | tail -n 1)
if [ -z "$QT_HOME" ]; then
if [ -d "/usr/lib/x86_64-linux-gnu/qt6" ]; then
QT_HOME="/usr/lib/x86_64-linux-gnu/qt6"
elif [ -d "/usr/lib64/qt6" ]; then
QT_HOME="/usr/lib64/qt6"
else
QT_HOME="/usr"
fi
fi
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
if [ -d "/opt/homebrew/opt/qtbase/lib/cmake/Qt6" ]; then
QT_HOME="/opt/homebrew/opt/qtbase"
elif [ -d "/opt/homebrew/opt/qt/lib/cmake/Qt6" ]; then
QT_HOME="/opt/homebrew/opt/qt"
else
QT_HOME=$(find /opt/homebrew/Cellar/qtbase/*/lib/cmake/Qt6 /opt/homebrew/Cellar/qt/*/lib/cmake/Qt6 -maxdepth 0 2>/dev/null | sort -V | tail -n 1 | sed 's|/lib/cmake/Qt6||')
fi
if [ -z "$QT_HOME" ]; then
QT_HOME=$(find ~/Qt*/6.* -maxdepth 4 -type d -path '*/macos' 2>/dev/null | sort -V | tail -n 1)
fi
fi
fi
if [ -z "$QT_HOME" ]; then
echo "ERROR: Could not find required Qt 6 installation. Please set QT_HOME."
exit 1
fi
echo "Using QT_HOME=${QT_HOME}"
# 3. macOS Specific Fixes
if [[ "$OSTYPE" == "darwin"* ]]; then
if command -v xcodebuild >/dev/null 2>&1; then
XCODE_MAJOR_VERSION=$(xcodebuild -version | head -n 1 | awk '{print $2}' | cut -d. -f1)
if [[ -n "$XCODE_MAJOR_VERSION" && "$XCODE_MAJOR_VERSION" =~ ^[0-9]+$ && "$XCODE_MAJOR_VERSION" -ge 26 ]]; then
QT_BASE_DIR="$(dirname "$(dirname "$QT_HOME")")"
fi
fi
fi
# 4. Configure CMake
echo "--- Configuring CMake ---"
CMAKE_GENERATOR=${CMAKE_GENERATOR:-Ninja}
CMAKE_ARGS=(
"-B" "${BUILD_DIR}"
"-G" "${CMAKE_GENERATOR}"
"-DCMAKE_BUILD_TYPE=${BUILD_TYPE}"
"-DRV_DEPS_QT_LOCATION=${QT_HOME}"
"-DRV_VFX_PLATFORM=CY2026"
"-DRV_USE_SYSTEM_DEPS=ON"
)
# Linux Homebrew prefix injection
if [[ "$OSTYPE" == "linux"* ]] && (command -v brew >/dev/null 2>&1 || [ -x "/home/linuxbrew/.linuxbrew/bin/brew" ]); then
if [ -x "/home/linuxbrew/.linuxbrew/bin/brew" ] && ! command -v brew >/dev/null 2>&1; then
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
fi
BREW_PREFIX=$(brew --prefix 2>/dev/null || echo "")
if [ -n "$BREW_PREFIX" ]; then
CMAKE_ARGS+=("-DCMAKE_PREFIX_PATH=${BREW_PREFIX};${BREW_PREFIX}/opt/qt;${BREW_PREFIX}/opt/qtbase")
export PKG_CONFIG_PATH="${BREW_PREFIX}/lib/pkgconfig:${BREW_PREFIX}/opt/ffmpeg/lib/pkgconfig:$PKG_CONFIG_PATH"
export LD_LIBRARY_PATH="${BREW_PREFIX}/lib:${LD_LIBRARY_PATH:-}"
fi
fi
# vcpkg fallback toolchain injection for missing Linux system dependencies
if [ -f "${PROJECT_ROOT}/vcpkg/scripts/buildsystems/vcpkg.cmake" ]; then
echo "Injecting vcpkg toolchain for system dependency fallbacks..."
CMAKE_ARGS+=("-DCMAKE_TOOLCHAIN_FILE=${PROJECT_ROOT}/vcpkg/scripts/buildsystems/vcpkg.cmake" "-DVCPKG_BUILD_TYPE=release")
fi
# On Ubuntu without Homebrew, OpenColorIO is installed to /usr/share/cmake, so we manually point it out
if command -v apt-get >/dev/null 2>&1 && [ ! -d "/home/linuxbrew/.linuxbrew" ] && ! command -v brew >/dev/null 2>&1; then
CMAKE_ARGS+=("-DOpenColorIO_DIR=/usr/share/cmake")
fi
if [ -n "$BMD_SDK" ]; then
CMAKE_ARGS+=("-DRV_DEPS_BMD_DECKLINK_SDK_ZIP_PATH=${BMD_SDK}")
fi
if [ -n "$PRORES_SDK" ]; then
CMAKE_ARGS+=("-DRV_DEPS_APPLE_PRORES_SDK_ZIP_PATH=${PRORES_SDK}")
fi
if [ -z "$CUSTOM_VERSION" ]; then
LATEST_GIT_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [[ "$LATEST_GIT_TAG" =~ ^([0-9]+)\.([0-9]+)(\.([0-9]+))? ]]; then
CUSTOM_VERSION="$LATEST_GIT_TAG"
fi
fi
if [ -n "$CUSTOM_VERSION" ]; then
MAJOR=$(echo "$CUSTOM_VERSION" | cut -d'.' -f1)
MINOR=$(echo "$CUSTOM_VERSION" | cut -d'.' -f2)
PATCH=$(echo "$CUSTOM_VERSION" | cut -d'.' -f3)
if [ -z "$PATCH" ]; then
PATCH="0"
fi
CMAKE_ARGS+=("-DRV_MAJOR_VERSION=${MAJOR}" "-DRV_MINOR_VERSION=${MINOR}" "-DRV_REVISION_NUMBER=${PATCH}" "-DRV_VERSION_YEAR=${MAJOR}" "-DRV_VERSION_EXPLICIT=ON")
fi
# Add Windows specifics if running in MSYS/Cygwin
if [[ "$OSTYPE" == "msys"* || "$OSTYPE" == "cygwin"* ]]; then
CMAKE_ARGS+=("-T" "v143,version=14.40" "-A" "x64")
fi
cmake "${CMAKE_ARGS[@]}"
# 5. Build
echo "--- Building UTV ---"
PARALLELISM=${RV_BUILD_PARALLELISM:-$(python3 -c 'import os; print(os.cpu_count())')}
echo "Building dependencies target..."
cmake --build "${BUILD_DIR}" --config "${BUILD_TYPE}" --parallel "${PARALLELISM}" --target dependencies
echo "Building main_executable target..."
cmake --build "${BUILD_DIR}" --config "${BUILD_TYPE}" --parallel "${PARALLELISM}" --target main_executable
# 6. Sanitize Homebrew Links
echo "--- Staging Python Dependencies into App Bundle ---"
ACTUAL_PY_VER=$(python3 -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')" 2>/dev/null || echo "${PYTHON_VERSION}")
PYTHON_STAGING_DIR=""
if [[ "$OSTYPE" == "darwin"* ]] && [ -d "${BUILD_DIR}/stage/app/UTV.app" ]; then
PYTHON_STAGING_DIR="${BUILD_DIR}/stage/app/UTV.app/Contents/lib/python${ACTUAL_PY_VER}/site-packages"
elif [ -d "${BUILD_DIR}/stage/app/lib" ]; then
PYTHON_STAGING_DIR="${BUILD_DIR}/stage/app/lib/python${ACTUAL_PY_VER}/site-packages"
fi
if [ -n "${PYTHON_STAGING_DIR}" ]; then
mkdir -p "${PYTHON_STAGING_DIR}"
if command -v uv >/dev/null 2>&1; then
uv pip install --python python3 --target "${PYTHON_STAGING_DIR}" -r "${PROJECT_ROOT}/requirements.txt"
else
python3 -m pip install --target "${PYTHON_STAGING_DIR}" -r "${PROJECT_ROOT}/requirements.txt"
fi
# Remove unnecessary CLI binaries from bundled site-packages (e.g. PyOpenColorIO/bin)
find "${PYTHON_STAGING_DIR}" -type d -name "bin" -exec rm -rf {} + 2>/dev/null || true
fi
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "--- Sanitizing Homebrew Links ---"
python3 "${PROJECT_ROOT}/src/build/sanitize_homebrew_links.py" "${BUILD_DIR}/stage"
if [ -d "${BUILD_DIR}/stage/app/UTV.app" ]; then
codesign --force --deep --sign - "${BUILD_DIR}/stage/app/UTV.app" 2>/dev/null || true
fi
elif [[ "$OSTYPE" == "linux"* ]]; then
echo "--- Sanitizing Dynamic Library Links ---"
python3 "${PROJECT_ROOT}/src/build/sanitize_homebrew_links.py" "${BUILD_DIR}/stage"
fi
if [ "${INSTALL}" -eq 1 ]; then
echo "--- Installing UTV ---"
cmake --install "${BUILD_DIR}" --prefix "${INST_DIR}" --config "${BUILD_TYPE}"
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "--- Sanitizing Installed Homebrew Links ---"
python3 "${PROJECT_ROOT}/src/build/sanitize_homebrew_links.py" "${INST_DIR}"
if [ -d "${INST_DIR}/UTV.app" ]; then
codesign --force --deep --sign - "${INST_DIR}/UTV.app" 2>/dev/null || true
fi
elif [[ "$OSTYPE" == "linux"* ]]; then
echo "--- Sanitizing Installed Dynamic Library Links ---"
python3 "${PROJECT_ROOT}/src/build/sanitize_homebrew_links.py" "${INST_DIR}"
fi
fi
if [ "${PACKAGE}" -eq 1 ]; then
echo "--- Packaging UTV ---"
cd "${BUILD_DIR}"
if [[ "$OSTYPE" == "linux"* ]]; then
if command -v dpkg >/dev/null 2>&1; then
cpack -G DEB -C "${BUILD_TYPE}"
elif command -v rpmbuild >/dev/null 2>&1; then
cpack -G RPM -C "${BUILD_TYPE}"
else
cpack -G TGZ -C "${BUILD_TYPE}"
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
cpack -G ZIP -C "${BUILD_TYPE}"
else
cpack -G ZIP -C "${BUILD_TYPE}"
fi
cd "${PROJECT_ROOT}"
fi
echo "=== Build Complete ==="
if [ "${INSTALL}" -eq 1 ]; then
echo "Installed to: ${INST_DIR}"
fi
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "Executable is at: ${BUILD_DIR}/stage/app/UTV.app/Contents/MacOS/UTV"
else
echo "Executable is at: ${BUILD_DIR}/stage/app/bin/utv"
fi