From caf6f9ebd0bf447b904811b03cc3ceb6e875638c Mon Sep 17 00:00:00 2001 From: gaozheng Date: Tue, 9 Jun 2026 19:07:14 +0800 Subject: [PATCH] =?UTF-8?q?docs(build):=20=E6=96=B0=E5=A2=9E=20build.bat?= =?UTF-8?q?=20=E4=B8=80=E9=94=AE=E6=9E=84=E5=BB=BA=E8=84=9A=E6=9C=AC=20+?= =?UTF-8?q?=20README=20=E8=A1=A5=E5=85=85=E6=9E=84=E5=BB=BA=E4=B8=8E?= =?UTF-8?q?=E8=BF=90=E8=A1=8C=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 52 +++++++++++++++++++++++++++++------- build.bat | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+), 10 deletions(-) create mode 100644 build.bat diff --git a/README.md b/README.md index e883264..6602a55 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ ## 技术栈 -Qt 6.8 LTS(QtWidgets)+ VTK 9.3+ · CMake + vcpkg(全量,含 Qt)· MSVC 2022 / C++17 · ADS 停靠 · GDAL/PROJ · OpenSSL · QtKeychain。 +Qt 6.11(QtWidgets)+ VTK 9.6 · CMake + Ninja · 官方 MSVC 预编译 Qt + vcpkg(仅非 Qt 依赖)· MSVC(VS 2022/2026)/ C++17 · ADS 停靠 · GDAL/PROJ · OpenSSL · QtKeychain。 ## 目录(设计 §3) @@ -25,19 +25,51 @@ tools/ 离线验证脚本(validate_samples.py) docs/ 规约、API、样本数据、设计文档 ``` -## 快速开始 +## 构建与运行 -前置:VS2022(C++ 桌面开发)、Git、vcpkg(设 `VCPKG_ROOT`)。详见 ENV_SETUP_Windows.md。 +前置:**Visual Studio 2022/2026**(勾选「使用 C++ 的桌面开发」工作负载,自带 CMake + Ninja)、Git、**vcpkg** 并设环境变量 `VCPKG_ROOT`。构建方案②:单一官方 MSVC 预编译 Qt(`CMAKE_PREFIX_PATH` → `D:/Qt/6.11.1/msvc2022_64`)、VTK 预编译于 `external/vtk-install`、ADS/QtKeychain 经 FetchContent 对接同一份 Qt、仅非 Qt 依赖(GDAL/PROJ/OpenSSL/…)走 vcpkg。详见 [docs/ENV_SETUP_Windows.md](docs/ENV_SETUP_Windows.md)。 -```powershell -# x64 Native Tools 命令行,项目根 -vcpkg x-update-baseline --add-initial-baseline # 锁依赖版本 -cmake --preset msvc-debug # 首次编译 Qt+VTK,较久 -cmake --build build/debug -.\build\debug\src\app\geopro_desktop.exe # spike 冒烟:应显示一个锥体 -ctest --test-dir build/debug # 运行单测 +> ⚠️ 本机 `cmake` / `ninja` / `cl` **默认不在 PATH**,必须在已激活 MSVC 环境的终端里构建。下面三种方式都已处理好这一点。 + +### 方式一:一键脚本(推荐) + +项目根的 `build.bat` 自动用 vswhere 定位 VS、激活 MSVC 环境、按需配置并编译。在 **cmd** 里于项目根执行 `build <命令>`: + +| 命令 | 作用 | +|---|---| +| `build`(或 `build app`) | 编译主程序 `geopro_desktop`(默认) | +| `build run` | 编译并运行主程序 | +| `build test` | 编译并跑单元测试(ctest) | +| `build all` | 编译全部目标 | +| `build configure` | 改了 CMakeLists / 新增源文件后,强制重新配置 | + +### 方式二:Visual Studio 打开文件夹 + +VS →「打开本地文件夹」→ 选仓库根 → 自动识别 `CMakePresets.json` → 选配置 **MSVC Release** → 菜单「生成 → 全部生成」;运行/调试目标选 `geopro_desktop`。 + +### 方式三:手动命令行 + +开始菜单打开「**x64 Native Tools Command Prompt for VS**」(已带 MSVC 环境),在仓库根(CMake 用 VS 自带的全路径,因其不在 PATH): + +```bat +set CMAKE="%VSINSTALLDIR%Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" +%CMAKE% --preset msvc-release :: 配置(首次 / 改 CMakeLists 后) +%CMAKE% --build build/release --target geopro_desktop :: 编译主程序 +build\release\src\app\geopro_desktop.exe :: 运行 +%CMAKE% --build build/release --target geopro_tests :: 编译测试 +ctest --test-dir build/release --output-on-failure :: 跑测试 ``` +(Debug 用 `--preset msvc-debug`,对应 `build/debug`。`%VSINSTALLDIR%` 在 Native Tools 提示符里已设好。) + +### 构建目标与产物 + +- `geopro_desktop` — 主程序,产物 `build/release/src/app/geopro_desktop.exe` +- `geopro_tests` — 单元测试,配 `ctest` +- 不带 `--target` 编译全部 + +> 改了已有 `.cpp/.hpp` 直接 `--build`(Ninja 增量);改了 `CMakeLists.txt` 或新增源文件需先 `--preset` / `build configure`。链接报 **LNK1104**(文件被占用)时,先关掉运行中的 `geopro_desktop.exe`。 + ## 当前状态 M1 设计完成(v2,经双专家评审)。进入 **spike 预研**(设计 §15):① 全 vcpkg 构建/部署 ② ADS + QVTKOpenGLStereoWidget 停靠稳定 ③ 真实样本跑通 banded contour。spike 通过后展开完整实现计划。 diff --git a/build.bat b/build.bat new file mode 100644 index 0000000..86db412 --- /dev/null +++ b/build.bat @@ -0,0 +1,79 @@ +@echo off +REM ============================================================ +REM geopro build helper (Windows / MSVC + Ninja, CMake presets) +REM +REM Usage: build [app | all | test | run | configure] +REM app (default) build target geopro_desktop +REM all build all targets +REM test build + run unit tests via ctest +REM run build + launch geopro_desktop +REM configure force re-run CMake configure (after CMakeLists changes) +REM +REM Requires: Visual Studio 2022/2026 (Desktop C++ workload, ships +REM CMake + Ninja) and the VCPKG_ROOT environment variable. +REM Note: cmake/ninja/cl are NOT on PATH on this machine; this script +REM locates VS via vswhere and activates the MSVC env itself. +REM ============================================================ +setlocal +set "ROOT=%~dp0" +set "BUILDDIR=%ROOT%build\release" +set "PRESET=msvc-release" + +REM --- locate Visual Studio (vswhere lives at a fixed path) --- +set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" +if not exist "%VSWHERE%" ( + echo [build] vswhere not found. Open "x64 Native Tools Command Prompt for VS" and build manually. + exit /b 1 +) +for /f "usebackq tokens=*" %%i in (`"%VSWHERE%" -latest -property installationPath`) do set "VSPATH=%%i" +if not defined VSPATH ( echo [build] Visual Studio not found. & exit /b 1 ) + +set "VCVARS=%VSPATH%\VC\Auxiliary\Build\vcvars64.bat" +set "CMAKE=%VSPATH%\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" +set "CTEST=%VSPATH%\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\ctest.exe" +if not exist "%VCVARS%" ( echo [build] vcvars64.bat not found: %VCVARS% & exit /b 1 ) +if not exist "%CMAKE%" ( echo [build] cmake not found: %CMAKE% & exit /b 1 ) + +REM --- activate MSVC environment (cl / link / include / lib) --- +call "%VCVARS%" >nul + +set "CMD=%~1" +if "%CMD%"=="" set "CMD=app" + +if /i "%CMD%"=="configure" goto :configure +if /i "%CMD%"=="app" goto :app +if /i "%CMD%"=="all" goto :all +if /i "%CMD%"=="test" goto :test +if /i "%CMD%"=="run" goto :run +echo [build] unknown command "%CMD%". Use: app ^| all ^| test ^| run ^| configure +exit /b 1 + +:ensure +if not exist "%BUILDDIR%\CMakeCache.txt" "%CMAKE%" --preset %PRESET% +exit /b 0 + +:configure +"%CMAKE%" --preset %PRESET% +exit /b %errorlevel% + +:app +call :ensure +"%CMAKE%" --build "%BUILDDIR%" --target geopro_desktop +exit /b %errorlevel% + +:all +call :ensure +"%CMAKE%" --build "%BUILDDIR%" +exit /b %errorlevel% + +:test +call :ensure +"%CMAKE%" --build "%BUILDDIR%" --target geopro_tests || exit /b 1 +"%CTEST%" --test-dir "%BUILDDIR%" --output-on-failure +exit /b %errorlevel% + +:run +call :ensure +"%CMAKE%" --build "%BUILDDIR%" --target geopro_desktop || exit /b 1 +"%BUILDDIR%\src\app\geopro_desktop.exe" +exit /b %errorlevel%