From e653d7663581d48c4a2d088196ceb6bf38893e1f Mon Sep 17 00:00:00 2001 From: Richard Ward Date: Thu, 18 Dec 2025 19:45:45 +0000 Subject: [PATCH] build scripts --- .gitignore | 1 + CMakeLists.txt | 6 +++ README.md | 10 ++++ scripts/setup_vendor_dependencies.py | 72 ++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+) create mode 100644 scripts/setup_vendor_dependencies.py diff --git a/.gitignore b/.gitignore index a75d751..98586b8 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,4 @@ .venv/ venv/ env/ +vendor/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b21d16..148d750 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,12 @@ cmake_minimum_required(VERSION 3.24) project(SDL3App LANGUAGES CXX) option(BUILD_SDL3_APP "Build the SDL3 Vulkan demo" ON) +set(VENDOR_INSTALL_DIR "${CMAKE_SOURCE_DIR}/vendor/install") +if(EXISTS "${VENDOR_INSTALL_DIR}") + list(APPEND CMAKE_PREFIX_PATH "${VENDOR_INSTALL_DIR}") + message(STATUS "Using vendored dependencies from ${VENDOR_INSTALL_DIR}") +endif() + set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) diff --git a/README.md b/README.md index edc4b3d..13b074d 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,16 @@ A minimal SDL3 + Vulkan spinning cube demo. cmake --build build ``` +### Vendor SDL3/Vulkan from source + +If you cannot install the SDL3/Vulkan headers via the distro packages, run the helper to download and build them into `vendor/install`: + +``` +python3 scripts/setup_vendor_dependencies.py +cmake -S . -B build -DBUILD_SDL3_APP=ON -DCMAKE_BUILD_TYPE=Release +cmake --build build +``` + Shaders are copied into `build/shaders` during configuration, so the demo can load the precompiled `cube.{vert,frag}.spv`. ## Run diff --git a/scripts/setup_vendor_dependencies.py b/scripts/setup_vendor_dependencies.py new file mode 100644 index 0000000..f2f761e --- /dev/null +++ b/scripts/setup_vendor_dependencies.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python3 +import subprocess +import sys +from pathlib import Path + +ROOT = Path(__file__).resolve().parent.parent +VENDOR_DIR = ROOT / "vendor" +INSTALL_DIR = VENDOR_DIR / "install" + + +def run(command, cwd=None): + print(f"[vendor-deps] running: {' '.join(command)} (cwd={cwd or ROOT})") + subprocess.run(command, cwd=cwd or ROOT, check=True) + + +def fetch_repo(name, url, ref): + target = VENDOR_DIR / name + if (target / ".git").exists(): + print(f"[vendor-deps] updating {name}") + run(["git", "-C", str(target), "fetch", "--tags", "origin"]) + run(["git", "-C", str(target), "checkout", ref]) + run(["git", "-C", str(target), "reset", "--hard", f"origin/{ref}"]) + else: + print(f"[vendor-deps] cloning {name}") + run(["git", "clone", "--depth", "1", "--branch", ref, url, str(target)]) + + +def build_and_install(source_dir, build_dir, cmake_options=None): + cmake_options = cmake_options or [] + build_dir.mkdir(parents=True, exist_ok=True) + run( + [ + "cmake", + "-S", + str(source_dir), + "-B", + str(build_dir), + "-DCMAKE_BUILD_TYPE=Release", + f"-DCMAKE_INSTALL_PREFIX={INSTALL_DIR}", + *cmake_options, + ] + ) + run(["cmake", "--build", str(build_dir), "--", f"-j{max(1, (subprocess.os.cpu_count() or 1))}"]) + run(["cmake", "--install", str(build_dir)]) + + +def main(): + VENDOR_DIR.mkdir(exist_ok=True) + INSTALL_DIR.mkdir(exist_ok=True) + + fetch_repo("SDL", "https://github.com/libsdl-org/SDL.git", "release-3.0.0") + build_and_install( + VENDOR_DIR / "SDL", + VENDOR_DIR / "build-sdl", + ["-DSDL_SHARED=OFF", "-DSDL_STATIC=ON", "-DSDL_TEST=OFF", "-DBUILD_SHARED_LIBS=OFF"], + ) + + fetch_repo("Vulkan-Loader", "https://github.com/KhronosGroup/Vulkan-Loader.git", "sdk-1.3.275") + build_and_install( + VENDOR_DIR / "Vulkan-Loader", + VENDOR_DIR / "build-vulkan-loader", + ["-DBUILD_WSI=OFF", "-DBUILD_SAMPLES=OFF"], + ) + + print(f"[vendor-deps] vendor dependencies built into {INSTALL_DIR}") + + +if __name__ == "__main__": + try: + main() + except subprocess.CalledProcessError as exc: + sys.exit(exc.returncode)