| 1 |
# Copyright 2019-2022, Mesa contributors |
| 2 |
# Copyright 2022, Collabora, Ltd. |
| 3 |
# SPDX-License-Identifier: MIT |
| 4 |
# Based on https://gitlab.freedesktop.org/mesa/mesa/-/blob/8396df5ad90aeb6ab2267811aba2187954562f81/.gitlab-ci/windows/mesa_build.ps1 |
| 5 |
|
| 6 |
[CmdletBinding()] |
| 7 |
param ( |
| 8 |
# Should we install the project? |
| 9 |
[Parameter()] |
| 10 |
[switch] |
| 11 |
$Install = $false, |
| 12 |
|
| 13 |
# Should we package the project? |
| 14 |
[Parameter()] |
| 15 |
[switch] |
| 16 |
$Package = $false, |
| 17 |
|
| 18 |
# Should we run the test suite? |
| 19 |
[Parameter()] |
| 20 |
[switch] |
| 21 |
$RunTests = $false |
| 22 |
) |
| 23 |
$ErrorActionPreference = 'Stop' |
| 24 |
|
| 25 |
$env:PYTHONUTF8 = 1 |
| 26 |
|
| 27 |
Get-Date |
| 28 |
Write-Host "Compiling Monado" |
| 29 |
$sourcedir = (Resolve-Path "$PSScriptRoot/../..") |
| 30 |
$builddir = Join-Path $sourcedir "build" |
| 31 |
$installdir = Join-Path $sourcedir "install" |
| 32 |
$vcpkgdir = "c:\vcpkg" |
| 33 |
$toolchainfile = Join-Path $vcpkgdir "scripts/buildsystems/vcpkg.cmake" |
| 34 |
|
| 35 |
Remove-Item -Recurse -Force $installdir -ErrorAction SilentlyContinue |
| 36 |
|
| 37 |
Write-Output "builddir:$builddir" |
| 38 |
Write-Output "installdir:$installdir" |
| 39 |
Write-Output "sourcedir:$sourcedir" |
| 40 |
Write-Output "toolchainfile:$toolchainfile" |
| 41 |
|
| 42 |
# $installPath = & "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -version 17 -property installationpath |
| 43 |
# Write-Information "vswhere.exe installPath: $installPath" |
| 44 |
# if (!$installPath) { |
| 45 |
# throw "Could not find VS2022 using vswhere!" |
| 46 |
# } |
| 47 |
$installPath = "C:\BuildTools" |
| 48 |
Write-Output "installPath: $installPath" |
| 49 |
|
| 50 |
# We have to clear this because some characters in a commit message may confuse cmd/Enter-VsDevShell. |
| 51 |
$env:CI_COMMIT_DESCRIPTION = "" |
| 52 |
$env:CI_COMMIT_MESSAGE = "" |
| 53 |
|
| 54 |
Import-Module (Join-Path $installPath "Common7\Tools\Microsoft.VisualStudio.DevShell.dll") |
| 55 |
Enter-VsDevShell -VsInstallPath $installPath -SkipAutomaticLocation -DevCmdArguments '-arch=x64 -no_logo -host_arch=amd64' |
| 56 |
|
| 57 |
$ErrorActionPreference = 'Stop' |
| 58 |
Push-Location $sourcedir |
| 59 |
|
| 60 |
$cmakeArgs = @( |
| 61 |
"-S" |
| 62 |
"." |
| 63 |
"-B" |
| 64 |
"$builddir" |
| 65 |
"-GNinja" |
| 66 |
"-DCMAKE_BUILD_TYPE=RelWithDebInfo" |
| 67 |
"-DCMAKE_TOOLCHAIN_FILE=$toolchainfile" |
| 68 |
"-DCMAKE_INSTALL_PREFIX=$installdir" |
| 69 |
"-DX_VCPKG_APPLOCAL_DEPS_INSTALL=ON" |
| 70 |
) |
| 71 |
cmake @cmakeArgs |
| 72 |
if (!$?) { |
| 73 |
throw "cmake generate failed!" |
| 74 |
} |
| 75 |
|
| 76 |
Write-Information "Building" |
| 77 |
cmake --build $builddir |
| 78 |
if (!$?) { |
| 79 |
throw "cmake build failed!" |
| 80 |
} |
| 81 |
|
| 82 |
if ($RunTests) { |
| 83 |
Write-Information "Running tests" |
| 84 |
cmake --build $builddir --target test |
| 85 |
|
| 86 |
} |
| 87 |
|
| 88 |
if ($Install) { |
| 89 |
Write-Information "Installing" |
| 90 |
cmake --build $builddir --target install |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
if ($Package) { |
| 95 |
Write-Information "Packaging" |
| 96 |
cmake --build $builddir --target package |
| 97 |
} |