From 731e4f27b42917e836eddfbf0a060a35cbca77b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=AD=90=E6=A5=9A=5Czhuzi?= Date: Mon, 3 Apr 2023 20:04:46 +0800 Subject: [PATCH] update --- .github/workflows/windows-mingw.yml | 77 +++++++++++++++++++++++++++++ example/CMakeLists.txt | 6 +-- example/example.pro | 12 +---- scripts/windows-mingw-publish.ps1 | 34 +++++++++++++ 4 files changed, 114 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/windows-mingw.yml create mode 100644 scripts/windows-mingw-publish.ps1 diff --git a/.github/workflows/windows-mingw.yml b/.github/workflows/windows-mingw.yml new file mode 100644 index 00000000..145112ad --- /dev/null +++ b/.github/workflows/windows-mingw.yml @@ -0,0 +1,77 @@ +name: Windows MinGW +on: + push: + paths: + - '*.pro' + - 'src/**' + - '.github/workflows/windows-mingw.yml' + pull_request: + paths: + - '*.pro' + - 'src/**' + - '.github/workflows/windows-mingw.yml' +jobs: + build: + name: Build + runs-on: windows-2019 + strategy: + matrix: + include: + - qt_arch: win64_mingw + qt_ver: 6.4.3 + qt_tools: "tools_mingw,9.0.0-1-202203221220,qt.tools.win64_mingw900" + qt_tools_mingw_install: mingw900_64 + env: + targetName: example.exe + fileName: example + steps: + - name: Install Qt + # 使用外部action。这个action专门用来安装Qt + uses: jurplel/install-qt-action@v3 + with: + version: ${{ matrix.qt_ver }} + arch: ${{ matrix.qt_arch }} + cache: ${{steps.cache-qt.outputs.cache-hit}} + modules: 'qt5compat qtmultimedia qtshadertools qtimageformats' + - uses: actions/checkout@v2 + with: + fetch-depth: 1 + - name: Qt 6 environment configuration + if: ${{ startsWith( matrix.qt_ver, 6 ) }} + shell: pwsh + run: | + Write-Output "${{ env.Qt6_DIR }}/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + Write-Output "${{ env.Qt6_DIR }}/../../Tools/${{ matrix.qt_tools_mingw_install }}/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + - name: where is qmake & where is mingw32-make + shell: pwsh + run: | + Get-Command -Name 'qmake' | Format-List + Get-Command -Name 'mingw32-make' | Format-List + - name: mingw-build + id: build + shell: cmd + run: | + qmake + mingw32-make + - name: package + id: package + env: + archiveName: ${{ env.fileName }}-${{ matrix.qt_arch }}-${{ matrix.qt_ver }} + shell: pwsh + run: | + & scripts\windows-mingw-publish.ps1 ${env:archiveName} ${env:targetName} + $name = ${env:archiveName} + echo "::set-output name=packageName::$name" + - uses: actions/upload-artifact@v2 + with: + name: ${{ steps.package.outputs.packageName }} + path: ${{ steps.package.outputs.packageName }} + - name: uploadRelease + if: startsWith(github.event.ref, 'refs/tags/') + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: ${{ steps.package.outputs.packageName }}.zip + asset_name: ${{ env.fileName }}_${{ github.ref_name }}_${{ matrix.os }}_Qt${{ matrix.qt_ver }}.zip + tag: ${{ github.ref }} + overwrite: true \ No newline at end of file diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index d41ac6df..8b1bafca 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -34,11 +34,7 @@ if(WIN32) else() set(COPYDLL ${CMAKE_CURRENT_SOURCE_DIR}/../third/Win_x64/*.dll ${DESTDIR}) endif() - if(QMAKE_CC STREQUAL "cl") - set(QMAKE_PRE_LINK "${QMAKE_COPY} ${COPYDLL}") - else() - set(QMAKE_PRE_LINK "${QMAKE_COPY} ${COPYDLL}") - endif() + set(QMAKE_PRE_LINK "${QMAKE_COPY} ${COPYDLL}") endif() add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS} ${QT_RESOURCES} ${RC_ICONS}) diff --git a/example/example.pro b/example/example.pro index 5bdb77ad..be84c3f3 100644 --- a/example/example.pro +++ b/example/example.pro @@ -25,18 +25,10 @@ CONFIG(debug,debug|release) { win32 { contains(QT_ARCH, i386) { COPYDLL = $$absolute_path($${_PRO_FILE_PWD_}/../third/Win_x86/*.dll) $$DESTDIR - contains(QMAKE_CC, cl) { - QMAKE_PRE_LINK += $$QMAKE_COPY $$replace(COPYDLL, /, \\) - } else { - QMAKE_PRE_LINK += $$QMAKE_COPY $$COPYDLL - } + QMAKE_PRE_LINK += $$QMAKE_COPY $$replace(COPYDLL, /, \\) } else { COPYDLL = $$absolute_path($${_PRO_FILE_PWD_}/../third/Win_x64/*.dll) $$DESTDIR - contains(QMAKE_CC, cl) { - QMAKE_PRE_LINK += $$QMAKE_COPY $$replace(COPYDLL, /, \\) - } else { - QMAKE_PRE_LINK += $$QMAKE_COPY $$COPYDLL - } + QMAKE_PRE_LINK += $$QMAKE_COPY $$replace(COPYDLL, /, \\) } } diff --git a/scripts/windows-mingw-publish.ps1 b/scripts/windows-mingw-publish.ps1 new file mode 100644 index 00000000..d1c8fae8 --- /dev/null +++ b/scripts/windows-mingw-publish.ps1 @@ -0,0 +1,34 @@ +[CmdletBinding()] +param ( + [string] $archiveName, [string] $targetName +) +# 外部环境变量包括: +# archiveName: ${{ matrix.qt_ver }}-${{ matrix.qt_arch }} + + +# archiveName: 5.15.2-win64_mingw81 + +$scriptDir = $PSScriptRoot +$currentDir = Get-Location +Write-Host "currentDir" $currentDir +Write-Host "scriptDir" $scriptDir + +function Main() { + + New-Item -ItemType Directory $archiveName + # 拷贝exe + Copy-Item bin\release\* $archiveName\ + # 拷贝依赖 + windeployqt --qmldir . --plugindir $archiveName\plugins --no-translations --compiler-runtime $archiveName\$targetName + # 删除不必要的文件 + $excludeList = @("*.qmlc", "*.ilk", "*.exp", "*.lib", "*.pdb") + Remove-Item -Path $archiveName -Include $excludeList -Recurse -Force + # 打包zip + Compress-Archive -Path $archiveName $archiveName'.zip' +} + +if ($null -eq $archiveName || $null -eq $targetName) { + Write-Host "args missing, archiveName is" $archiveName ", targetName is" $targetName + return +} +Main