Integrate vcpkg support for Windows builds and enhance documentation

- Added vcpkg integration in CMake for Windows, enabling automatic dependency management.
- Updated CMakePresets.json to include presets for debug and release builds with vcpkg.
- Created setup scripts for easy vcpkg installation on Windows.
- Enhanced documentation to guide users on vcpkg setup and usage with YAZE.
- Improved logging in Overworld class to track expanded tile flags during map assembly.
This commit is contained in:
scawful
2025-09-27 20:05:00 -04:00
parent 7815f8cc85
commit 5e45c94e59
8 changed files with 344 additions and 4 deletions

View File

@@ -75,6 +75,14 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(YAZE_PLATFORM_LINUX ON)
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
set(YAZE_PLATFORM_WINDOWS ON)
# Enable vcpkg integration for Windows builds
if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "Vcpkg toolchain file")
elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake" AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "Vcpkg toolchain file")
endif()
endif()
# Create a common interface target for shared settings

View File

@@ -166,7 +166,7 @@
{
"name": "windows-debug",
"displayName": "Windows Debug",
"description": "Windows-specific debug configuration",
"description": "Windows-specific debug configuration with vcpkg",
"inherits": "debug",
"condition": {
"type": "equals",
@@ -177,7 +177,26 @@
"architecture": "x64",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/vcpkg/scripts/buildsystems/vcpkg.cmake",
"VCPKG_TARGET_TRIPLET": "x64-windows"
"VCPKG_TARGET_TRIPLET": "x64-windows",
"VCPKG_MANIFEST_MODE": "ON"
}
},
{
"name": "windows-release",
"displayName": "Windows Release",
"description": "Windows-specific release configuration with vcpkg",
"inherits": "release",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
},
"generator": "Visual Studio 17 2022",
"architecture": "x64",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/vcpkg/scripts/buildsystems/vcpkg.cmake",
"VCPKG_TARGET_TRIPLET": "x64-windows",
"VCPKG_MANIFEST_MODE": "ON"
}
},
{
@@ -260,6 +279,16 @@
"configurePreset": "debug",
"displayName": "Fast Debug Build",
"jobs": 0
},
{
"name": "windows-debug",
"configurePreset": "windows-debug",
"displayName": "Windows Debug Build"
},
{
"name": "windows-release",
"configurePreset": "windows-release",
"displayName": "Windows Release Build"
}
],
"testPresets": [

View File

@@ -1,6 +1,26 @@
# vcpkg configuration for Windows builds
add_definitions("-DMICROSOFT_WINDOWS_WINBASE_H_DEFINE_INTERLOCKED_CPLUSPLUS_OVERLOADS=0")
# vcpkg settings
set(VCPKG_TARGET_ARCHITECTURE x64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)
# Enable vcpkg manifest mode for automatic dependency management
set(VCPKG_MANIFEST_MODE ON)
# Configure vcpkg triplet (defaults to x64-windows)
if(NOT DEFINED VCPKG_TARGET_TRIPLET)
set(VCPKG_TARGET_TRIPLET "x64-windows" CACHE STRING "vcpkg target triplet")
endif()
# Set vcpkg installation directory if not already set
if(NOT DEFINED VCPKG_INSTALLED_DIR)
set(VCPKG_INSTALLED_DIR "${CMAKE_BINARY_DIR}/vcpkg_installed" CACHE PATH "vcpkg installed directory")
endif()
message(STATUS "vcpkg configuration:")
message(STATUS " Target triplet: ${VCPKG_TARGET_TRIPLET}")
message(STATUS " Installed directory: ${VCPKG_INSTALLED_DIR}")
message(STATUS " Manifest mode: ${VCPKG_MANIFEST_MODE}")

View File

@@ -59,9 +59,40 @@ sudo apt-get install -y build-essential cmake ninja-build pkg-config \
- Visual Studio 2019+ with C++ CMake tools
- No additional dependencies needed (all bundled)
**Option 2 - Full Development:**
**Option 2 - Full Development with vcpkg (Recommended):**
- Visual Studio 2019+ with C++ CMake tools
- Install vcpkg and dependencies from `vcpkg.json`
#### vcpkg Setup (Option 2)
Run the setup script to automatically configure vcpkg:
```cmd
# Command Prompt
scripts\setup-vcpkg-windows.bat
# PowerShell
.\scripts\setup-vcpkg-windows.ps1
```
Or manually:
```cmd
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
.\bootstrap-vcpkg.bat
.\vcpkg.exe integrate install
set VCPKG_ROOT=%CD%
```
#### Windows Build Commands
```cmd
# Debug build with vcpkg
cmake --preset windows-debug
cmake --build build --preset windows-debug
# Release build with vcpkg
cmake --preset windows-release
cmake --build build --preset windows-release
```
## Build Targets
### Applications

140
docs/vcpkg-integration.md Normal file
View File

@@ -0,0 +1,140 @@
# vcpkg Integration for Windows Builds
This document describes how to use vcpkg for Windows builds in Visual Studio with YAZE.
## Overview
vcpkg is Microsoft's C++ package manager that simplifies dependency management for Windows builds. YAZE now includes full vcpkg integration with manifest mode support for automatic dependency resolution.
## Features
- **Manifest Mode**: Dependencies are automatically managed via `vcpkg.json`
- **Visual Studio Integration**: Seamless integration with Visual Studio 2019+
- **CMake Presets**: Pre-configured build presets for Windows
- **Automatic Setup**: Setup scripts for easy vcpkg installation
## Quick Start
### 1. Setup vcpkg
Run the automated setup script:
```cmd
# Command Prompt
scripts\setup-vcpkg-windows.bat
# PowerShell
.\scripts\setup-vcpkg-windows.ps1
```
### 2. Build with vcpkg
Use the Windows presets in CMakePresets.json:
```cmd
# Debug build
cmake --preset windows-debug
cmake --build build --preset windows-debug
# Release build
cmake --preset windows-release
cmake --build build --preset windows-release
```
## Configuration Details
### vcpkg.json Manifest
The `vcpkg.json` file defines all dependencies:
```json
{
"name": "yaze",
"version": "0.3.1",
"dependencies": [
"zlib",
"libpng",
"sdl2",
"abseil",
"gtest"
]
}
```
### CMake Configuration
vcpkg integration is handled in several files:
- **CMakeLists.txt**: Automatic toolchain detection
- **cmake/vcpkg.cmake**: vcpkg-specific settings
- **CMakePresets.json**: Windows build presets
### Build Presets
Available Windows presets:
- `windows-debug`: Debug build with vcpkg
- `windows-release`: Release build with vcpkg
## Dependencies
vcpkg automatically installs these dependencies:
- **zlib**: Compression library
- **libpng**: PNG image support
- **sdl2**: Graphics and input handling
- **abseil**: Google's C++ common libraries
- **gtest**: Google Test framework (with gmock)
## Environment Variables
Set `VCPKG_ROOT` to point to your vcpkg installation:
```cmd
set VCPKG_ROOT=C:\path\to\vcpkg
```
## Troubleshooting
### Common Issues
1. **vcpkg not found**: Ensure `VCPKG_ROOT` is set or vcpkg is in the project directory
2. **Dependencies not installing**: Check internet connection and vcpkg bootstrap
3. **Visual Studio integration**: Run `vcpkg integrate install` from vcpkg directory
### Manual Setup
If automated setup fails:
```cmd
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
.\bootstrap-vcpkg.bat
.\vcpkg.exe integrate install
```
## Benefits
- **Consistent Dependencies**: Same versions across development environments
- **Easy Updates**: Update dependencies via vcpkg.json
- **CI/CD Friendly**: Reproducible builds
- **Visual Studio Integration**: Native IntelliSense support
- **No Manual Downloads**: Automatic dependency resolution
## Advanced Usage
### Custom Triplets
Override the default x64-windows triplet:
```cmd
cmake --preset windows-debug -DVCPKG_TARGET_TRIPLET=x86-windows
```
### Static Linking
For static builds, modify `cmake/vcpkg.cmake`:
```cmake
set(VCPKG_LIBRARY_LINKAGE static)
set(VCPKG_CRT_LINKAGE static)
```

View File

@@ -0,0 +1,54 @@
@echo off
REM Setup script for vcpkg on Windows
REM This script helps set up vcpkg for YAZE Windows builds
echo Setting up vcpkg for YAZE Windows builds...
REM Check if vcpkg directory exists
if not exist "vcpkg" (
echo Cloning vcpkg...
git clone https://github.com/Microsoft/vcpkg.git
if errorlevel 1 (
echo Error: Failed to clone vcpkg repository
pause
exit /b 1
)
)
REM Bootstrap vcpkg
cd vcpkg
if not exist "vcpkg.exe" (
echo Bootstrapping vcpkg...
call bootstrap-vcpkg.bat
if errorlevel 1 (
echo Error: Failed to bootstrap vcpkg
pause
exit /b 1
)
)
REM Integrate vcpkg with Visual Studio (optional)
echo Integrating vcpkg with Visual Studio...
vcpkg integrate install
REM Set environment variable for this session
set VCPKG_ROOT=%CD%
echo VCPKG_ROOT set to: %VCPKG_ROOT%
cd ..
echo.
echo vcpkg setup complete!
echo.
echo To use vcpkg with YAZE:
echo 1. Use the Windows presets in CMakePresets.json:
echo - windows-debug (Debug build)
echo - windows-release (Release build)
echo.
echo 2. Or set VCPKG_ROOT environment variable:
echo set VCPKG_ROOT=%CD%\vcpkg
echo.
echo 3. Dependencies will be automatically installed via vcpkg manifest mode
echo.
pause

View File

@@ -0,0 +1,54 @@
# Setup script for vcpkg on Windows (PowerShell)
# This script helps set up vcpkg for YAZE Windows builds
Write-Host "Setting up vcpkg for YAZE Windows builds..." -ForegroundColor Green
# Check if vcpkg directory exists
if (-not (Test-Path "vcpkg")) {
Write-Host "Cloning vcpkg..." -ForegroundColor Yellow
git clone https://github.com/Microsoft/vcpkg.git
if ($LASTEXITCODE -ne 0) {
Write-Host "Error: Failed to clone vcpkg repository" -ForegroundColor Red
Read-Host "Press Enter to continue"
exit 1
}
}
# Bootstrap vcpkg
Set-Location vcpkg
if (-not (Test-Path "vcpkg.exe")) {
Write-Host "Bootstrapping vcpkg..." -ForegroundColor Yellow
& .\bootstrap-vcpkg.bat
if ($LASTEXITCODE -ne 0) {
Write-Host "Error: Failed to bootstrap vcpkg" -ForegroundColor Red
Read-Host "Press Enter to continue"
exit 1
}
}
# Integrate vcpkg with Visual Studio (optional)
Write-Host "Integrating vcpkg with Visual Studio..." -ForegroundColor Yellow
& .\vcpkg.exe integrate install
# Set environment variable for this session
$vcpkgRoot = Get-Location
$env:VCPKG_ROOT = $vcpkgRoot.Path
Write-Host "VCPKG_ROOT set to: $($env:VCPKG_ROOT)" -ForegroundColor Green
Set-Location ..
Write-Host ""
Write-Host "vcpkg setup complete!" -ForegroundColor Green
Write-Host ""
Write-Host "To use vcpkg with YAZE:" -ForegroundColor Cyan
Write-Host "1. Use the Windows presets in CMakePresets.json:" -ForegroundColor White
Write-Host " - windows-debug (Debug build)" -ForegroundColor Gray
Write-Host " - windows-release (Release build)" -ForegroundColor Gray
Write-Host ""
Write-Host "2. Or set VCPKG_ROOT environment variable:" -ForegroundColor White
Write-Host " `$env:VCPKG_ROOT = `"$vcpkgRoot`"" -ForegroundColor Gray
Write-Host ""
Write-Host "3. Dependencies will be automatically installed via vcpkg manifest mode" -ForegroundColor White
Write-Host ""
Read-Host "Press Enter to continue"

View File

@@ -216,7 +216,9 @@ absl::Status Overworld::AssembleMap32Tiles() {
// Check if expanded tile32 data is actually present in ROM
// The flag position should contain 0x04 for vanilla, something else for expanded
uint8_t asm_version = (*rom_)[OverworldCustomASMHasBeenApplied];
if (rom()->data()[kMap32ExpandedFlagPos] != 0x04 || asm_version >= 3) {
uint8_t expanded_flag = rom()->data()[kMap32ExpandedFlagPos];
util::logf("Expanded tile32 flag: %d", expanded_flag);
if (expanded_flag != 0x04 || asm_version >= 3) {
// ROM has expanded tile32 data - use expanded addresses
map32address[0] = rom()->version_constants().kMap32TileTL;
map32address[1] = kMap32TileTRExpanded;
@@ -270,6 +272,8 @@ absl::Status Overworld::AssembleMap16Tiles() {
// Check if expanded tile16 data is actually present in ROM
// The flag position should contain 0x0F for vanilla, something else for expanded
uint8_t asm_version = (*rom_)[OverworldCustomASMHasBeenApplied];
uint8_t expanded_flag = rom()->data()[kMap16ExpandedFlagPos];
util::logf("Expanded tile16 flag: %d", expanded_flag);
if (rom()->data()[kMap16ExpandedFlagPos] == 0x0F || asm_version >= 3) {
// ROM has expanded tile16 data - use expanded addresses
tpos = kMap16TilesExpanded;