Reworking process_completion() function
This commit is contained in:
96
build.bat
96
build.bat
@@ -2,14 +2,23 @@
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
:: ============================================================================
|
||||
:: build.bat - Build script with compiler preference: clang-cl > gcc > clang
|
||||
:: Usage: build [Release|Debug] [clean]
|
||||
:: build.bat
|
||||
:: ============================================================================
|
||||
|
||||
:: Get script directory (project root)
|
||||
set SCRIPT_DIR=%~dp0
|
||||
set SCRIPT_DIR=%SCRIPT_DIR:~0,-1%
|
||||
|
||||
:: ---------------------------------------------------------------------------
|
||||
:: Default values
|
||||
:: ---------------------------------------------------------------------------
|
||||
|
||||
set BUILD_TYPE=Release
|
||||
set CLEAN_BUILD=0
|
||||
|
||||
:: --------------------------------------------------------------------------
|
||||
:: Parse arguments
|
||||
:: --------------------------------------------------------------------------
|
||||
:parse_args
|
||||
if "%~1"=="" goto :main
|
||||
|
||||
@@ -29,27 +38,34 @@ if /i "%~1"=="clean" (
|
||||
goto :parse_args
|
||||
)
|
||||
|
||||
:: Unknown argument fallback (the *)
|
||||
echo Unknown argument: %~1
|
||||
echo Usage: .\%~nx0 [Release^|Debug] [clean]
|
||||
echo Usage: build [Release^|Debug] [clean]
|
||||
exit /b 1
|
||||
|
||||
:main
|
||||
set BUILD_DIR=build\windows\%BUILD_TYPE%
|
||||
set BUILD_DIR=%SCRIPT_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
|
||||
:: --------------------------------------------------------------------------
|
||||
:: Create build directory
|
||||
:: --------------------------------------------------------------------------
|
||||
if not exist "%BUILD_DIR%" mkdir "%BUILD_DIR%"
|
||||
pushd "%BUILD_DIR%"
|
||||
|
||||
:: Find compiler in preferred order
|
||||
:: --------------------------------------------------------------------------
|
||||
:: Compiler selection
|
||||
:: --------------------------------------------------------------------------
|
||||
set CC=
|
||||
|
||||
where clang-cl >nul 2>&1
|
||||
if !ERRORLEVEL! equ 0 (
|
||||
echo Compiler: clang-cl ^(preferred^)
|
||||
@@ -71,12 +87,14 @@ if !ERRORLEVEL! equ 0 (
|
||||
goto :find_generator
|
||||
)
|
||||
|
||||
echo ERROR: No suitable compiler found! (clang-cl, gcc, or clang required)
|
||||
echo ERROR: No suitable compiler found!
|
||||
popd
|
||||
exit /b 1
|
||||
|
||||
:: --------------------------------------------------------------------------
|
||||
:: Generator selection (prefer ninja)
|
||||
:: --------------------------------------------------------------------------
|
||||
:find_generator
|
||||
:: Find Ninja for build system
|
||||
set GEN=
|
||||
where ninja >nul 2>&1
|
||||
if !ERRORLEVEL! equ 0 (
|
||||
@@ -86,35 +104,67 @@ if !ERRORLEVEL! equ 0 (
|
||||
echo Generator: Default
|
||||
)
|
||||
|
||||
:: --------------------------------------------------------------------------
|
||||
:: Configure
|
||||
:: --------------------------------------------------------------------------
|
||||
echo.
|
||||
echo Configuring CMake...
|
||||
set CMD=cmake ../../.. %GEN% %CC% -DCMAKE_BUILD_TYPE=%BUILD_TYPE% -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
|
||||
|
||||
:: --------------------------------------------------------------------------
|
||||
:: compile_commands.json logic
|
||||
:: --------------------------------------------------------------------------
|
||||
set EXPORT_COMPILE_COMMANDS=OFF
|
||||
|
||||
if /i "%BUILD_TYPE%"=="Release" (
|
||||
if exist "%SCRIPT_DIR%\compile_commands.json" (
|
||||
echo compile_commands.json already exists - skipping generation
|
||||
) else (
|
||||
echo compile_commands.json will be generated
|
||||
set EXPORT_COMPILE_COMMANDS=ON
|
||||
)
|
||||
)
|
||||
|
||||
set CMD=cmake "%SCRIPT_DIR%" %GEN% %CC% -DCMAKE_BUILD_TYPE=%BUILD_TYPE% -DCMAKE_EXPORT_COMPILE_COMMANDS=%EXPORT_COMPILE_COMMANDS%
|
||||
|
||||
echo !CMD!
|
||||
!CMD!
|
||||
if !ERRORLEVEL! neq 0 (echo ERROR: Configuration failed & popd & exit /b 1)
|
||||
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)
|
||||
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
|
||||
:: --------------------------------------------------------------------------
|
||||
:: Copy compile_commands.json (only if generated)
|
||||
:: --------------------------------------------------------------------------
|
||||
if /i "%EXPORT_COMPILE_COMMANDS%"=="ON" (
|
||||
if exist "compile_commands.json" (
|
||||
echo.
|
||||
echo clangd: compile_commands.json generated
|
||||
|
||||
copy /Y "compile_commands.json" "%SCRIPT_DIR%\compile_commands.json" >nul 2>&1
|
||||
if !ERRORLEVEL! equ 0 (
|
||||
echo clangd: Copied to project root
|
||||
) else (
|
||||
echo clangd: Copy failed
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
popd
|
||||
|
||||
echo.
|
||||
echo === Build Complete ===
|
||||
echo Executable: %BUILD_DIR%\filehasher.exe
|
||||
Reference in New Issue
Block a user