|
28 | 28 | - uses: actions/checkout@v4 |
29 | 29 | with: |
30 | 30 | persist-credentials: false |
| 31 | + - name: Select Visual Studio generator |
| 32 | + id: vs_generator |
| 33 | + shell: pwsh |
| 34 | + run: | |
| 35 | + $ErrorActionPreference = "Stop" |
| 36 | +
|
| 37 | + $vswhere = Join-Path ${env:ProgramFiles(x86)} "Microsoft Visual Studio\Installer\vswhere.exe" |
| 38 | + $vsInstances = & $vswhere -latest -products * -format json | ConvertFrom-Json |
| 39 | + $vsInstance = @($vsInstances)[0] |
| 40 | + if ($null -eq $vsInstance) { |
| 41 | + Write-Error "No Visual Studio installation was found." |
| 42 | + exit 1 |
| 43 | + } |
| 44 | +
|
| 45 | + $vsVersion = [string]$vsInstance.installationVersion |
| 46 | + if ([string]::IsNullOrWhiteSpace($vsVersion)) { |
| 47 | + Write-Error "Visual Studio installation did not report a version." |
| 48 | + exit 1 |
| 49 | + } |
| 50 | +
|
| 51 | + $vcToolsVersionFile = Join-Path $vsInstance.installationPath "VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt" |
| 52 | + if (-not (Test-Path $vcToolsVersionFile)) { |
| 53 | + Write-Error "Visual Studio was found, but C++ tools were not found at $vcToolsVersionFile." |
| 54 | + exit 1 |
| 55 | + } |
| 56 | +
|
| 57 | + $major = [int]($vsVersion.Split(".")[0]) |
| 58 | + if ($major -ge 18) { |
| 59 | + $generator = "Visual Studio 18 2026" |
| 60 | + } elseif ($major -eq 17) { |
| 61 | + $generator = "Visual Studio 17 2022" |
| 62 | + } else { |
| 63 | + Write-Error "Unsupported Visual Studio version: $vsVersion" |
| 64 | + exit 1 |
| 65 | + } |
| 66 | +
|
| 67 | + $cmake = Get-Command cmake -ErrorAction SilentlyContinue |
| 68 | + if ($null -eq $cmake) { |
| 69 | + Write-Error "CMake was not found on PATH." |
| 70 | + exit 1 |
| 71 | + } |
| 72 | +
|
| 73 | + $cmakeHelp = & $cmake.Source --help | Out-String |
| 74 | + if (-not $cmakeHelp.Contains($generator)) { |
| 75 | + Write-Error "The installed CMake does not support the '$generator' generator." |
| 76 | + exit 1 |
| 77 | + } |
| 78 | +
|
| 79 | + "cmake_generator=$generator" | Out-File -FilePath $env:GITHUB_OUTPUT -Append |
| 80 | + "vs_major=$major" | Out-File -FilePath $env:GITHUB_OUTPUT -Append |
| 81 | + Write-Host "Using CMake generator: $generator" |
31 | 82 | - name: Cache vcpkg |
32 | 83 | uses: actions/cache@v4 |
33 | 84 | with: |
|
37 | 88 | C:\vcpkg\buildtrees |
38 | 89 | C:\vcpkg\packages |
39 | 90 | C:\vcpkg\binarycache |
40 | | - key: ${{ runner.os }}-${{ matrix.arch }}-vcpkg-${{ hashFiles('vcpkg.json', 'vcpkg-configuration.json') }} |
| 91 | + key: ${{ runner.os }}-${{ matrix.arch }}-vs${{ steps.vs_generator.outputs.vs_major }}-vcpkg-${{ hashFiles('vcpkg.json', 'vcpkg-configuration.json') }} |
41 | 92 | - name: Install FFmpeg (vcpkg) |
42 | 93 | shell: pwsh |
43 | 94 | run: | |
|
54 | 105 | uses: actions/cache@v4 |
55 | 106 | with: |
56 | 107 | path: Projects/VS/_deps |
57 | | - key: ${{ runner.os }}-${{ matrix.arch }}-cmake-deps-${{ hashFiles('CMakeLists.txt') }} |
| 108 | + key: ${{ runner.os }}-${{ matrix.arch }}-vs${{ steps.vs_generator.outputs.vs_major }}-cmake-deps-${{ hashFiles('CMakeLists.txt') }} |
58 | 109 | - name: Configure |
59 | | - run: cmake -S . -B Projects/VS -G "Visual Studio 17 2022" -A ${{ matrix.cmake_platform }} ${{ matrix.cmake_extra_args }} -DOPENFODDER_ENABLE_FFMPEG=ON -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=${{ matrix.vcpkg_triplet }} |
| 110 | + run: cmake -S . -B Projects/VS -G "${{ steps.vs_generator.outputs.cmake_generator }}" -A ${{ matrix.cmake_platform }} ${{ matrix.cmake_extra_args }} -DOPENFODDER_ENABLE_FFMPEG=ON -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=${{ matrix.vcpkg_triplet }} |
60 | 111 | - name: Build |
61 | 112 | run: cmake --build Projects/VS --config ${{ matrix.configuration }} |
62 | 113 | - name: Test |
|
0 commit comments