Add CMake availability checks and installation in project generation scripts
- Implemented checks for CMake in both batch and PowerShell scripts to ensure it is available before proceeding. - Added logic to attempt installation of CMake via Chocolatey if not found, with appropriate user feedback. - Enhanced user experience by providing instructions for manual installation if Chocolatey is not present. - Included verification steps to confirm successful installation of CMake after the installation attempt. - Introduced a new setup script for Windows development environment, automating the installation of essential tools like Git, Ninja, and Python 3, along with checks for Visual Studio.
This commit is contained in:
@@ -41,6 +41,60 @@ if not "%OS%"=="Windows_NT" (
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM Check if CMake is available
|
||||
where cmake >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
REM Try common CMake installation paths
|
||||
if exist "C:\Program Files\CMake\bin\cmake.exe" (
|
||||
echo Found CMake at: C:\Program Files\CMake\bin\cmake.exe
|
||||
set "PATH=%PATH%;C:\Program Files\CMake\bin"
|
||||
goto :cmake_found
|
||||
)
|
||||
if exist "C:\Program Files (x86)\CMake\bin\cmake.exe" (
|
||||
echo Found CMake at: C:\Program Files (x86)\CMake\bin\cmake.exe
|
||||
set "PATH=%PATH%;C:\Program Files (x86)\CMake\bin"
|
||||
goto :cmake_found
|
||||
)
|
||||
if exist "C:\cmake\bin\cmake.exe" (
|
||||
echo Found CMake at: C:\cmake\bin\cmake.exe
|
||||
set "PATH=%PATH%;C:\cmake\bin"
|
||||
goto :cmake_found
|
||||
)
|
||||
|
||||
REM If we get here, CMake is not found
|
||||
echo CMake not found in PATH. Attempting to install...
|
||||
|
||||
REM Try to install CMake via Chocolatey
|
||||
where choco >nul 2>&1
|
||||
if not errorlevel 1 (
|
||||
echo Installing CMake via Chocolatey...
|
||||
choco install -y cmake
|
||||
if errorlevel 1 (
|
||||
echo Failed to install CMake via Chocolatey
|
||||
) else (
|
||||
echo CMake installed successfully
|
||||
REM Refresh PATH
|
||||
call refreshenv
|
||||
)
|
||||
) else (
|
||||
echo Chocolatey not found. Please install CMake manually:
|
||||
echo 1. Download from: https://cmake.org/download/
|
||||
echo 2. Or install Chocolatey first: https://chocolatey.org/install
|
||||
echo 3. Then run: choco install cmake
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM Check again after installation
|
||||
where cmake >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo CMake still not found after installation. Please restart your terminal or add CMake to PATH manually.
|
||||
exit /b 1
|
||||
)
|
||||
)
|
||||
|
||||
:cmake_found
|
||||
echo CMake found and ready to use
|
||||
|
||||
REM Set up paths
|
||||
set SOURCE_DIR=%~dp0..
|
||||
set BUILD_DIR=%SOURCE_DIR%\build-vs
|
||||
|
||||
@@ -27,6 +27,77 @@ if ($env:OS -ne "Windows_NT") {
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Check if CMake is available
|
||||
$cmakePath = Get-Command cmake -ErrorAction SilentlyContinue
|
||||
if (-not $cmakePath) {
|
||||
# Try common CMake installation paths
|
||||
$commonPaths = @(
|
||||
"C:\Program Files\CMake\bin\cmake.exe",
|
||||
"C:\Program Files (x86)\CMake\bin\cmake.exe",
|
||||
"C:\cmake\bin\cmake.exe"
|
||||
)
|
||||
|
||||
foreach ($path in $commonPaths) {
|
||||
if (Test-Path $path) {
|
||||
Write-Host "Found CMake at: $path" -ForegroundColor Green
|
||||
$env:Path += ";$(Split-Path $path)"
|
||||
$cmakePath = Get-Command cmake -ErrorAction SilentlyContinue
|
||||
if ($cmakePath) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (-not $cmakePath) {
|
||||
Write-Host "CMake not found in PATH. Attempting to install..." -ForegroundColor Yellow
|
||||
|
||||
# Try to install CMake via Chocolatey
|
||||
if (Get-Command choco -ErrorAction SilentlyContinue) {
|
||||
Write-Host "Installing CMake via Chocolatey..." -ForegroundColor Yellow
|
||||
choco install -y cmake
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
Write-Host "CMake installed successfully" -ForegroundColor Green
|
||||
# Refresh PATH
|
||||
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
|
||||
} else {
|
||||
Write-Host "Failed to install CMake via Chocolatey" -ForegroundColor Red
|
||||
}
|
||||
} else {
|
||||
Write-Host "Chocolatey not found. Please install CMake manually:" -ForegroundColor Red
|
||||
Write-Host "1. Download from: https://cmake.org/download/" -ForegroundColor Yellow
|
||||
Write-Host "2. Or install Chocolatey first: https://chocolatey.org/install" -ForegroundColor Yellow
|
||||
Write-Host "3. Then run: choco install cmake" -ForegroundColor Yellow
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Check again after installation
|
||||
$cmakePath = Get-Command cmake -ErrorAction SilentlyContinue
|
||||
if (-not $cmakePath) {
|
||||
Write-Host "CMake still not found after installation. Please restart your terminal or add CMake to PATH manually." -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "CMake found: $($cmakePath.Source)" -ForegroundColor Green
|
||||
|
||||
# Check if Visual Studio is available
|
||||
$vsWhere = Get-Command "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -ErrorAction SilentlyContinue
|
||||
if (-not $vsWhere) {
|
||||
$vsWhere = Get-Command vswhere -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
if ($vsWhere) {
|
||||
$vsInstallPath = & $vsWhere.Source -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
|
||||
if ($vsInstallPath) {
|
||||
Write-Host "Visual Studio found at: $vsInstallPath" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "Visual Studio 2022 not found. Please install Visual Studio 2022 with C++ workload." -ForegroundColor Yellow
|
||||
}
|
||||
} else {
|
||||
Write-Host "vswhere not found. Assuming Visual Studio is available." -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
# Set up paths
|
||||
$SourceDir = Split-Path -Parent $PSScriptRoot
|
||||
$BuildDir = Join-Path $SourceDir "build-vs"
|
||||
|
||||
177
scripts/setup-windows-dev.bat
Normal file
177
scripts/setup-windows-dev.bat
Normal file
@@ -0,0 +1,177 @@
|
||||
@echo off
|
||||
REM Setup script for Windows development environment
|
||||
REM This script installs the necessary tools for YAZE development on Windows
|
||||
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
set FORCE=false
|
||||
|
||||
REM Parse command line arguments
|
||||
:parse_args
|
||||
if "%~1"=="" goto :args_done
|
||||
if "%~1"=="--force" set FORCE=true
|
||||
shift
|
||||
goto :parse_args
|
||||
|
||||
:args_done
|
||||
|
||||
echo Setting up Windows development environment for YAZE...
|
||||
|
||||
REM Check if we're on Windows
|
||||
if not "%OS%"=="Windows_NT" (
|
||||
echo This script is designed for Windows only.
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM Check if running as administrator
|
||||
net session >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo This script requires administrator privileges to install software.
|
||||
echo Please run Command Prompt as Administrator and try again.
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM Install Chocolatey if not present
|
||||
where choco >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo Installing Chocolatey package manager...
|
||||
powershell -Command "Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))"
|
||||
|
||||
REM Refresh environment variables
|
||||
call refreshenv
|
||||
|
||||
echo Chocolatey installed successfully
|
||||
) else (
|
||||
echo Chocolatey already installed
|
||||
)
|
||||
|
||||
REM Install required tools
|
||||
echo.
|
||||
echo Installing required development tools...
|
||||
|
||||
REM CMake
|
||||
where cmake >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo Installing CMake...
|
||||
choco install -y cmake
|
||||
if errorlevel 1 (
|
||||
echo Failed to install CMake
|
||||
) else (
|
||||
echo CMake installed successfully
|
||||
)
|
||||
) else (
|
||||
echo CMake already installed
|
||||
)
|
||||
|
||||
REM Git
|
||||
where git >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo Installing Git...
|
||||
choco install -y git
|
||||
if errorlevel 1 (
|
||||
echo Failed to install Git
|
||||
) else (
|
||||
echo Git installed successfully
|
||||
)
|
||||
) else (
|
||||
echo Git already installed
|
||||
)
|
||||
|
||||
REM Ninja
|
||||
where ninja >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo Installing Ninja...
|
||||
choco install -y ninja
|
||||
if errorlevel 1 (
|
||||
echo Failed to install Ninja
|
||||
) else (
|
||||
echo Ninja installed successfully
|
||||
)
|
||||
) else (
|
||||
echo Ninja already installed
|
||||
)
|
||||
|
||||
REM Python 3
|
||||
where python3 >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo Installing Python 3...
|
||||
choco install -y python3
|
||||
if errorlevel 1 (
|
||||
echo Failed to install Python 3
|
||||
) else (
|
||||
echo Python 3 installed successfully
|
||||
)
|
||||
) else (
|
||||
echo Python 3 already installed
|
||||
)
|
||||
|
||||
REM Refresh environment variables
|
||||
call refreshenv
|
||||
|
||||
REM Verify installations
|
||||
echo.
|
||||
echo Verifying installations...
|
||||
|
||||
where cmake >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo ✗ CMake not found
|
||||
) else (
|
||||
echo ✓ CMake found
|
||||
)
|
||||
|
||||
where git >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo ✗ Git not found
|
||||
) else (
|
||||
echo ✓ Git found
|
||||
)
|
||||
|
||||
where ninja >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo ✗ Ninja not found
|
||||
) else (
|
||||
echo ✓ Ninja found
|
||||
)
|
||||
|
||||
where python3 >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo ✗ Python 3 not found
|
||||
) else (
|
||||
echo ✓ Python 3 found
|
||||
)
|
||||
|
||||
REM Check for Visual Studio
|
||||
echo.
|
||||
echo Checking for Visual Studio...
|
||||
where vswhere >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
if exist "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" (
|
||||
set VSWHERE="C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe"
|
||||
) else (
|
||||
echo ✗ vswhere not found - cannot detect Visual Studio
|
||||
goto :setup_complete
|
||||
)
|
||||
) else (
|
||||
set VSWHERE=vswhere
|
||||
)
|
||||
|
||||
%VSWHERE% -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo ✗ Visual Studio 2022 with C++ workload not found
|
||||
echo Please install Visual Studio 2022 with the 'Desktop development with C++' workload
|
||||
) else (
|
||||
echo ✓ Visual Studio found
|
||||
)
|
||||
|
||||
:setup_complete
|
||||
echo.
|
||||
echo 🎉 Windows development environment setup complete!
|
||||
echo.
|
||||
echo Next steps:
|
||||
echo 1. Run the Visual Studio project generation script:
|
||||
echo .\scripts\generate-vs-projects.bat
|
||||
echo 2. Or use CMake presets:
|
||||
echo cmake --preset windows-debug
|
||||
echo 3. Open YAZE.sln in Visual Studio and build
|
||||
|
||||
pause
|
||||
115
scripts/setup-windows-dev.ps1
Normal file
115
scripts/setup-windows-dev.ps1
Normal file
@@ -0,0 +1,115 @@
|
||||
# Setup script for Windows development environment
|
||||
# This script installs the necessary tools for YAZE development on Windows
|
||||
|
||||
param(
|
||||
[switch]$Force = $false
|
||||
)
|
||||
|
||||
Write-Host "Setting up Windows development environment for YAZE..." -ForegroundColor Green
|
||||
|
||||
# Check if we're on Windows
|
||||
if ($env:OS -ne "Windows_NT") {
|
||||
Write-Host "This script is designed for Windows only." -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Check if running as administrator
|
||||
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
|
||||
if (-not $isAdmin) {
|
||||
Write-Host "This script requires administrator privileges to install software." -ForegroundColor Yellow
|
||||
Write-Host "Please run PowerShell as Administrator and try again." -ForegroundColor Yellow
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Install Chocolatey if not present
|
||||
if (-not (Get-Command choco -ErrorAction SilentlyContinue)) {
|
||||
Write-Host "Installing Chocolatey package manager..." -ForegroundColor Yellow
|
||||
Set-ExecutionPolicy Bypass -Scope Process -Force
|
||||
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
|
||||
iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
|
||||
|
||||
# Refresh environment variables
|
||||
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
|
||||
|
||||
Write-Host "Chocolatey installed successfully" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "Chocolatey already installed" -ForegroundColor Green
|
||||
}
|
||||
|
||||
# Install required tools
|
||||
$tools = @(
|
||||
@{Name="cmake"; Description="CMake build system"},
|
||||
@{Name="git"; Description="Git version control"},
|
||||
@{Name="ninja"; Description="Ninja build system"},
|
||||
@{Name="python3"; Description="Python 3 for scripts"}
|
||||
)
|
||||
|
||||
foreach ($tool in $tools) {
|
||||
Write-Host "Checking $($tool.Description)..." -ForegroundColor Cyan
|
||||
|
||||
$installed = $false
|
||||
if ($tool.Name -eq "cmake") {
|
||||
$installed = Get-Command cmake -ErrorAction SilentlyContinue
|
||||
} elseif ($tool.Name -eq "git") {
|
||||
$installed = Get-Command git -ErrorAction SilentlyContinue
|
||||
} elseif ($tool.Name -eq "ninja") {
|
||||
$installed = Get-Command ninja -ErrorAction SilentlyContinue
|
||||
} elseif ($tool.Name -eq "python3") {
|
||||
$installed = Get-Command python3 -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
if (-not $installed -or $Force) {
|
||||
Write-Host "Installing $($tool.Description)..." -ForegroundColor Yellow
|
||||
choco install -y $tool.Name
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
Write-Host "$($tool.Description) installed successfully" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "Failed to install $($tool.Description)" -ForegroundColor Red
|
||||
}
|
||||
} else {
|
||||
Write-Host "$($tool.Description) already installed" -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
|
||||
# Refresh environment variables
|
||||
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
|
||||
|
||||
# Verify installations
|
||||
Write-Host "`nVerifying installations..." -ForegroundColor Cyan
|
||||
|
||||
$toolsToVerify = @("cmake", "git", "ninja", "python3")
|
||||
foreach ($tool in $toolsToVerify) {
|
||||
$path = Get-Command $tool -ErrorAction SilentlyContinue
|
||||
if ($path) {
|
||||
Write-Host "✓ $tool found at: $($path.Source)" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "✗ $tool not found" -ForegroundColor Red
|
||||
}
|
||||
}
|
||||
|
||||
# Check for Visual Studio
|
||||
Write-Host "`nChecking for Visual Studio..." -ForegroundColor Cyan
|
||||
$vsWhere = Get-Command "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -ErrorAction SilentlyContinue
|
||||
if (-not $vsWhere) {
|
||||
$vsWhere = Get-Command vswhere -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
if ($vsWhere) {
|
||||
$vsInstallPath = & $vsWhere.Source -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
|
||||
if ($vsInstallPath) {
|
||||
Write-Host "✓ Visual Studio found at: $vsInstallPath" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "✗ Visual Studio 2022 with C++ workload not found" -ForegroundColor Red
|
||||
Write-Host "Please install Visual Studio 2022 with the 'Desktop development with C++' workload" -ForegroundColor Yellow
|
||||
}
|
||||
} else {
|
||||
Write-Host "✗ vswhere not found - cannot detect Visual Studio" -ForegroundColor Red
|
||||
}
|
||||
|
||||
Write-Host "`n🎉 Windows development environment setup complete!" -ForegroundColor Green
|
||||
Write-Host "`nNext steps:" -ForegroundColor Cyan
|
||||
Write-Host "1. Run the Visual Studio project generation script:" -ForegroundColor White
|
||||
Write-Host " .\scripts\generate-vs-projects.ps1" -ForegroundColor Gray
|
||||
Write-Host "2. Or use CMake presets:" -ForegroundColor White
|
||||
Write-Host " cmake --preset windows-debug" -ForegroundColor Gray
|
||||
Write-Host "3. Open YAZE.sln in Visual Studio and build" -ForegroundColor White
|
||||
Reference in New Issue
Block a user