@echo off
setlocal

rem Build Nebula Browser (Windows).
rem Usage:
rem   build.bat              - configure + Release build
rem   build.bat Debug        - configure + Debug build
rem   build.bat Release      - configure + Release build
rem   build.bat configure    - configure only
rem   build.bat clean        - remove the build folder

cd /d "%~dp0"

set "CONFIG=Release"
if /I "%~1"=="Debug" set "CONFIG=Debug"
if /I "%~1"=="Release" set "CONFIG=Release"

if /I "%~1"=="clean" (
    echo Removing build\ ...
    if exist build rmdir /s /q build
    echo Done.
    exit /b 0
)

if not exist "thirdparty\cef\cmake\FindCEF.cmake" (
    echo ERROR: CEF not found at thirdparty\cef\
    echo Download a Windows 64-bit CEF standard binary distribution and extract it
    echo so that thirdparty\cef\cmake\FindCEF.cmake exists.
    exit /b 1
)

echo Configuring CMake...
cmake -B build
if errorlevel 1 (
    echo Configure failed.
    exit /b 1
)

if /I "%~1"=="configure" (
    echo Configure complete.
    exit /b 0
)

echo Building %CONFIG%...
cmake --build build --config %CONFIG%
if errorlevel 1 (
    echo Build failed.
    exit /b 1
)

echo.
echo Build succeeded: build\%CONFIG%\NebulaBrowser.exe
exit /b 0
