aluf/windows/build_arm64.bat

192 lines
6.7 KiB
Batchfile

@echo off
setlocal enabledelayedexpansion
:: ==============================================================================
:: PATHS
:: ==============================================================================
set "SCRIPT_DIR=%~dp0"
set "PROJECT_ROOT=%SCRIPT_DIR%.."
set "BUILD_DIR=%PROJECT_ROOT%\build_windows\arm64"
set "QT_ARM64_BIN=C:\Qt\6.8.3\msvc2022_arm64\bin"
set "QT_ARM64_PLUGINS=C:\Qt\6.8.3\msvc2022_arm64\plugins"
set "VCPKG_BIN=%PROJECT_ROOT%\vcpkg_installed\arm64-windows\bin"
:: ==============================================================================
:: ENVIRONMENT SETUP
:: ==============================================================================
if defined VSINSTALLDIR (
set "VS_INSTALL_DIR=!VSINSTALLDIR!"
) else (
if exist "C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Auxiliary\Build\vcvarsall.bat" (
set "VS_INSTALL_DIR=C:\Program Files\Microsoft Visual Studio\2022\Preview"
) else if exist "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" (
set "VS_INSTALL_DIR=C:\Program Files\Microsoft Visual Studio\2022\Enterprise"
) else if exist "C:\Program Files\Microsoft Visual Studio\18\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" (
set "VS_INSTALL_DIR=C:\Program Files\Microsoft Visual Studio\18\Enterprise"
)
)
if "!VS_INSTALL_DIR:~-1!"=="\" set "VS_INSTALL_DIR=!VS_INSTALL_DIR:~0,-1!"
set "VCVARSALL=!VS_INSTALL_DIR!\VC\Auxiliary\Build\vcvarsall.bat"
set "VCPKG_EXE=!VS_INSTALL_DIR!\VC\vcpkg\vcpkg.exe"
set "VCPKG_CMAKE=!VS_INSTALL_DIR!\VC\vcpkg\scripts\buildsystems\vcpkg.cmake"
:: ==============================================================================
:: 0. MANIFEST GENERATION
:: ==============================================================================
echo [INFO] Generating vcpkg.json...
(
echo {
echo "name": "yrcrystals",
echo "version-string": "1.0.0",
echo "builtin-baseline": "b1b19307e2d2ec1eefbdb7ea069de7d4bcd31f01",
echo "dependencies": [
echo "fftw3"
echo ]
echo }
) > "%PROJECT_ROOT%\vcpkg.json"
:: ==============================================================================
:: 1. CHECK VCPKG
:: ==============================================================================
echo [INFO] Verifying dependencies...
cd "%PROJECT_ROOT%"
"!VCPKG_EXE!" install --triplet arm64-windows
if %errorlevel% neq 0 (
echo [ERROR] VCPKG install failed.
pause
exit /b %errorlevel%
)
:: ==============================================================================
:: 2. AUTO-DETECT MAGICK
:: ==============================================================================
set "MAGICK_PATH="
where magick >nul 2>nul
if %errorlevel% equ 0 (
for /f "delims=" %%i in ('where magick') do set "MAGICK_PATH=%%i"
echo [INFO] Found Magick in PATH.
)
if not defined MAGICK_PATH (
for /d %%d in ("C:\Program Files\ImageMagick*") do (
if exist "%%d\magick.exe" set "MAGICK_PATH=%%d\magick.exe"
)
)
if defined MAGICK_PATH (
echo [INFO] Using ImageMagick: !MAGICK_PATH!
set "CMAKE_MAGICK_ARG=-DMAGICK_EXECUTABLE="!MAGICK_PATH!""
) else (
echo [WARNING] ImageMagick not found. Icons will be skipped.
set "CMAKE_MAGICK_ARG="
)
:: ==============================================================================
:: 3. CONFIGURE & BUILD
:: ==============================================================================
echo [INFO] Setting up Environment...
call "!VCVARSALL!" arm64
if not exist "%BUILD_DIR%" mkdir "%BUILD_DIR%"
cd "%BUILD_DIR%"
:: Check if we need to configure (Missing Ninja or Cache)
set "NEED_CONFIG=0"
if not exist "build.ninja" set "NEED_CONFIG=1"
if not exist "CMakeCache.txt" set "NEED_CONFIG=1"
if "!NEED_CONFIG!"=="1" (
echo [INFO] Build configuration missing. Running CMake Configure...
cmake -G "Ninja" ^
-DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_PREFIX_PATH="%QT_ARM64_BIN%\..;%PROJECT_ROOT%\vcpkg_installed\arm64-windows" ^
-DCMAKE_TOOLCHAIN_FILE="!VCPKG_CMAKE!" ^
-DVCPKG_TARGET_TRIPLET=arm64-windows ^
!CMAKE_MAGICK_ARG! ^
"%PROJECT_ROOT%"
if !errorlevel! neq 0 (
echo [ERROR] Configuration Failed.
pause
exit /b !errorlevel!
)
)
echo [INFO] Building...
cmake --build .
if %errorlevel% neq 0 (
echo [ERROR] Build Failed.
pause
exit /b %errorlevel%
)
:: ==============================================================================
:: 4. THE NUKE (Clean Slate)
:: ==============================================================================
echo.
echo [CLEAN] Removing old DLLs and Plugins...
del /f /q *.dll 2>nul
if exist "platforms" rmdir /s /q "platforms"
if exist "styles" rmdir /s /q "styles"
if exist "multimedia" rmdir /s /q "multimedia"
if exist "audio" rmdir /s /q "audio"
if exist "imageformats" rmdir /s /q "imageformats"
if exist "iconengines" rmdir /s /q "iconengines"
if exist "tls" rmdir /s /q "tls"
:: ==============================================================================
:: 5. COPY DEPENDENCIES
:: ==============================================================================
echo.
echo [COPY] Copying DLLs...
:: Core & Helpers
copy /Y "%QT_ARM64_BIN%\Qt6Core.dll" . >nul
copy /Y "%QT_ARM64_BIN%\Qt6Gui.dll" . >nul
copy /Y "%QT_ARM64_BIN%\Qt6Widgets.dll" . >nul
copy /Y "%QT_ARM64_BIN%\Qt6Multimedia.dll" . >nul
copy /Y "%QT_ARM64_BIN%\Qt6OpenGL.dll" . >nul
copy /Y "%QT_ARM64_BIN%\Qt6OpenGLWidgets.dll" . >nul
copy /Y "%QT_ARM64_BIN%\Qt6Network.dll" . >nul
copy /Y "%QT_ARM64_BIN%\Qt6Svg.dll" . >nul
copy /Y "%QT_ARM64_BIN%\Qt6ShaderTools.dll" . >nul
copy /Y "%QT_ARM64_BIN%\Qt6Concurrent.dll" . >nul
copy /Y "%QT_ARM64_BIN%\d3dcompiler_47.dll" . >nul
copy /Y "%QT_ARM64_BIN%\opengl32sw.dll" . >nul
:: FFmpeg
copy /Y "%QT_ARM64_BIN%\avcodec*.dll" . >nul
copy /Y "%QT_ARM64_BIN%\avformat*.dll" . >nul
copy /Y "%QT_ARM64_BIN%\avutil*.dll" . >nul
copy /Y "%QT_ARM64_BIN%\swresample*.dll" . >nul
copy /Y "%QT_ARM64_BIN%\swscale*.dll" . >nul
:: Plugins
if not exist "platforms" mkdir "platforms"
copy /Y "%QT_ARM64_PLUGINS%\platforms\qwindows.dll" "platforms\" >nul
if not exist "styles" mkdir "styles"
copy /Y "%QT_ARM64_PLUGINS%\styles\qwindowsvistastyle.dll" "styles\" >nul
if not exist "imageformats" mkdir "imageformats"
copy /Y "%QT_ARM64_PLUGINS%\imageformats\*.dll" "imageformats\" >nul
if not exist "multimedia" mkdir "multimedia"
copy /Y "%QT_ARM64_PLUGINS%\multimedia\*.dll" "multimedia\" >nul
if not exist "iconengines" mkdir "iconengines"
copy /Y "%QT_ARM64_PLUGINS%\iconengines\*.dll" "iconengines\" >nul
if not exist "tls" mkdir "tls"
copy /Y "%QT_ARM64_PLUGINS%\tls\*.dll" "tls\" >nul
:: FFTW3
if exist "%VCPKG_BIN%\fftw3.dll" (
copy /Y "%VCPKG_BIN%\fftw3.dll" . >nul
)
echo.
echo [SUCCESS] Build and Deploy Complete. Launching...
.\YrCrystals.exe
pause