build scripts

This commit is contained in:
Richard Ward
2025-12-18 19:45:45 +00:00
parent 1505415337
commit e653d76635
4 changed files with 89 additions and 0 deletions

1
.gitignore vendored
View File

@@ -43,3 +43,4 @@
.venv/
venv/
env/
vendor/

View File

@@ -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)

View File

@@ -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

View File

@@ -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)