@echo off setlocal enabledelayedexpansion :: ============================================================================== :: PATHS :: ============================================================================== set "SCRIPT_DIR=%~dp0" set "PROJECT_ROOT=%SCRIPT_DIR%.." set "BUILD_DIR=%PROJECT_ROOT%\build_windows\x64" set "QT_X64_BIN=C:\Qt\6.8.3\msvc2022_64\bin" set "QT_X64_PLUGINS=C:\Qt\6.8.3\msvc2022_64\plugins" set "VCPKG_BIN=%PROJECT_ROOT%\vcpkg_installed\x64-windows\bin" :: ============================================================================== :: ENVIRONMENT SETUP (VS Discovery) :: ============================================================================== 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. DYNAMIC BASELINE DISCOVERY :: ============================================================================== echo [INFO] Probing for latest vcpkg baseline... :: 1. Create temporary manifest with empty baseline to provoke the "suggestion" error ( echo { echo "name": "yrcrystals", echo "version-string": "1.0.0", echo "dependencies": [ "fftw3" ], echo "builtin-baseline": "" echo } ) > "%PROJECT_ROOT%\vcpkg.json" :: 2. Run dry-run and capture output (stderr included) "!VCPKG_EXE!" install --triplet x64-windows --dry-run > "%PROJECT_ROOT%\vcpkg_probe.log" 2>&1 :: 3. Extract the hash using PowerShell regex :: Matches pattern: "builtin-baseline": "HEX_HASH" set "DETECTED_HASH=" for /f "usebackq tokens=*" %%H in (`powershell -NoProfile -Command "$content = Get-Content '%PROJECT_ROOT%\vcpkg_probe.log' -Raw; if ($content -match 'builtin-baseline.: .([a-f0-9]+).') { $matches[1] }"`) do ( set "DETECTED_HASH=%%H" ) if "!DETECTED_HASH!"=="" ( echo [WARNING] Could not auto-detect baseline. Defaulting to standard hash. set "DETECTED_HASH=b1b19307e2d2ec1eefbdb7ea069de7d4bcd31f01" ) else ( echo [INFO] Detected Baseline: !DETECTED_HASH! ) :: Clean up log del "%PROJECT_ROOT%\vcpkg_probe.log" 2>nul :: 4. Generate Final Manifest with discovered hash echo [INFO] Writing vcpkg.json... ( echo { echo "name": "yrcrystals", echo "version-string": "1.0.0", echo "builtin-baseline": "!DETECTED_HASH!", echo "dependencies": [ echo "fftw3" echo ] echo } ) > "%PROJECT_ROOT%\vcpkg.json" :: ============================================================================== :: 1. INSTALL DEPENDENCIES (Targeting x64-windows) :: ============================================================================== echo [INFO] Verifying dependencies for x64... cd "%PROJECT_ROOT%" "!VCPKG_EXE!" install --triplet x64-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 for x64 Build... :: CRITICAL: arm64_x64 means "Use ARM64 host to build x64 binaries" call "!VCVARSALL!" arm64_x64 if not exist "%BUILD_DIR%" mkdir "%BUILD_DIR%" cd "%BUILD_DIR%" 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_X64_BIN%\..;%PROJECT_ROOT%\vcpkg_installed\x64-windows" ^ -DCMAKE_TOOLCHAIN_FILE="!VCPKG_CMAKE!" ^ -DVCPKG_TARGET_TRIPLET=x64-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 (x64 Source) :: ============================================================================== echo. echo [COPY] Copying DLLs... :: Core & Helpers copy /Y "%QT_X64_BIN%\Qt6Core.dll" . >nul copy /Y "%QT_X64_BIN%\Qt6Gui.dll" . >nul copy /Y "%QT_X64_BIN%\Qt6Widgets.dll" . >nul copy /Y "%QT_X64_BIN%\Qt6Multimedia.dll" . >nul copy /Y "%QT_X64_BIN%\Qt6OpenGL.dll" . >nul copy /Y "%QT_X64_BIN%\Qt6OpenGLWidgets.dll" . >nul copy /Y "%QT_X64_BIN%\Qt6Network.dll" . >nul copy /Y "%QT_X64_BIN%\Qt6Svg.dll" . >nul copy /Y "%QT_X64_BIN%\Qt6ShaderTools.dll" . >nul copy /Y "%QT_X64_BIN%\Qt6Concurrent.dll" . >nul copy /Y "%QT_X64_BIN%\d3dcompiler_47.dll" . >nul copy /Y "%QT_X64_BIN%\opengl32sw.dll" . >nul :: FFmpeg copy /Y "%QT_X64_BIN%\avcodec*.dll" . >nul copy /Y "%QT_X64_BIN%\avformat*.dll" . >nul copy /Y "%QT_X64_BIN%\avutil*.dll" . >nul copy /Y "%QT_X64_BIN%\swresample*.dll" . >nul copy /Y "%QT_X64_BIN%\swscale*.dll" . >nul :: Plugins if not exist "platforms" mkdir "platforms" copy /Y "%QT_X64_PLUGINS%\platforms\qwindows.dll" "platforms\" >nul if not exist "styles" mkdir "styles" copy /Y "%QT_X64_PLUGINS%\styles\qwindowsvistastyle.dll" "styles\" >nul if not exist "imageformats" mkdir "imageformats" copy /Y "%QT_X64_PLUGINS%\imageformats\*.dll" "imageformats\" >nul if not exist "multimedia" mkdir "multimedia" copy /Y "%QT_X64_PLUGINS%\multimedia\*.dll" "multimedia\" >nul if not exist "iconengines" mkdir "iconengines" copy /Y "%QT_X64_PLUGINS%\iconengines\*.dll" "iconengines\" >nul if not exist "tls" mkdir "tls" copy /Y "%QT_X64_PLUGINS%\tls\*.dll" "tls\" >nul :: FFTW3 (x64) if exist "%VCPKG_BIN%\fftw3.dll" ( copy /Y "%VCPKG_BIN%\fftw3.dll" . >nul ) echo. echo [SUCCESS] x64 Build Complete. pause