120 lines
2.7 KiB
Batchfile
120 lines
2.7 KiB
Batchfile
@echo off
|
|
setlocal enabledelayedexpansion
|
|
|
|
:: ============================================================================
|
|
:: build.bat - Build script with compiler preference: clang-cl > gcc > clang
|
|
:: Usage: build [Release|Debug] [clean]
|
|
:: ============================================================================
|
|
|
|
set BUILD_TYPE=Release
|
|
set CLEAN_BUILD=0
|
|
|
|
:: Parse arguments
|
|
:parse_args
|
|
if "%~1"=="" goto :main
|
|
|
|
if /i "%~1"=="Release" (
|
|
set BUILD_TYPE=Release
|
|
shift
|
|
goto :parse_args
|
|
)
|
|
if /i "%~1"=="Debug" (
|
|
set BUILD_TYPE=Debug
|
|
shift
|
|
goto :parse_args
|
|
)
|
|
if /i "%~1"=="clean" (
|
|
set CLEAN_BUILD=1
|
|
shift
|
|
goto :parse_args
|
|
)
|
|
|
|
:: Unknown argument fallback (the *)
|
|
echo Unknown argument: %~1
|
|
echo Usage: .\%~nx0 [Release^|Debug] [clean]
|
|
exit /b 1
|
|
|
|
:main
|
|
set BUILD_DIR=build\windows\%BUILD_TYPE%
|
|
echo === Building filehasher (%BUILD_TYPE%) ===
|
|
|
|
:: Clean if requested
|
|
if %CLEAN_BUILD%==1 (
|
|
echo Cleaning...
|
|
if exist "%BUILD_DIR%" rmdir /s /q "%BUILD_DIR%" 2>nul
|
|
)
|
|
|
|
:: Create build dir
|
|
if not exist "%BUILD_DIR%" mkdir "%BUILD_DIR%"
|
|
pushd "%BUILD_DIR%"
|
|
|
|
:: Find compiler in preferred order
|
|
set CC=
|
|
where clang-cl >nul 2>&1
|
|
if !ERRORLEVEL! equ 0 (
|
|
echo Compiler: clang-cl ^(preferred^)
|
|
set "CC=-DCMAKE_C_COMPILER=clang-cl"
|
|
goto :find_generator
|
|
)
|
|
|
|
where gcc >nul 2>&1
|
|
if !ERRORLEVEL! equ 0 (
|
|
echo Compiler: gcc ^(fallback^)
|
|
set "CC=-DCMAKE_C_COMPILER=gcc"
|
|
goto :find_generator
|
|
)
|
|
|
|
where clang >nul 2>&1
|
|
if !ERRORLEVEL! equ 0 (
|
|
echo Compiler: clang ^(last resort^)
|
|
set "CC=-DCMAKE_C_COMPILER=clang"
|
|
goto :find_generator
|
|
)
|
|
|
|
echo ERROR: No suitable compiler found! (clang-cl, gcc, or clang required)
|
|
popd
|
|
exit /b 1
|
|
|
|
:find_generator
|
|
:: Find Ninja for build system
|
|
set GEN=
|
|
where ninja >nul 2>&1
|
|
if !ERRORLEVEL! equ 0 (
|
|
echo Generator: Ninja
|
|
set "GEN=-G Ninja"
|
|
) else (
|
|
echo Generator: Default
|
|
)
|
|
|
|
:: Configure
|
|
echo.
|
|
echo Configuring CMake...
|
|
set CMD=cmake ../../.. %GEN% %CC% -DCMAKE_BUILD_TYPE=%BUILD_TYPE% -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
|
|
echo !CMD!
|
|
!CMD!
|
|
if !ERRORLEVEL! neq 0 (echo ERROR: Configuration failed & popd & exit /b 1)
|
|
|
|
:: Build
|
|
echo.
|
|
echo Building...
|
|
cmake --build . --config %BUILD_TYPE%
|
|
if !ERRORLEVEL! neq 0 (echo ERROR: Build failed & popd & exit /b 1)
|
|
|
|
:: Check if compile_commands.json exists in the current build directory
|
|
if exist "compile_commands.json" (
|
|
echo.
|
|
echo clangd: compile_commands.json generated
|
|
|
|
:: Copy from current build dir up two levels to the project root
|
|
copy /Y "compile_commands.json" "..\..\..\compile_commands.json" >nul 2>&1
|
|
if !ERRORLEVEL! equ 0 (
|
|
echo clangd: Copied to project root
|
|
) else (
|
|
echo clangd: Could not copy to project root
|
|
)
|
|
)
|
|
|
|
popd
|
|
echo.
|
|
echo === Build Complete ===
|
|
echo Executable: %BUILD_DIR%\filehasher.exe |