diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 5fdc60a..945d463 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -58,25 +58,29 @@ jobs: with: os_name: ${{ matrix.os }} - - name: Configure msvc for amd64 - if: startsWith(matrix.os, 'windows') - uses: ilammy/msvc-dev-cmd@v1 - with: - arch: amd64 - - name: Configure windows + - name: Configure and build windows if: startsWith(matrix.os, 'windows') + shell: pwsh + run: | + .\scripts\windows\setVsDev.ps1 + cmake ` + -S . ` + -B ./build ` + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} ` + -G "${{ matrix.generators }}" + cmake --build ./build --config ${{ matrix.build_type }} + - name: Configure and build ubuntu + if: startsWith(matrix.os, 'ubuntu') shell: bash run: | cmake \ -S . \ -B ./build \ - -DCMAKE_C_COMPILER=cl \ - -DCMAKE_CXX_COMPILER=cl \ -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ - -G "${{ matrix.generators }}" \ - -DCMAKE_INSTALL_PREFIX:PATH=instdir - - name: Configure macos or ubuntu - if: startsWith(matrix.os, 'macos') || startsWith(matrix.os, 'ubuntu') + -G "${{ matrix.generators }}" + cmake --build ./build --config ${{ matrix.build_type }} + - name: Configure and build macos + if: startsWith(matrix.os, 'macos') shell: bash run: | cmake \ @@ -84,12 +88,7 @@ jobs: -B ./build \ -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ -DCMAKE_OSX_ARCHITECTURES="${{ matrix.arch }}" \ - -G "${{ matrix.generators }}" \ - -DCMAKE_INSTALL_PREFIX:PATH=instdir - - - name: Build - shell: bash - run: | + -G "${{ matrix.generators }}" cmake --build ./build --config ${{ matrix.build_type }} - name: Deploy windows diff --git a/.github/workflows/delete_workflow.yml b/.github/workflows/delete_workflow.yml index 7fcd036..9c96ce6 100644 --- a/.github/workflows/delete_workflow.yml +++ b/.github/workflows/delete_workflow.yml @@ -27,7 +27,7 @@ on: delete_run_by_conclusion_pattern: description: 'Remove runs based on conclusion: action_required, cancelled, failure, skipped, success' required: true - default: "Unsuccessful" + default: "Unsuccessful: action_required,cancelled,failure,skipped" type: choice options: - "ALL" diff --git a/.github/workflows/qmake.yml b/.github/workflows/qmake.yml index a1e35ef..8f07769 100644 --- a/.github/workflows/qmake.yml +++ b/.github/workflows/qmake.yml @@ -63,11 +63,11 @@ jobs: - name: msvc-build if: startsWith(matrix.os, 'windows') - shell: cmd + shell: pwsh run: | - call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64 - qmake ./../. - .\..\jom\jom.exe + ..\scripts\windows\setVsDev.ps1 -VersionRange "[16.0,17.0)" -Arch "x64" + & qmake ./../. + & .\..\jom\jom.exe working-directory: build - name: ubuntu-build if: startsWith(matrix.os, 'ubuntu') diff --git a/scripts/windows/setVsDev.ps1 b/scripts/windows/setVsDev.ps1 new file mode 100644 index 0000000..c7928f7 --- /dev/null +++ b/scripts/windows/setVsDev.ps1 @@ -0,0 +1,62 @@ +param( + [Parameter(Mandatory = $false)] + [string]$VersionRange, + [Parameter(Mandatory = $false)] + [string]$Arch +) + + +$vswhereArgs = @() + +if ($VersionRange) { + $vswhereArgs += "-version" + $vswhereArgs += $VersionRange +} +else { + $vswhereArgs += "-latest" +} + + +$vswhereArgs += "-property" +$vswhereArgs += "installationPath" + +if ([string]::IsNullOrEmpty($Arch)) { + $Arch = "x64" +} + +Write-Host "Architecture: $Arch" +Write-Host "VSWhere Args: $vswhereArgs" + +# 使用 vswhere 获取 Visual Studio 的安装路径 +$vswherePath = "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" +$vsInstallPath = & $vswherePath $vswhereArgs | ForEach-Object { $_ } +# Output the results +Write-Host "Visual Studio installation paths:" +$vsInstallPath + +if ($null -ne $vsInstallPath) { + $vsDevShell = Join-Path $vsInstallPath "Common7\Tools\Microsoft.VisualStudio.DevShell.dll" + if (-not (Test-Path $vsDevShell)) { + Write-Host "Failed to find Visual Studio DevShell DLL: $vsDevShell" + exit 1 + } + Import-Module $vsDevShell + Enter-VsDevShell -VsInstallPath $vsInstallPath -DevCmdArguments "-arch=$Arch -host_arch=$Arch" -SkipAutomaticLocation + + if ($LASTEXITCODE -eq 0) { + Write-Host "Development environment set up successfully." + } + else { + Write-Host "Failed to set up the development environment." + } +} +else { + Write-Host "Using Custom Visual Studio installation path." + $vsInstallPath = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise" + if (-not (Test-Path $vsInstallPath)) { + $vsInstallPath = "C:\Program Files (x86)\Microsoft Visual Studio\2022\Enterprise" + } + $vsDevShell = Join-Path $vsInstallPath "Common7\Tools\Microsoft.VisualStudio.DevShell.dll" + Import-Module $vsDevShell + Enter-VsDevShell -VsInstallPath $vsInstallPath -DevCmdArguments "-arch=x64 -host_arch=x64" -SkipAutomaticLocation +} \ No newline at end of file