Add project files.

This commit is contained in:
alejo committed 2026-09-12 00:08:03 -03:00
commit 3087fcea8a
71 files changed
+8325

No files matched your search

+71
View File
@@ -0,0 +1,71 @@
@echo off
REM Configure (if needed) and build the project, preferably with Ninja.
REM
REM Usage (from the project root):
REM scripts\build.bat [BUILD_TYPE]
REM
REM BUILD_TYPE Debug^|Release^|RelWithDebInfo^|MinSizeRel (default: Release)
REM
REM Set BUILD_DIR to build somewhere other than out\build (see Configuration.cmake).
setlocal enabledelayedexpansion
cd /d "%~dp0.."
if "%BUILD_DIR%"=="" set "BUILD_DIR=out\build"
set "BUILD_TYPE=%~1"
if "%BUILD_TYPE%"=="" set "BUILD_TYPE=Release"
if "%TOOLCACHE_DIR%"=="" set "TOOLCACHE_DIR=.cache\tools"
where cmake >nul 2>nul
if errorlevel 1 (
echo error: cmake not found on PATH.
exit /b 1
)
REM Prefer a pinned ninja (fetched by scripts\setup.bat -- see
REM cmake\FetchNinja.cmake) over a system one, same "always the pinned
REM copy" preference as Doxygen. Deliberately goto-based, and deliberately
REM `pushd` + a bare wildcard rather than `for /d %%D in ("path\*")` --
REM both tested directly; a path-prefixed wildcard didn't match here,
REM this form does, and it also sidesteps nesting a FOR loop inside an
REM if/else block, which separately corrupts cmd.exe's paren-matching for
REM the enclosing block (see scripts\refactor.bat for that one).
set "NINJA_BIN="
if not exist "%TOOLCACHE_DIR%" goto check_system_ninja
pushd "%TOOLCACHE_DIR%"
for /d %%D in (ninja-*) do if exist "%%D\ninja.exe" if not defined NINJA_BIN set "NINJA_BIN=%%~fD\ninja.exe"
popd
if defined NINJA_BIN goto have_pinned_ninja
:check_system_ninja
where ninja >nul 2>nul
if errorlevel 1 goto no_ninja
echo ==^> Using system ninja
set "GENERATOR_ARGS=-G Ninja"
goto configure
:have_pinned_ninja
echo ==^> Using pinned ninja: %NINJA_BIN%
set "GENERATOR_ARGS=-G Ninja -DCMAKE_MAKE_PROGRAM=%NINJA_BIN%"
goto configure
:no_ninja
echo warning: ninja not found ^(no pinned copy, none on PATH^) -- falling back to
echo CMake's default generator for this platform. Run scripts\setup.bat
echo to fetch a pinned ninja, or install ninja yourself, for a faster
echo and more consistent build. Continuing without it.
set "GENERATOR_ARGS="
:configure
echo ==^> Configuring (%BUILD_TYPE%) into %BUILD_DIR%\
cmake %GENERATOR_ARGS% -S . -B "%BUILD_DIR%" -DCMAKE_BUILD_TYPE=%BUILD_TYPE%
if errorlevel 1 exit /b 1
echo ==^> Building
cmake --build "%BUILD_DIR%"
if errorlevel 1 exit /b 1
echo ==^> Done. Run a module with: scripts\run.bat ^<target-name^>
exit /b 0
+59
View File
@@ -0,0 +1,59 @@
#!/usr/bin/env bash
# Configure (if needed) and build the project, preferably with Ninja.
#
# Usage (from the project root):
# scripts/build.sh [BUILD_TYPE]
#
# BUILD_TYPE Debug|Release|RelWithDebInfo|MinSizeRel (default: Release)
#
# Set BUILD_DIR to build somewhere other than out/build (see Configuration.cmake).
set -euo pipefail
shopt -s nullglob
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR/.."
BUILD_DIR="${BUILD_DIR:-out/build}"
BUILD_TYPE="${1:-Release}"
command -v cmake >/dev/null 2>&1 || { echo "error: cmake not found on PATH." >&2; exit 1; }
# Prefer a pinned ninja (fetched by scripts/setup.sh -- see
# cmake/FetchNinja.cmake) over a system one, same "always the pinned copy"
# preference as Doxygen. TOOLCACHE_DIR default here matches
# Configuration.cmake's; if you've overridden TOOLCACHE_DIR at configure
# time, also set it here as an env var so this still finds it.
TOOLCACHE_DIR="${TOOLCACHE_DIR:-.cache/tools}"
NINJA_BIN=""
for _candidate in "${TOOLCACHE_DIR}"/ninja-*/ninja; do
if [ -x "$_candidate" ]; then
# Must be absolute: CMake invokes CMAKE_MAKE_PROGRAM from several
# different working directories during its own internal
# try-compile steps, where a relative path doesn't resolve.
NINJA_BIN="$(cd "$(dirname "$_candidate")" && pwd)/$(basename "$_candidate")"
break
fi
done
GENERATOR_ARGS=()
if [ -n "$NINJA_BIN" ]; then
echo "==> Using pinned ninja: ${NINJA_BIN}"
GENERATOR_ARGS=(-G Ninja "-DCMAKE_MAKE_PROGRAM=${NINJA_BIN}")
elif command -v ninja >/dev/null 2>&1; then
echo "==> Using system ninja: $(command -v ninja)"
GENERATOR_ARGS=(-G Ninja)
else
echo "warning: ninja not found (no pinned copy, none on PATH) -- falling back to" >&2
echo " CMake's default generator for this platform. Run scripts/setup.sh" >&2
echo " to fetch a pinned ninja, or install ninja yourself, for a faster" >&2
echo " and more consistent build. Continuing without it." >&2
GENERATOR_ARGS=()
fi
echo "==> Configuring (${BUILD_TYPE}) into ${BUILD_DIR}/"
cmake "${GENERATOR_ARGS[@]}" -S . -B "${BUILD_DIR}" -DCMAKE_BUILD_TYPE="${BUILD_TYPE}"
echo "==> Building"
cmake --build "${BUILD_DIR}"
echo "==> Done. Run a module with: scripts/run.sh <target-name>"
+36
View File
@@ -0,0 +1,36 @@
@echo off
REM Build Doxygen documentation for every module (see cmake\Documentation.cmake)
REM and print the path to the landing page. A no-op with a clear message if
REM Doxygen isn't installed or ENABLE_DOXYGEN=OFF.
REM
REM Output goes to out\docs\ (DOCS_OUTPUT_DIR in Configuration.cmake) --
REM note this is a sibling of out\build, not nested inside it. If you've
REM overridden DOCS_OUTPUT_DIR at configure time, also set DOCS_DIR here to
REM match so the printed path is correct (docs still land in the right
REM place either way -- this only affects the message below).
REM
REM Usage (from the project root):
REM scripts\docs.bat REM every module
REM scripts\docs.bat core_lib REM just one module's docs (docs_<target>)
setlocal
cd /d "%~dp0.."
if "%BUILD_DIR%"=="" set "BUILD_DIR=out\build"
if "%DOCS_DIR%"=="" set "DOCS_DIR=out\docs"
if not exist "%BUILD_DIR%" (
echo error: "%BUILD_DIR%" not found. Run scripts\build.bat first.
exit /b 1
)
if "%~1"=="" (
cmake --build "%BUILD_DIR%" --target docs
if exist "%DOCS_DIR%\index.html" (
echo ==^> Open: %DOCS_DIR%\index.html
)
) else (
cmake --build "%BUILD_DIR%" --target docs_%1
echo ==^> Open: %DOCS_DIR%\%1\html\index.html
)
exit /b %ERRORLEVEL%
+37
View File
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
# Build Doxygen documentation for every module (see cmake/Documentation.cmake)
# and print the path to the landing page. A no-op with a clear message if
# Doxygen isn't installed or ENABLE_DOXYGEN=OFF.
#
# Output goes to out/docs/ (DOCS_OUTPUT_DIR in Configuration.cmake) --
# note this is a sibling of out/build, not nested inside it. If you've
# overridden DOCS_OUTPUT_DIR at configure time, also set DOCS_DIR here to
# match so the printed path is correct (docs still land in the right
# place either way -- this only affects the message below).
#
# Usage (from the project root):
# scripts/docs.sh # every module
# scripts/docs.sh core_lib # just one module's docs (docs_<target>)
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR/.."
BUILD_DIR="${BUILD_DIR:-out/build}"
DOCS_DIR="${DOCS_DIR:-out/docs}"
if [ ! -d "$BUILD_DIR" ]; then
echo "error: '${BUILD_DIR}' not found. Run scripts/build.sh first." >&2
exit 1
fi
if [ $# -ge 1 ]; then
TARGET="docs_$1"
cmake --build "${BUILD_DIR}" --target "${TARGET}"
echo "==> Open: ${DOCS_DIR}/$1/html/index.html"
else
cmake --build "${BUILD_DIR}" --target docs
if [ -f "${DOCS_DIR}/index.html" ]; then
echo "==> Open: ${DOCS_DIR}/index.html"
fi
fi
+30
View File
@@ -0,0 +1,30 @@
@echo off
REM Install this project's own build artifacts to
REM out\install\<platform>-<arch>-<compiler>\ (INSTALL_OUTPUT_DIR in
REM Configuration.cmake; see CMakeLists.txt's install() DESTINATION paths).
REM
REM Always passes --component to `cmake --install`. Without it, any
REM vendored/fetched dependency's own install() rules (see
REM cmake\Dependencies.cmake) would also run, typically dumping files under
REM CMAKE_INSTALL_PREFIX -- COMPONENT is what keeps `cmake --install`
REM scoped to just this project's own targets.
REM
REM Usage (from the project root):
REM scripts\install.bat [BUILD_TYPE]
setlocal
cd /d "%~dp0.."
if "%BUILD_DIR%"=="" set "BUILD_DIR=out\build"
set "BUILD_TYPE=%~1"
if "%BUILD_TYPE%"=="" set "BUILD_TYPE=Release"
set "COMPONENT=demo"
if not exist "%BUILD_DIR%" (
echo error: "%BUILD_DIR%" not found. Run scripts\build.bat first.
exit /b 1
)
echo ==^> Installing (component: %COMPONENT%)
cmake --install "%BUILD_DIR%" --config %BUILD_TYPE% --component %COMPONENT%
exit /b %ERRORLEVEL%
+32
View File
@@ -0,0 +1,32 @@
#!/usr/bin/env bash
# Install this project's own build artifacts to
# out/install/<platform>-<arch>-<compiler>/ (INSTALL_OUTPUT_DIR in
# Configuration.cmake; see CMakeLists.txt's install() DESTINATION paths).
#
# Always passes --component to `cmake --install`. Without it, any
# vendored/fetched dependency's own install() rules (see
# cmake/Dependencies.cmake) would also run, typically dumping files under
# CMAKE_INSTALL_PREFIX (e.g. /usr/local) -- COMPONENT is what keeps
# `cmake --install` scoped to just this project's own targets.
#
# Usage (from the project root):
# scripts/install.sh [BUILD_TYPE]
#
# BUILD_TYPE Debug|Release|RelWithDebInfo|MinSizeRel (default: Release) --
# only relevant for a Ninja Multi-Config build.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR/.."
BUILD_DIR="${BUILD_DIR:-out/build}"
BUILD_TYPE="${1:-Release}"
COMPONENT="demo" # must match PROJECT_CODE_NAME in CMakeLists.txt
if [ ! -d "$BUILD_DIR" ]; then
echo "error: '${BUILD_DIR}' not found. Run scripts/build.sh first." >&2
exit 1
fi
echo "==> Installing (component: ${COMPONENT})"
cmake --install "${BUILD_DIR}" --config "${BUILD_TYPE}" --component "${COMPONENT}"
+85
View File
@@ -0,0 +1,85 @@
@echo off
REM Applies clang-format and clang-tidy's --fix across this project's own
REM C/C++ code. The pre-commit hook only CHECKS; this is the "just fix it"
REM counterpart -- review the result with `git diff` afterward, same as any
REM auto-formatter.
REM
REM Defaults to source\ and c-api\, this template's own-code roots -- NEVER
REM walks out\, .cache\, vendor\, or .git\ by default, so it can't
REM accidentally spend minutes reformatting/analyzing a fetched dependency's
REM entire source tree the way scanning the whole repo from "." would.
REM
REM Usage, from the project root: scripts\refactor.bat [optional path]
REM scripts\refactor.bat every file under source\ and c-api\
REM scripts\refactor.bat source\Core just one file or directory -- taken
REM as given, with no exclusion filter,
REM so pick a path that doesn't overlap
REM with out\/.cache\/vendor\/.git\
setlocal enabledelayedexpansion
cd /d "%~dp0.."
where clang-format >nul 2>nul
set "HAVE_FORMAT=0"
if not errorlevel 1 set "HAVE_FORMAT=1"
where clang-tidy >nul 2>nul
set "HAVE_TIDY=0"
if not errorlevel 1 set "HAVE_TIDY=1"
if "%HAVE_FORMAT%"=="1" goto have_a_tool
if "%HAVE_TIDY%"=="1" goto have_a_tool
echo error: neither clang-format nor clang-tidy found on PATH. Run scripts\setup.bat for install guidance.
exit /b 1
:have_a_tool
set "FILELIST=%TEMP%\refactor_files_%RANDOM%.txt"
if exist "%FILELIST%" del "%FILELIST%"
REM Collect the file list. Deliberately NOT using an if/else block here --
REM a for /f or for /r loop nested inside a parenthesized if(...) else(...)
REM block confuses cmd.exe's paren-matching for the enclosing block (this
REM was tested and confirmed, not a guess); goto-based branching sidesteps
REM the problem entirely by never nesting a FOR loop inside another block.
if not "%~1"=="" goto collect_custom
set "SCOPE_DESC=source and c-api"
if exist "source" for /r "source" %%F in (*.c *.h *.cpp *.hpp *.cc *.cxx *.tpp) do echo %%F>>"%FILELIST%"
if exist "c-api" for /r "c-api" %%F in (*.c *.h *.cpp *.hpp *.cc *.cxx *.tpp) do echo %%F>>"%FILELIST%"
goto collected
:collect_custom
set "SCOPE_DESC=%~1"
if not exist "%~1" goto collected
for /r "%~1" %%F in (*.c *.h *.cpp *.hpp *.cc *.cxx *.tpp) do echo %%F>>"%FILELIST%"
:collected
if exist "%FILELIST%" goto have_files
echo No C/C++ files found under: %SCOPE_DESC%
exit /b 0
:have_files
echo ==^> Files in scope: %SCOPE_DESC%
if "%HAVE_FORMAT%"=="1" goto do_format
echo ==^> Skipping clang-format ^(not found on PATH -- see scripts\setup.bat^)
goto after_format
:do_format
echo ==^> Running clang-format -i
for /f "usebackq delims=" %%F in ("%FILELIST%") do clang-format -i "%%F"
:after_format
if "%HAVE_TIDY%"=="1" goto do_tidy
echo ==^> Skipping clang-tidy ^(not found on PATH -- see scripts\setup.bat^)
goto after_tidy
:do_tidy
if exist compile_commands.json goto run_tidy
echo ==^> Skipping clang-tidy ^(no compile_commands.json -- run scripts\build.bat first^)
goto after_tidy
:run_tidy
echo ==^> Running clang-tidy --fix ^(auto-fixable issues only; build once first if this is stale^)
for /f "usebackq delims=" %%F in ("%FILELIST%") do clang-tidy --quiet --fix "%%F"
:after_tidy
del "%FILELIST%" 2>nul
echo ==^> Done. Review the changes: git diff
exit /b 0
+75
View File
@@ -0,0 +1,75 @@
#!/usr/bin/env bash
# Applies clang-format and clang-tidy's --fix across this project's own
# C/C++ code. The pre-commit hook only CHECKS; this is the "just fix it"
# counterpart -- review the result with `git diff` afterward, same as any
# auto-formatter.
#
# Defaults to source/ and c-api/ (this template's own-code roots) --
# NEVER walks out/, .cache/, vendor/, or .git/ by default, so it can't
# accidentally spend minutes reformatting/analyzing a fetched dependency's
# entire source tree (e.g. out/build/_deps/*-src/) the way scanning the
# whole repo from "." would. Passing an explicit scope still excludes
# those four directories defensively, in case the scope you give overlaps
# with them.
#
# Usage (from the project root):
# scripts/refactor.sh # every file under source/ and c-api/
# scripts/refactor.sh source/Core # just one file or directory
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR/.."
if [ $# -ge 1 ]; then
scopes=("$1")
else
scopes=()
[ -d source ] && scopes+=(source)
[ -d c-api ] && scopes+=(c-api)
fi
if [ "${#scopes[@]}" -eq 0 ]; then
echo "No default scope found (expected a source/ and/or c-api/ directory here)." >&2
exit 1
fi
if ! command -v clang-format >/dev/null 2>&1 && ! command -v clang-tidy >/dev/null 2>&1; then
echo "error: neither clang-format nor clang-tidy found on PATH. Run scripts/setup.sh for install guidance." >&2
exit 1
fi
mapfile -t files < <(
find "${scopes[@]}" \
\( -path './vendor' -o -path './out' -o -path './.cache' -o -path './.git' \) -prune -o \
-type f \( -name '*.c' -o -name '*.h' -o -name '*.cpp' -o -name '*.hpp' -o -name '*.cc' -o -name '*.cxx' -o -name '*.tpp' \) -print \
| sed 's|^\./||' | sort
)
if [ "${#files[@]}" -eq 0 ]; then
echo "No C/C++ files found under: ${scopes[*]}"
exit 0
fi
echo "==> ${#files[@]} file(s) in scope: ${scopes[*]}"
if command -v clang-format >/dev/null 2>&1; then
echo "==> Running clang-format -i"
clang-format -i "${files[@]}"
else
echo "==> Skipping clang-format (not found on PATH -- see scripts/setup.sh)"
fi
if command -v clang-tidy >/dev/null 2>&1; then
if [ ! -f compile_commands.json ]; then
echo "==> Skipping clang-tidy (no compile_commands.json -- run scripts/build.sh first)"
else
echo "==> Running clang-tidy --fix (auto-fixable issues only; build once first if this is stale)"
for f in "${files[@]}"; do
clang-tidy --quiet --fix "$f" || true
done
fi
else
echo "==> Skipping clang-tidy (not found on PATH -- see scripts/setup.sh)"
fi
echo "==> Done. Review the changes: git diff"
+80
View File
@@ -0,0 +1,80 @@
@echo off
REM Run an executable module by its CMake target name (as registered in
REM that module's own CMakeLists.txt), resolved via the manifest that
REM _write_module_manifest() generates at configure time -- so this script
REM never needs updating when modules are added, removed, or renamed.
REM
REM Usage (from the project root):
REM scripts\run.bat <target-name> [-- program-args...]
REM
REM Examples:
REM scripts\run.bat hello_exe
REM scripts\run.bat farewell_exe -- Ale
setlocal enabledelayedexpansion
cd /d "%~dp0.."
if "%BUILD_DIR%"=="" set "BUILD_DIR=out\build"
if "%~1"=="" goto usage
set "TARGET_NAME=%~1"
shift
REM Collect any remaining args to pass through to the program (skipping a
REM leading "--" separator if present).
set "PASSTHROUGH="
set "skip_next_dashes=1"
:collect
if "%~1"=="" goto collected
if "!skip_next_dashes!"=="1" if "%~1"=="--" (
set "skip_next_dashes=0"
shift
goto collect
)
set "skip_next_dashes=0"
set "PASSTHROUGH=!PASSTHROUGH! "%~1""
shift
goto collect
:collected
set "MANIFEST="
for %%F in ("%BUILD_DIR%\module_manifest-*.txt") do (
if not defined MANIFEST set "MANIFEST=%%F"
)
if not defined MANIFEST (
echo error: no build manifest found in "%BUILD_DIR%". Run scripts\build.bat first. 1>&2
exit /b 1
)
set "BIN_PATH="
for /f "usebackq tokens=1,* delims==" %%K in ("%MANIFEST%") do (
if "%%K"=="%TARGET_NAME%" set "BIN_PATH=%%L"
)
if not defined BIN_PATH (
echo error: no executable target named "%TARGET_NAME%". 1>&2
echo Available targets: 1>&2
for /f "usebackq tokens=1 delims==" %%T in ("%MANIFEST%") do echo %%T 1>&2
exit /b 1
)
if not exist "%BIN_PATH%" (
echo error: "%BIN_PATH%" was not found. Rebuild with scripts\build.bat. 1>&2
exit /b 1
)
"%BIN_PATH%" !PASSTHROUGH!
exit /b %ERRORLEVEL%
:usage
echo Usage: %~nx0 ^<cmake-target-name^> [-- program-args...] 1>&2
echo. 1>&2
echo Available executable targets: 1>&2
set "found=0"
for %%F in ("%BUILD_DIR%\module_manifest-*.txt") do (
set "found=1"
for /f "usebackq tokens=1 delims==" %%T in ("%%F") do echo %%T 1>&2
)
if "!found!"=="0" echo (none found -- did you run scripts\build.bat?) 1>&2
exit /b 1
+76
View File
@@ -0,0 +1,76 @@
#!/usr/bin/env bash
# Run an executable module by its CMake target name (as registered in
# that module's own CMakeLists.txt), resolved via the manifest that
# _write_module_manifest() generates at configure time -- so this script
# never needs updating when modules are added, removed, or renamed.
#
# Usage (from the project root):
# scripts/run.sh <target-name> [-- program-args...]
#
# Examples:
# scripts/run.sh hello_exe
# scripts/run.sh farewell_exe -- Ale
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR/.."
BUILD_DIR="${BUILD_DIR:-out/build}"
list_targets() {
local manifest
for manifest in "${BUILD_DIR}"/module_manifest-*.txt; do
[ -e "$manifest" ] || continue
cut -d= -f1 "$manifest"
done | sort -u
}
usage() {
echo "Usage: $0 <cmake-target-name> [-- program-args...]" >&2
echo >&2
echo "Available executable targets:" >&2
local targets
targets="$(list_targets)"
if [ -n "$targets" ]; then
echo "$targets" | sed 's/^/ /' >&2
else
echo " (none found -- did you run scripts/build.sh?)" >&2
fi
exit 1
}
[ $# -ge 1 ] || usage
TARGET_NAME="$1"
shift
if [ "${1:-}" = "--" ]; then
shift
fi
MANIFEST=""
for m in "${BUILD_DIR}"/module_manifest-*.txt; do
[ -e "$m" ] || continue
MANIFEST="$m"
break
done
if [ -z "$MANIFEST" ]; then
echo "error: no build manifest found in '${BUILD_DIR}'. Run scripts/build.sh first." >&2
exit 1
fi
BIN_PATH="$(grep "^${TARGET_NAME}=" "$MANIFEST" | head -n1 | cut -d= -f2- || true)"
if [ -z "$BIN_PATH" ]; then
echo "error: no executable target named '${TARGET_NAME}'." >&2
echo "Available targets:" >&2
list_targets | sed 's/^/ /' >&2
exit 1
fi
if [ ! -x "$BIN_PATH" ]; then
echo "error: '${BIN_PATH}' was not found or is not executable. Rebuild with scripts/build.sh." >&2
exit 1
fi
exec "$BIN_PATH" "$@"
+83
View File
@@ -0,0 +1,83 @@
@echo off
REM One-time (or re-run any time) environment setup for this template:
REM
REM 1. Fetches the pinned ninja (cmake\FetchNinja.cmake) -- used by
REM scripts\build.bat if found (see there); a system ninja still
REM works fine too, this just avoids needing one installed at all.
REM 2. Fetches the pinned Doxygen (cmake\FetchDoxygen.cmake) -- NOT
REM required to build the project itself (see cmake\Documentation.cmake),
REM only to run scripts\docs.bat afterward.
REM 3. Checks for clang-format/clang-tidy (used by scripts\refactor.bat and
REM .githooks\pre-commit) and prints install guidance if either is
REM missing -- these aren't auto-installed, since doing so would need
REM assumptions about your package manager/installer this script
REM shouldn't assume it has.
REM 4. Activates the pre-commit hook (.githooks\pre-commit) for this
REM clone, if it's a git repository.
REM
REM Usage (from the project root):
REM scripts\setup.bat
setlocal enabledelayedexpansion
cd /d "%~dp0.."
where cmake >nul 2>nul
if errorlevel 1 (
echo error: cmake not found on PATH.
exit /b 1
)
echo ==^> Fetching pinned ninja (cmake\FetchNinja.cmake)
cmake -P cmake\FetchNinja.cmake
if errorlevel 1 exit /b 1
echo.
echo ==^> Fetching pinned Doxygen (cmake\FetchDoxygen.cmake)
cmake -P cmake\FetchDoxygen.cmake
if errorlevel 1 exit /b 1
echo.
echo ==^> Checking for clang-format / clang-tidy
set "_missing=0"
where clang-format >nul 2>nul
if errorlevel 1 (
echo clang-format: not found
set "_missing=1"
) else (
for /f "delims=" %%V in ('where clang-format') do echo clang-format: %%V
)
where clang-tidy >nul 2>nul
if errorlevel 1 (
echo clang-tidy: not found
set "_missing=1"
) else (
for /f "delims=" %%V in ('where clang-tidy') do echo clang-tidy: %%V
)
if "%_missing%"=="1" (
echo.
echo Install the missing tool(s^) with one of:
echo winget install LLVM.LLVM
echo choco install llvm
echo or the installer from https://releases.llvm.org/
echo Not required to build this project -- only for scripts\refactor.bat
echo and the pre-commit hook.
)
echo.
git rev-parse --is-inside-work-tree >nul 2>nul
if errorlevel 1 (
echo ==^> Skipping pre-commit hook activation ^(not a git repository yet^)
echo Once you've run "git init", re-run this script or:
echo git config core.hooksPath .githooks
) else (
echo ==^> Activating pre-commit hook
git config core.hooksPath .githooks
echo core.hooksPath = .githooks
)
echo.
echo ==^> Setup complete. scripts\build.bat and scripts\docs.bat are ready to use.
exit /b 0
+79
View File
@@ -0,0 +1,79 @@
#!/usr/bin/env bash
# One-time (or re-run any time) environment setup for this template:
#
# 1. Fetches the pinned ninja (cmake/FetchNinja.cmake) -- used by
# scripts/build.sh / build.bat if found (see there); a system ninja
# still works fine too, this just avoids needing one installed at all.
# 2. Fetches the pinned Doxygen (cmake/FetchDoxygen.cmake) -- NOT
# required to build the project itself (see cmake/Documentation.cmake),
# only to run scripts/docs.sh / docs.bat afterward.
# 3. Checks for clang-format/clang-tidy (used by scripts/refactor.sh and
# .githooks/pre-commit) and prints install guidance if either is
# missing -- these aren't auto-installed, since doing so would need
# assumptions about your package manager and elevated privileges
# this script shouldn't assume it has.
# 4. Activates the pre-commit hook (.githooks/pre-commit) for this
# clone, if it's a git repository.
#
# Usage (from the project root):
# scripts/setup.sh
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR/.."
command -v cmake >/dev/null 2>&1 || { echo "error: cmake not found on PATH." >&2; exit 1; }
echo "==> Fetching pinned ninja (cmake/FetchNinja.cmake)"
cmake -P cmake/FetchNinja.cmake
echo
echo "==> Fetching pinned Doxygen (cmake/FetchDoxygen.cmake)"
cmake -P cmake/FetchDoxygen.cmake
echo
echo "==> Checking for clang-format / clang-tidy"
_missing=0
if ! command -v clang-format >/dev/null 2>&1; then
echo " clang-format: not found"
_missing=1
else
echo " clang-format: $(command -v clang-format) ($(clang-format --version))"
fi
if ! command -v clang-tidy >/dev/null 2>&1; then
echo " clang-tidy: not found"
_missing=1
else
echo " clang-tidy: $(command -v clang-tidy) ($(clang-tidy --version | head -n1))"
fi
if [ "$_missing" -eq 1 ]; then
echo
echo " Install the missing tool(s) with:"
case "$(uname -s)" in
Darwin)
echo " brew install clang-format llvm"
;;
*)
echo " sudo apt-get install clang-format clang-tidy # Debian/Ubuntu"
echo " (or your distro's equivalent package)"
;;
esac
echo " Not required to build this project -- only for scripts/refactor.sh"
echo " and the pre-commit hook."
fi
echo
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo "==> Activating pre-commit hook"
chmod +x .githooks/pre-commit
git config core.hooksPath .githooks
echo " core.hooksPath = .githooks"
else
echo "==> Skipping pre-commit hook activation (not a git repository yet)"
echo " Once you've run 'git init', re-run this script or:"
echo " chmod +x .githooks/pre-commit && git config core.hooksPath .githooks"
fi
echo
echo "==> Setup complete. scripts/build.sh and scripts/docs.sh are ready to use."