Files
cavity_LIBS/scripts/build.cmd
T
2026-11-06 14:45:09 +08:00

111 lines
3.0 KiB
Batchfile
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
@echo off
chcp 65001 >nul
setlocal
rem ============================================================
rem CavityLIBS 构建脚本(MinGW 32 / 64 位)
rem
rem 用法:
rem scripts\build.cmd [32^|64] [Debug^|Release] [clean]
rem
rem 示例:
rem scripts\build.cmd 32 Debug
rem scripts\build.cmd 64 Release
rem scripts\build.cmd 32 Debug clean
rem
rem 可用环境变量覆盖 Qt 目录: QTDIR32 / QTDIR64 / QTDIR
rem ============================================================
pushd "%~dp0.."
set "ROOT=%CD%"
set "ARCH=%~1"
if "%ARCH%"=="" set "ARCH=64"
set "CFG=%~2"
if "%CFG%"=="" set "CFG=Release"
if not "%ARCH%"=="32" if not "%ARCH%"=="64" (
echo [ERROR] 第一个参数必须是 32 或 64,当前为 "%ARCH%"
goto :fail
)
rem ---------- 查找 Qt ----------
set "QT="
if "%ARCH%"=="32" (
call :tryqt "%QTDIR32%"
call :tryqt "%QTDIR%"
call :tryqt "G:\qt\Qt\5.15.2\mingw81_32"
call :tryqt "E:\perfessional\QT\install\5.15.2\mingw81_32"
call :tryqt "D:\QT\QT5.15.2\5.15.2\mingw81_32"
) else (
call :tryqt "%QTDIR64%"
call :tryqt "%QTDIR%"
call :tryqt "G:\qt\Qt\5.15.2\mingw81_64"
call :tryqt "E:\perfessional\QT\install\5.15.2\mingw81_64"
call :tryqt "D:\QT\QT5.15.2\5.15.2\mingw81_64"
)
if not defined QT (
echo [ERROR] 没有找到 %ARCH% 位 Qt 5.15.2。
echo 请确认已安装 "Desktop Qt 5.15.2 MinGW %ARCH%-bit",
echo 或设置环境变量 QTDIR%ARCH% 指向 Qt 目录(含 bin\qmake.exe)。
goto :fail
)
rem ---------- 推导 Qt 工具目录 ----------
for %%I in ("%QT%") do set "QTV=%%~dpI"
for %%I in ("%QTV:~0,-1%") do set "QTBASE=%%~dpI"
set "MINGW=%QTBASE%Tools\mingw810_%ARCH%\bin"
if not exist "%MINGW%\g++.exe" (
echo [ERROR] 没有找到 %ARCH% 位 MinGW 工具链: %MINGW%
goto :fail
)
rem ---------- 查找 CMake ----------
set "CMAKE="
if exist "%QTBASE%Tools\CMake_64\bin\cmake.exe" set "CMAKE=%QTBASE%Tools\CMake_64\bin\cmake.exe"
if not defined CMAKE if exist "G:\qt\Qt\Tools\CMake_64\bin\cmake.exe" set "CMAKE=G:\qt\Qt\Tools\CMake_64\bin\cmake.exe"
if not defined CMAKE set "CMAKE=cmake"
rem ---------- 准备构建目录 ----------
set "BUILD=%ROOT%\build\mingw%ARCH%-%CFG%"
if /i "%~3"=="clean" (
echo [INFO] 清理 %BUILD%
if exist "%BUILD%" rmdir /s /q "%BUILD%"
)
if not exist "%BUILD%" mkdir "%BUILD%"
set "PATH=%MINGW%;%PATH%"
rem ---------- 配置 ----------
echo [INFO] Qt : %QT%
echo [INFO] MinGW : %MINGW%
echo [INFO] CMake : %CMAKE%
echo [INFO] 构建目录: %BUILD%
echo.
"%CMAKE%" -S "%ROOT%" -B "%BUILD%" -G "MinGW Makefiles" ^
-DCMAKE_BUILD_TYPE=%CFG% ^
-DCMAKE_PREFIX_PATH="%QT%"
if errorlevel 1 goto :fail
rem ---------- 编译 ----------
"%CMAKE%" --build "%BUILD%" -j %NUMBER_OF_PROCESSORS%
if errorlevel 1 goto :fail
echo.
echo [OK] 构建完成: %BUILD%\bin\CavityLIBS.exe
popd
exit /b 0
:tryqt
if defined QT goto :eof
if "%~1"=="" goto :eof
if not exist "%~1\bin\qmake.exe" goto :eof
set "QT=%~1"
goto :eof
:fail
popd
exit /b 1