Skip to content

Commit abab4bb

Browse files
committed
feat: move to vcpkg
1 parent 98a71ea commit abab4bb

26 files changed

Lines changed: 130 additions & 37486 deletions

.github/workflows/build.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@ name: Build Mob
22

33
on:
44
push:
5-
branches: master
5+
branches: [master]
66
pull_request:
77
types: [opened, synchronize, reopened]
88

9+
env:
10+
VCPKG_BINARY_SOURCES: ${{ vars.AZ_BLOB_VCPKG_URL != '' && format('clear;x-azblob,{0},{1},readwrite', vars.AZ_BLOB_VCPKG_URL, secrets.AZ_BLOB_SAS) || '' }}
11+
912
jobs:
1013
build:
1114
runs-on: windows-2022
1215
steps:
1316
- uses: actions/checkout@v4
1417
- name: Build Mob
1518
shell: pwsh
16-
run: ./bootstrap.ps1 -Verbose
19+
run: |
20+
$env:VCPKG_ROOT = $env:VCPKG_INSTALLATION_ROOT
21+
./bootstrap.ps1 -Verbose

CMakePresets.json

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"version": 6,
3+
"configurePresets": [
4+
{
5+
"name": "vcpkg",
6+
"generator": "Visual Studio 17 2022",
7+
"architecture": "x64",
8+
"binaryDir": "${sourceDir}/build/",
9+
"toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
10+
"cacheVariables": {
11+
"VCPKG_TARGET_TRIPLET": "x64-windows-static-md",
12+
"CMAKE_CONFIGURATION_TYPES": "Debug;Release;RelWithDebInfo",
13+
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
14+
}
15+
}
16+
],
17+
"buildPresets": [
18+
{
19+
"name": "Base",
20+
"hidden": true,
21+
"nativeToolOptions": [
22+
"-m",
23+
"-noLogo",
24+
"-p:UseMultiToolTask=true",
25+
"-p:EnforceProcessCountAcrossBuilds=true"
26+
]
27+
},
28+
{
29+
"name": "Debug",
30+
"configurePreset": "vcpkg",
31+
"inherits": "Base",
32+
"configuration": "Debug"
33+
},
34+
{
35+
"name": "Release",
36+
"configurePreset": "vcpkg",
37+
"inherits": "Base",
38+
"configuration": "Release"
39+
},
40+
{
41+
"name": "RelWithDebInfo",
42+
"configurePreset": "vcpkg",
43+
"inherits": "Base",
44+
"configuration": "RelWithDebInfo"
45+
}
46+
]
47+
}

bootstrap.ps1

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,16 @@ if (!$root) {
1111
$root = "."
1212
}
1313

14-
$output = if ($Verbose) { "Out-Default" } else { "Out-Null" }
14+
$logLevel = if ($Verbose) { "STATUS" } else { "ERROR" }
1515

16-
cmake -B $root/build -G "Visual Studio 17 2022" $root | & $output
16+
cmake --preset vcpkg --log-level=$logLevel
1717

18-
$installationPath = & $root\third-party\bin\vswhere.exe -products * -nologo -prerelease -latest -property installationPath
19-
if (! $?) {
20-
Write-Error "vswhere returned $LastExitCode"
21-
exit $LastExitCode
22-
}
23-
24-
if (! $installationPath) {
25-
Write-Error "Empty installation path"
26-
exit 1
27-
}
28-
29-
$opts = ""
30-
$opts += " $root\build\mob.sln"
31-
$opts += " -m"
32-
$opts += " -p:Configuration=${Config}"
33-
$opts += " -noLogo"
34-
$opts += " -p:UseMultiToolTask=true"
35-
$opts += " -p:EnforceProcessCountAcrossBuilds=true"
36-
37-
if (!$Verbose) {
38-
$opts += " -clp:ErrorsOnly;Verbosity=minimal"
18+
if ($Verbose) {
19+
cmake --build --preset $Config
20+
} else {
21+
cmake --build --preset $Config -- -clp:ErrorsOnly -v:m
3922
}
4023

41-
$vsDevCmd = "$installationPath\Common7\Tools\VsDevCmd.bat"
42-
if (!(Test-Path "$vsDevCmd")) {
43-
Write-Error "VdDevCmd.bat not found at $vsDevCmd"
44-
exit 1
45-
}
46-
47-
& "${env:COMSPEC}" /c "`"$vsDevCmd`" -no_logo -arch=amd64 -host_arch=amd64 && msbuild $opts"
48-
4924
if (! $?) {
5025
Write-Error "Build failed"
5126
exit $LastExitCode

custom-ports/zlib/portfile.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)

custom-ports/zlib/vcpkg.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
3+
"name": "zlib",
4+
"version-string": "zlib-ng overlay",
5+
"dependencies": [
6+
"zlib-ng"
7+
]
8+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
set(VCPKG_TARGET_ARCHITECTURE x64)
2+
set(VCPKG_CRT_LINKAGE dynamic)
3+
set(VCPKG_LIBRARY_LINKAGE static)
4+
5+
set(ZLIB_COMPAT ON)
6+
set(nlohmann-json_IMPLICIT_CONVERSIONS OFF)

readme.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ check the [ModOrganizer2 Wiki](https://github.com/ModOrganizer2/modorganizer/wik
3333
```powershell
3434
git clone https://github.com/ModOrganizer2/mob
3535
cd mob
36+
$env:VCPKG_ROOT = "C:\path\to\vcpkg"
3637
./bootstrap
3738
mob -d c:\somewhere build
3839
```
@@ -108,6 +109,20 @@ aqt install-qt --outputdir "C:\Qt" windows desktop ${QT_VERSION} win64_msvc2022_
108109
- Git for Windows (Skip if you have this already installed outside of the VS installer)
109110
- CMake tools for Windows (Skip if you have this already installed outside of the VS installer)
110111

112+
### vcpkg
113+
114+
`mob` now uses **vcpkg** to manage its third-party dependencies (like libcurl).
115+
116+
1. **Install vcpkg**: If you don't have it, follow the [official instructions](https://learn.microsoft.com/en-us/vcpkg/get_started/get-started).
117+
2. **Set Environment Variable**: `mob` requires the `VCPKG_ROOT` environment variable to locate the toolchain.
118+
119+
```powershell
120+
$env:VCPKG_ROOT = "C:\path\to\vcpkg"
121+
$env:PATH = "$env:VCPKG_ROOT;$env:PATH"
122+
```
123+
124+
3. **Static Triplet**: `mob` builds with the `x64-windows-static-md` triplet by default to ensure a standalone executable. The `bootstrap.ps1` script handles this automatically if `VCPKG_ROOT` is set.
125+
111126
## Setting up MOB
112127

113128
```powershell
@@ -117,6 +132,9 @@ cd C:\dev
117132
# clone this repository
118133
git clone https://github.com/ModOrganizer2/mob
119134
135+
# set vcpkg path, or use `vcpkg integrate install` instead
136+
$env:VCPKG_ROOT = "C:\path\to\your\vcpkg"
137+
120138
# build mob itself - this will create mob.exe in the current directory
121139
./bootstrap.ps1
122140

src/CMakeLists.txt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
cmake_minimum_required(VERSION 3.16)
22

3+
find_package(clipp CONFIG REQUIRED)
4+
find_package(nlohmann_json CONFIG REQUIRED)
5+
find_package(CURL REQUIRED)
6+
37
file(GLOB_RECURSE source_files *.cpp)
48
file(GLOB_RECURSE header_files *.h)
59

610
add_executable(mob ${source_files} ${header_files})
711
set_target_properties(mob PROPERTIES CXX_STANDARD 20)
812

9-
target_compile_definitions(mob PUBLIC NOMINMAX)
10-
target_compile_options(mob PUBLIC "/MT")
11-
target_include_directories(mob PUBLIC ${CMAKE_SOURCE_DIR}/third-party/include)
12-
target_link_libraries(mob PUBLIC
13-
wsock32 ws2_32 crypt32 wldap32 dbghelp shlwapi version
14-
optimized ${CMAKE_SOURCE_DIR}/third-party/lib/libcurl.lib
15-
debug ${CMAKE_SOURCE_DIR}/third-party/lib/libcurl-d.lib
16-
optimized ${CMAKE_SOURCE_DIR}/third-party/lib/zlib.lib
17-
debug ${CMAKE_SOURCE_DIR}/third-party/lib/zlibd.lib)
13+
target_compile_definitions(mob PRIVATE NOMINMAX)
14+
15+
target_link_libraries(mob PRIVATE clipp::clipp nlohmann_json::nlohmann_json
16+
CURL::libcurl dbghelp shlwapi version)
1817

19-
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}
20-
PREFIX src
21-
FILES ${source_files} ${header_files})
18+
source_group(
19+
TREE ${CMAKE_CURRENT_SOURCE_DIR}
20+
PREFIX src
21+
FILES ${source_files} ${header_files})
2222
set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT mob)

src/cmd/pr.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ namespace mob {
236236

237237
for (auto&& item : json["items"]) {
238238
// ex: https://api.github.com/repos/ModOrganizer2/modorganizer-Installer
239-
const std::string url = item["repository_url"];
239+
const std::string url = item["repository_url"].get<std::string>();
240240

241241
const auto last_slash = url.find_last_of("/");
242242
if (last_slash == std::string::npos) {
@@ -246,7 +246,7 @@ namespace mob {
246246

247247
const auto repo = url.substr(last_slash + 1);
248248

249-
pr_info info = {repo, author, branch, item["title"],
249+
pr_info info = {repo, author, branch, item["title"].get<std::string>(),
250250
std::to_string(item["number"].get<int>())};
251251

252252
if (!repos.emplace(repo, info).second) {
@@ -287,9 +287,9 @@ namespace mob {
287287
const auto output = dl.steal_output();
288288
json = nlohmann::json::parse(output);
289289

290-
const std::string repo = json["head"]["repo"]["name"];
291-
const std::string author = json["head"]["repo"]["user"]["login"];
292-
const std::string branch = json["head"]["ref"];
290+
const std::string repo = json["head"]["repo"]["name"].get<std::string>();
291+
const std::string author = json["head"]["repo"]["user"]["login"].get<std::string>();
292+
const std::string branch = json["head"]["ref"].get<std::string>();
293293

294294
return {repo, author, branch};
295295
}

0 commit comments

Comments
 (0)