|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# --- Configuration --- |
| 5 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 6 | +PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" |
| 7 | +INSTALL_DIR="$PROJECT_ROOT/third_party/install" |
| 8 | +BUILD_ROOT="$PROJECT_ROOT/third_party" |
| 9 | +mkdir -p "$INSTALL_DIR"/{lib,include} |
| 10 | + |
| 11 | +# --- Colors --- |
| 12 | +GREEN='\033[0;32m'; YELLOW='\033[1;33m'; BLUE='\033[0;34m'; RED='\033[0;31m'; NC='\033[0m' |
| 13 | + |
| 14 | +echo -e "${BLUE}=== Installing Native Build Dependencies ===${NC}" |
| 15 | +echo -e "${YELLOW}Install location: $INSTALL_DIR${NC}\n" |
| 16 | + |
| 17 | +# --- System Prep --- |
| 18 | +# FreeImage Stub |
| 19 | +mkdir -p "$BUILD_ROOT/free_image/FreeImage" |
| 20 | +ln -sf /usr/include/FreeImage.h "$BUILD_ROOT/free_image/FreeImage/FreeImage.h" |
| 21 | +echo "// Empty stub" > "$BUILD_ROOT/free_image/FreeImage/Utilities.h" |
| 22 | + |
| 23 | +# Distro Detection & System Package Install |
| 24 | +if [ -f /etc/os-release ]; then . /etc/os-release; else echo -e "${RED}No /etc/os-release${NC}"; exit 1; fi |
| 25 | +echo -e "${BLUE}Installing system packages for $ID...${NC}" |
| 26 | + |
| 27 | +if [[ "$ID" =~ ^(fedora|nobara|rhel|centos)$ ]]; then |
| 28 | + sudo dnf install -y --skip-unavailable gcc-c++ cmake ninja-build python3 wget git \ |
| 29 | + vulkan-loader-devel freetype-devel pugixml-devel freeimage-devel opencv-devel \ |
| 30 | + mesa-libGL-devel mesa-libGLU-devel libX11-devel libXcursor-devel libXext-devel \ |
| 31 | + libXi-devel libXinerama-devel libXrandr-devel libXss-devel libXtst-devel \ |
| 32 | + libXxf86vm-devel wayland-devel wayland-protocols-devel libxkbcommon-devel \ |
| 33 | + pulseaudio-libs-devel openssl-devel zlib-devel lua-devel |
| 34 | +elif [[ "$ID" == "arch" ]]; then |
| 35 | + sudo pacman -S --noconfirm gcc cmake ninja python wget git vulkan-headers freetype2 \ |
| 36 | + pugixml freeimage mesa libx11 libxcursor libxext libxi libxinerama libxrandr \ |
| 37 | + libxss libxtst libxxf86vm wayland libxkbcommon pulseaudio openssl opencv zstd lua |
| 38 | +elif [[ "$ID" =~ ^(ubuntu|debian)$ ]]; then |
| 39 | + sudo apt install -y g++ cmake ninja-build python3 wget git libvulkan-dev libfreetype-dev \ |
| 40 | + libpugixml-dev libfreeimage-dev libgl1-mesa-dev libglu1-mesa-dev libx11-dev \ |
| 41 | + libxcursor-dev libxext-dev libxi-dev libxinerama-dev libxrandr-dev libxss-dev \ |
| 42 | + libxtst-dev libxxf86vm-dev libwayland-dev libwayland-protocols-dev libxkbcommon-dev \ |
| 43 | + libpulse-dev libssl-dev zlib1g-dev libopencv-dev liblua5.4-dev |
| 44 | +fi |
| 45 | + |
| 46 | +# --- Helper Functions --- |
| 47 | + |
| 48 | +# $1=Name, $2=CheckFile, $3=FunctionToRun |
| 49 | +task() { |
| 50 | + if [ -e "$INSTALL_DIR/$2" ]; then |
| 51 | + echo -e "${GREEN}✓ $1 already installed${NC}" |
| 52 | + else |
| 53 | + echo -e "${BLUE}Building $1...${NC}" |
| 54 | + cd "$BUILD_ROOT" |
| 55 | + $3 |
| 56 | + echo -e "${GREEN} ✓ Done${NC}" |
| 57 | + fi |
| 58 | +} |
| 59 | + |
| 60 | +# $1=DirName, $2=RepoURL, $3=Branch/Commit(Optional) |
| 61 | +git_setup() { |
| 62 | + if [ ! -d "$BUILD_ROOT/${1}_build/$1" ]; then |
| 63 | + mkdir -p "$BUILD_ROOT/${1}_build" && cd "$BUILD_ROOT/${1}_build" |
| 64 | + git clone --depth 1 $2 $1 |
| 65 | + [ -n "$3" ] && cd $1 && git checkout "$3" || true |
| 66 | + fi |
| 67 | + cd "$BUILD_ROOT/${1}_build/$1" |
| 68 | +} |
| 69 | + |
| 70 | +# $1=DirName, $2=CMakeFlags, $3=NinjaTarget(Optional) |
| 71 | +cmake_make() { |
| 72 | + mkdir -p build && cd build |
| 73 | + cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" -GNinja $2 |
| 74 | + ninja -j$(nproc) $3 |
| 75 | +} |
| 76 | + |
| 77 | +# --- Build Logic --- |
| 78 | + |
| 79 | +build_draco() { |
| 80 | + git_setup "draco" "https://github.com/google/draco.git" |
| 81 | + cmake_make "draco" "-DBUILD_SHARED_LIBS=OFF" |
| 82 | + cp libdraco.a "$INSTALL_DIR/lib/" |
| 83 | +} |
| 84 | + |
| 85 | +build_sdl3() { |
| 86 | + git_setup "sdl3" "https://github.com/libsdl-org/SDL.git" "main" |
| 87 | + cmake_make "sdl3" "-DSDL_TESTS=OFF -DSDL_X11_XSCRNSAVER=OFF -DBUILD_SHARED_LIBS=OFF" |
| 88 | + ninja install |
| 89 | + # Fix lib64 location if exists |
| 90 | + [ -d "$INSTALL_DIR/lib64" ] && mv "$INSTALL_DIR/lib64/"* "$INSTALL_DIR/lib/" && rmdir "$INSTALL_DIR/lib64" |
| 91 | +} |
| 92 | + |
| 93 | +build_spirv() { |
| 94 | + git_setup "spirv_cross" "https://github.com/KhronosGroup/SPIRV-Cross.git" "vulkan-sdk-1.4.335.0" |
| 95 | + cmake_make "SPIRV-Cross" "-DSPIRV_CROSS_SHARED=OFF -DSPIRV_CROSS_STATIC=ON" |
| 96 | + cp libspirv-cross-*.a "$INSTALL_DIR/lib/" |
| 97 | + mkdir -p "$INSTALL_DIR/include/spirv_cross" |
| 98 | + cp ../include/spirv_cross/*.hpp ../*.hpp ../*.h "$INSTALL_DIR/include/spirv_cross/" 2>/dev/null || true |
| 99 | +} |
| 100 | + |
| 101 | +build_meshopt() { |
| 102 | + git_setup "meshoptimizer" "https://github.com/zeux/meshoptimizer.git" |
| 103 | + cmake_make "meshoptimizer" "" |
| 104 | + cp libmeshoptimizer.a "$INSTALL_DIR/lib/" |
| 105 | + mkdir -p "$INSTALL_DIR/include/meshoptimizer" |
| 106 | + cp ../src/meshoptimizer.h "$INSTALL_DIR/include/meshoptimizer/" |
| 107 | +} |
| 108 | + |
| 109 | +build_assimp() { |
| 110 | + # Commit closest to 2025-09-11 (v5.4.3 release) |
| 111 | + git_setup "assimp" "https://github.com/assimp/assimp.git" "v5.4.3" |
| 112 | + |
| 113 | + cmake_make "assimp" "-DASSIMP_BUILD_TESTS=OFF -DASSIMP_BUILD_SAMPLES=OFF -DBUILD_SHARED_LIBS=OFF -DASSIMP_BUILD_ASSIMP_TOOLS=OFF -DASSIMP_WARNINGS_AS_ERRORS=OFF" |
| 114 | + cp lib/libassimp.a "$INSTALL_DIR/lib/" |
| 115 | +} |
| 116 | + |
| 117 | +build_physx() { |
| 118 | + git_setup "physx" "https://github.com/NVIDIA-Omniverse/PhysX.git" "107.0-physx-5.6.0" |
| 119 | + cd physx |
| 120 | + bash generate_projects.sh linux-gcc-cpu-only |
| 121 | + cd compiler/linux-gcc-cpu-only-checked |
| 122 | + cmake --build . --config checked -j$(nproc) --target PhysXExtensions PhysXCommon PhysXPvdSDK PhysXCharacterKinematic PhysXCooking PhysXVehicle2 PhysX || true |
| 123 | + mkdir -p "$INSTALL_DIR/include/physx" |
| 124 | + cp -r ../../include/* "$INSTALL_DIR/include/physx/" |
| 125 | + find ../../bin -name "*.a" -exec cp {} "$INSTALL_DIR/lib/" \; |
| 126 | +} |
| 127 | + |
| 128 | +build_compressonator() { |
| 129 | + git_setup "compressonator" "https://github.com/GPUOpen-Tools/compressonator.git" "V4.2.5185" |
| 130 | + sed -i '1s/^/#include <cstdint>\n/' applications/_plugins/common/cmp_fileio.h applications/_plugins/common/utilfuncs.h |
| 131 | + cmake_make "compressonator" "-DOPTION_ENABLE_ALL_APPS=OFF -DOPTION_BUILD_CMP_SDK=ON -DLIB_BUILD_COMPRESSONATOR_SDK=ON -DLIB_BUILD_FRAMEWORK_SDK=ON -DLIB_BUILD_CORE=ON -DLIB_BUILD_COMMON=ON -DLIB_BUILD_IMAGEIO=OFF -DLIB_BUILD_GPUDECODE=ON -DOPTION_CMP_OPENCL=ON -DOPTION_CMP_OPENGL=OFF -DOPTION_CMP_QT=OFF -DOPTION_CMP_OPENCV=ON -DOPTION_BUILD_EXR=OFF -DOPTION_BUILD_APPS_CMP_CLI=OFF -DOPTION_BUILD_APPS_CMP_GUI=OFF" "CMP_Compressonator CMP_Core CMP_Framework CMP_Common" |
| 132 | + mkdir -p "$INSTALL_DIR/include/compressonator" |
| 133 | + cp ../cmp_compressonatorlib/compressonator.h "$INSTALL_DIR/include/compressonator/" |
| 134 | + find . -name "*.a" -exec cp {} "$INSTALL_DIR/lib/" \; |
| 135 | + cd "$INSTALL_DIR/lib" && ln -sf libCMP_Common.a libCommon.a |
| 136 | +} |
| 137 | + |
| 138 | +build_renderdoc() { |
| 139 | + git_setup "renderdoc" "https://github.com/baldurk/renderdoc.git" "v1.42" |
| 140 | + cmake_make "renderdoc" "-DENABLE_QRENDERDOC=OFF -DENABLE_PYRENDERDOC=OFF" "renderdoc" |
| 141 | + cp lib/librenderdoc.so "$INSTALL_DIR/lib/" |
| 142 | + mkdir -p "$INSTALL_DIR/include/renderdoc/app" |
| 143 | + cp ../renderdoc/api/app/renderdoc_app.h "$INSTALL_DIR/include/renderdoc/app/" |
| 144 | +} |
| 145 | + |
| 146 | +build_dxc() { |
| 147 | + mkdir -p "$BUILD_ROOT/dxc_build/dxc_temp" && cd "$BUILD_ROOT/dxc_build" |
| 148 | + if [ ! -f "linux_dxc.tar.gz" ]; then |
| 149 | + wget -O linux_dxc.tar.gz -q https://github.com/microsoft/DirectXShaderCompiler/releases/download/v1.8.2505.1/linux_dxc_2025_07_14.x86_64.tar.gz |
| 150 | + fi |
| 151 | + tar xzf linux_dxc.tar.gz -C dxc_temp --strip-components=1 |
| 152 | + cp -r dxc_temp/include/* "$INSTALL_DIR/include/" |
| 153 | + cp -r dxc_temp/lib/* "$INSTALL_DIR/lib/" |
| 154 | +} |
| 155 | + |
| 156 | +build_nrd() { |
| 157 | + git_setup "nrd" "https://github.com/NVIDIA-RTX/NRD.git" |
| 158 | + cd "$BUILD_ROOT/nrd_build/nrd" || cd "$BUILD_ROOT/nrd_build/NRD" |
| 159 | + git checkout $(git rev-list -n 1 --before="2026-01-25" master) 2>/dev/null || true |
| 160 | + cmake_make "nrd" "-DNRD_STATIC_LIBRARY=ON" |
| 161 | + mkdir -p "$INSTALL_DIR/include/nrd" |
| 162 | + cp -r ../Include/. ../Integration/. "$INSTALL_DIR/include/nrd/" |
| 163 | + cp ../_Bin/libNRD.a "$INSTALL_DIR/lib/" 2>/dev/null || cp libNRD.a "$INSTALL_DIR/lib/" |
| 164 | + cp _deps/shadermake-build/libShaderMakeBlob.a "$INSTALL_DIR/lib/" 2>/dev/null || true |
| 165 | +} |
| 166 | + |
| 167 | +# --- Execution --- |
| 168 | +task "Draco" "lib/libdraco.a" build_draco |
| 169 | +task "SDL3" "lib/libSDL3.a" build_sdl3 |
| 170 | +task "SPIRV-Cross" "lib/libspirv-cross-core.a" build_spirv |
| 171 | +task "MeshOptimizer" "lib/libmeshoptimizer.a" build_meshopt |
| 172 | +task "Assimp" "lib/libassimp.a" build_assimp |
| 173 | +task "PhysX" "lib/libPhysX_static_64.a" build_physx |
| 174 | +task "Compressonator" "lib/libCMP_Common.a" build_compressonator |
| 175 | +task "RenderDoc" "lib/librenderdoc.so" build_renderdoc |
| 176 | +task "DXC" "lib/libdxcompiler.so" build_dxc |
| 177 | +task "NRD" "lib/libNRD.a" build_nrd |
| 178 | + |
| 179 | +# --- Validation --- |
| 180 | +echo -e "\n${BLUE}Validating...${NC}" |
| 181 | +MISSING=0 |
| 182 | +check() { [ -f "$1" ] && echo -e "${GREEN}✓ Found $(basename $1)${NC}" || { echo -e "${RED}✗ Missing $(basename $1)${NC}"; MISSING=1; }; } |
| 183 | + |
| 184 | +check "$INSTALL_DIR/lib/libdraco.a" |
| 185 | +check "$INSTALL_DIR/lib/libSDL3.a" |
| 186 | +check "$INSTALL_DIR/lib/libspirv-cross-core.a" |
| 187 | +check "$INSTALL_DIR/lib/libmeshoptimizer.a" |
| 188 | +check "$INSTALL_DIR/lib/libassimp.a" |
| 189 | +check "$INSTALL_DIR/lib/libPhysX_static_64.a" |
| 190 | +check "$INSTALL_DIR/lib/libCMP_Common.a" |
| 191 | +check "$INSTALL_DIR/lib/librenderdoc.so" |
| 192 | +check "$INSTALL_DIR/lib/libdxcompiler.so" |
| 193 | +check "$INSTALL_DIR/lib/libNRD.a" |
| 194 | + |
| 195 | +echo "" |
| 196 | +if [ $MISSING -eq 0 ]; then |
| 197 | + echo -e "${GREEN}Success! Environment ready.${NC}" |
| 198 | + echo "Export vars: CMAKE_PREFIX_PATH=$INSTALL_DIR, LIBRARY_PATH=$INSTALL_DIR/lib, CPATH=$INSTALL_DIR/include" |
| 199 | +else |
| 200 | + echo -e "${RED}Some libraries failed to build.${NC}" |
| 201 | +fi |
0 commit comments