build: use explicit Qt paths in CMake presets
Remove QT_ROOT/MINGW_ROOT environment indirection for Windows and macOS; edit CMAKE_PREFIX_PATH and MinGW compiler paths directly in CMakePresets.json. Document clean reconfigure when paths change.
This commit is contained in:
+12
-12
@@ -36,12 +36,12 @@
|
||||
},
|
||||
{
|
||||
"name": "windows-msvc",
|
||||
"displayName": "Windows MSVC (set QT_ROOT)",
|
||||
"displayName": "Windows MSVC (edit Qt path in preset)",
|
||||
"generator": "Ninja",
|
||||
"binaryDir": "${sourceDir}/build/windows-msvc",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Debug",
|
||||
"CMAKE_PREFIX_PATH": "$env{QT_ROOT}"
|
||||
"CMAKE_PREFIX_PATH": "C:/Qt/6.6.3/msvc2019_64"
|
||||
},
|
||||
"warnings": {
|
||||
"deprecated": false
|
||||
@@ -49,16 +49,16 @@
|
||||
},
|
||||
{
|
||||
"name": "windows-mingw",
|
||||
"displayName": "Windows MinGW-w64 (set QT_ROOT and MINGW_ROOT)",
|
||||
"description": "Debug build using Qt's MinGW kit and the matching MinGW toolchain",
|
||||
"displayName": "Windows MinGW-w64 (edit Qt/MinGW paths in preset)",
|
||||
"description": "Debug build using Qt's MinGW kit; edit the paths below before configuring",
|
||||
"generator": "Ninja",
|
||||
"binaryDir": "${sourceDir}/build/windows-mingw",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Debug",
|
||||
"CMAKE_PREFIX_PATH": "$env{QT_ROOT}",
|
||||
"CMAKE_C_COMPILER": "$env{MINGW_ROOT}/bin/gcc.exe",
|
||||
"CMAKE_CXX_COMPILER": "$env{MINGW_ROOT}/bin/g++.exe",
|
||||
"CMAKE_RC_COMPILER": "$env{MINGW_ROOT}/bin/windres.exe",
|
||||
"CMAKE_PREFIX_PATH": "C:/Qt/6.6.3/mingw_64",
|
||||
"CMAKE_C_COMPILER": "C:/Qt/Tools/mingw1120_64/bin/gcc.exe",
|
||||
"CMAKE_CXX_COMPILER": "C:/Qt/Tools/mingw1120_64/bin/g++.exe",
|
||||
"CMAKE_RC_COMPILER": "C:/Qt/Tools/mingw1120_64/bin/windres.exe",
|
||||
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
|
||||
},
|
||||
"warnings": {
|
||||
@@ -67,12 +67,12 @@
|
||||
},
|
||||
{
|
||||
"name": "macos-clang",
|
||||
"displayName": "macOS Clang (set QT_ROOT)",
|
||||
"displayName": "macOS Clang (edit Qt path in preset)",
|
||||
"generator": "Ninja",
|
||||
"binaryDir": "${sourceDir}/build/macos-clang",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Debug",
|
||||
"CMAKE_PREFIX_PATH": "$env{QT_ROOT}"
|
||||
"CMAKE_PREFIX_PATH": "/Users/yourname/Qt/6.6.3/macos"
|
||||
},
|
||||
"warnings": {
|
||||
"deprecated": false
|
||||
@@ -130,7 +130,7 @@
|
||||
},
|
||||
"environment": {
|
||||
"QT_QPA_PLATFORM": "offscreen",
|
||||
"PATH": "$env{QT_ROOT}/bin;$penv{PATH}"
|
||||
"PATH": "C:/Qt/6.6.3/msvc2019_64/bin;$penv{PATH}"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -141,7 +141,7 @@
|
||||
},
|
||||
"environment": {
|
||||
"QT_QPA_PLATFORM": "offscreen",
|
||||
"PATH": "$env{QT_ROOT}/bin;$env{MINGW_ROOT}/bin;$penv{PATH}"
|
||||
"PATH": "C:/Qt/6.6.3/mingw_64/bin;C:/Qt/Tools/mingw1120_64/bin;$penv{PATH}"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
@@ -91,42 +91,53 @@ cmake --build --preset linux-gcc
|
||||
|
||||
若检测到 Go,构建时会同时生成 `build/linux-gcc/bin/schedule-sync-server`;未安装 Go 时客户端仍可单独构建,同步集成测试会自动跳过。
|
||||
|
||||
如果 Qt 不在 `/home/misaki/Qt6.3/6.6.3/gcc_64`,修改 `CMakePresets.json` 中
|
||||
`linux-gcc` 的 `CMAKE_PREFIX_PATH`,或使用 `windows-mingw` / `windows-msvc` / `macos-clang`
|
||||
preset 并通过环境变量 `QT_ROOT` 指定 Qt。
|
||||
如果 Qt 不在 `/home/misaki/Qt6.3/6.6.3/gcc_64`,直接修改 `CMakePresets.json` 中
|
||||
`linux-gcc` 的 `CMAKE_PREFIX_PATH`。Windows / macOS 同样在对应 preset 中手动填写路径,
|
||||
不依赖 `find_package` 自动搜索或环境变量。
|
||||
|
||||
### Windows + MinGW
|
||||
|
||||
1. 安装 Qt 6.5+ 的 **MinGW 64-bit** 套件,并在 Qt Maintenance Tool 中确认包含 **Qt WebSockets**;
|
||||
同时安装与该 Qt 套件匹配的 MinGW 工具链(官方安装器通常位于 `C:/Qt/Tools/mingw1120_64`)。
|
||||
不要混用 MSVC Qt、不同版本的 MinGW Qt 或系统里的其他 g++。
|
||||
2. 在 PowerShell 中设置环境变量(路径按实际安装修改):
|
||||
2. 打开 `CMakePresets.json`,手动修改 `windows-mingw` preset 中的路径:
|
||||
|
||||
```json
|
||||
"CMAKE_PREFIX_PATH": "C:/Qt/6.6.3/mingw_64",
|
||||
"CMAKE_C_COMPILER": "C:/Qt/Tools/mingw1120_64/bin/gcc.exe",
|
||||
"CMAKE_CXX_COMPILER": "C:/Qt/Tools/mingw1120_64/bin/g++.exe",
|
||||
"CMAKE_RC_COMPILER": "C:/Qt/Tools/mingw1120_64/bin/windres.exe",
|
||||
```
|
||||
|
||||
同时把 `testPresets` 中同名 `windows-mingw` 的 `PATH` 改成相同的 Qt/MinGW `bin` 路径。
|
||||
Qt 路径由 preset 的 `CMAKE_PREFIX_PATH` 显式提供,不依赖 `find_package` 自动探测或
|
||||
`QT_ROOT` / `MINGW_ROOT` 环境变量。若已经配置过,修改路径后请删除
|
||||
`build/windows-mingw` 再重新执行 `cmake --preset windows-mingw`,避免 CMake 缓存旧编译器。
|
||||
3. 在 PowerShell 中直接构建和测试:
|
||||
|
||||
```powershell
|
||||
$env:QT_ROOT = "C:/Qt/6.6.3/mingw_64"
|
||||
$env:MINGW_ROOT = "C:/Qt/Tools/mingw1120_64"
|
||||
$env:Path = "$env:QT_ROOT/bin;$env:MINGW_ROOT/bin;$env:Path"
|
||||
|
||||
cmake --preset windows-mingw
|
||||
cmake --build --preset windows-mingw -j 8
|
||||
ctest --preset windows-mingw --output-on-failure
|
||||
```
|
||||
|
||||
`windows-mingw` preset 使用 Ninja,并显式指定 `gcc.exe` / `g++.exe` / `windres.exe`,
|
||||
不会退回 MSVC。测试 preset 会把 Qt 和 MinGW 的 `bin` 加入 `PATH`,并使用
|
||||
`QT_QPA_PLATFORM=offscreen`,不需要桌面会话。
|
||||
3. 运行:
|
||||
`windows-mingw` 使用 Ninja,并显式指定 `gcc.exe` / `g++.exe` / `windres.exe`,
|
||||
不会退回 MSVC。测试 preset 使用 `QT_QPA_PLATFORM=offscreen`,不需要桌面会话。
|
||||
4. 运行:
|
||||
|
||||
```powershell
|
||||
.\build\windows-mingw\bin\Schedule.exe
|
||||
```
|
||||
|
||||
开发时保持 `QT_ROOT/bin` 在 `PATH` 即可;分发前可用
|
||||
`$env:QT_ROOT/bin/windeployqt.exe build/windows-mingw/bin/Schedule.exe` 收集 Qt DLL。
|
||||
4. 若 Windows 上安装了 Go,构建会同时生成 `build/windows-mingw/bin/schedule-sync-server.exe`
|
||||
若运行时找不到 Qt DLL,把 `C:/Qt/6.6.3/mingw_64/bin` 加入当前终端 `PATH`,或分发前执行
|
||||
`C:/Qt/6.6.3/mingw_64/bin/windeployqt.exe build/windows-mingw/bin/Schedule.exe`。
|
||||
5. 若 Windows 上安装了 Go,构建会同时生成 `build/windows-mingw/bin/schedule-sync-server.exe`
|
||||
并运行双客户端同步集成测试;没有 Go 时该测试自动跳过。也可以把同步服务端跑在 Linux
|
||||
或另一台机器上,客户端只需填写 `http://<server>:8787`。
|
||||
|
||||
`windows-msvc` 与 `macos-clang` 也采用相同的做法:在对应 preset 中直接填写
|
||||
`CMAKE_PREFIX_PATH`,不使用环境变量或自动搜索。
|
||||
|
||||
### Windows 多设备联调
|
||||
|
||||
1. 在服务端机器启动 `go run ./cmd/server`(或 Docker),设置随机 `SYNC_TOKEN_PEPPER`。
|
||||
|
||||
Reference in New Issue
Block a user