Skip to content

Commit 64c62ad

Browse files
authored
feat: move to vcpkg (#161)
1 parent 98a71ea commit 64c62ad

29 files changed

Lines changed: 148 additions & 37497 deletions

.github/workflows/build.yml

Lines changed: 8 additions & 3 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:
13-
- uses: actions/checkout@v4
16+
- uses: actions/checkout@v6
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

.github/workflows/linting.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
lint:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v3
12+
- uses: actions/checkout@v6
1313
- name: Check format
1414
uses: ModOrganizer2/check-formatting-action@master
1515
with:

CMakeLists.txt

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

3-
project(mob)
3+
project(mob LANGUAGES CXX)
4+
5+
find_package(clipp CONFIG REQUIRED)
6+
find_package(nlohmann_json CONFIG REQUIRED)
7+
find_package(CURL REQUIRED)
8+
49
add_subdirectory(src)
510

611
set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT mob)

CMakePresets.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
}
14+
}
15+
],
16+
"buildPresets": [
17+
{
18+
"name": "Base",
19+
"hidden": true,
20+
"nativeToolOptions": [
21+
"-m",
22+
"-noLogo",
23+
"-p:UseMultiToolTask=true",
24+
"-p:EnforceProcessCountAcrossBuilds=true"
25+
]
26+
},
27+
{
28+
"name": "Debug",
29+
"configurePreset": "vcpkg",
30+
"inherits": "Base",
31+
"configuration": "Debug"
32+
},
33+
{
34+
"name": "Release",
35+
"configurePreset": "vcpkg",
36+
"inherits": "Base",
37+
"configuration": "Release"
38+
},
39+
{
40+
"name": "RelWithDebInfo",
41+
"configurePreset": "vcpkg",
42+
"inherits": "Base",
43+
"configuration": "RelWithDebInfo"
44+
}
45+
]
46+
}

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 --verbose
20+
} else {
21+
cmake --build --preset $Config
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: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
cmake_minimum_required(VERSION 3.16)
2-
3-
file(GLOB_RECURSE source_files *.cpp)
4-
file(GLOB_RECURSE header_files *.h)
1+
file(GLOB_RECURSE source_files CONFIGURE_DEPENDS "*.cpp")
2+
file(GLOB_RECURSE header_files CONFIGURE_DEPENDS "*.h")
53

64
add_executable(mob ${source_files} ${header_files})
7-
set_target_properties(mob PROPERTIES CXX_STANDARD 20)
85

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)
6+
target_compile_features(mob PRIVATE cxx_std_20)
7+
8+
target_compile_definitions(
9+
mob PRIVATE _WIN32_WINNT=0x0A00 NTDDI_VERSION=0x0A000007 WIN32_LEAN_AND_MEAN
10+
NOMINMAX NOCOMM)
11+
12+
target_link_libraries(mob PRIVATE clipp::clipp nlohmann_json::nlohmann_json
13+
CURL::libcurl dbghelp shlwapi version)
1814

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

0 commit comments

Comments
 (0)