From 8845a23d5d6c5f3a2eba14b12585931f90153102 Mon Sep 17 00:00:00 2001 From: Joel Bethke Date: Mon, 30 Nov 2020 22:54:50 -0600 Subject: [PATCH] CI: Fix up Windows builds and add GitHub Actions for Windows (#4193) * ci: Add vcpkg submodule * cmake: Fix NSIS not detecting platform arch * cmake: Add QTDIR(64|32) This change adds a new var for QTDIR(32|64) which makes it easier to specify a specific directory for Qt, rather than having to edit the prefix path directly, which can get pretty messy. Functionally, this shouldn't affect any builds that are already finding Qt as part of path, and should not affect Linux/macOS. * cmake: Bump min cmake version * ci: Add GitHub Actions for Windows --- .github/workflows/windows-builds.yml | 214 +++++++++++++++++++++++++++ .gitmodules | 3 + CMakeLists.txt | 38 +++-- vcpkg | 1 + vcpkg.txt | 4 + 5 files changed, 248 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/windows-builds.yml create mode 100644 .gitmodules create mode 160000 vcpkg create mode 100644 vcpkg.txt diff --git a/.github/workflows/windows-builds.yml b/.github/workflows/windows-builds.yml new file mode 100644 index 00000000..9b394cf2 --- /dev/null +++ b/.github/workflows/windows-builds.yml @@ -0,0 +1,214 @@ +name: 'Build on Windows' + +on: + push: + branches: + - master + paths-ignore: + - '**.md' + tags: + - '*' + pull_request: + branches: + - master + paths-ignore: + - '**.md' + +jobs: + win64: + name: 'Windows 64-bit' + runs-on: [windows-latest] + env: + QT_VERSION: '5.12.9' + CMAKE_GENERATOR: "Visual Studio 16 2019" + steps: + - name: 'Add msbuild to PATH' + uses: microsoft/setup-msbuild@v1.0.2 + - name: 'Checkout' + uses: actions/checkout@v2 + with: + submodules: 'recursive' + - name: 'Get Cockatrice git info' + shell: bash + working-directory: ${{ github.workspace }} + run: | + git fetch --prune --unshallow + echo "GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_ENV + echo "GIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV + echo "GIT_TAG=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV + - name: 'Restore Qt 64-bit from cache' + id: cache-qt32 + uses: actions/cache@v2 + with: + path: | + ${{ runner.workspace }}/Qt64 + key: ${{ runner.os }}-QtCache-64bit + - name: 'Install 64-bit Qt' + uses: jurplel/install-qt-action@v2 + with: + cached: ${{ steps.cache-qt.outputs.cache-hit }} + version: '${{ env.QT_VERSION }}' + arch: 'win64_msvc2017_64' + dir: ${{ runner.workspace }}/Qt64 + - name: 'Restore or setup vcpkg' + uses: lukka/run-vcpkg@v6 + with: + vcpkgArguments: '@${{ github.workspace }}/vcpkg.txt' + vcpkgDirectory: '${{ github.workspace }}/vcpkg' + appendedCacheKey: ${{ hashFiles('**/vcpkg.txt') }} + vcpkgTriplet: x64-windows + - name: 'Configure Cockatrice 64-bit' + working-directory: ${{ github.workspace }} + run: | + New-Item build64 -type directory -force + cd build64 + cmake .. -G "${{ env.CMAKE_GENERATOR }}" -A "x64" -DQTDIR="${{ runner.workspace }}\Qt64\Qt\5.12.9\msvc2017_64" -DCMAKE_BUILD_TYPE="Release" -DWITH_SERVER=1 -DTEST=t + - name: 'Build Cockatrice 64-bit' + working-directory: ${{ github.workspace }} + run: msbuild /m /p:Configuration=Release .\build64\Cockatrice.sln + - name: 'Build Cockatrice Installer Package 64-bit' + working-directory: ${{ github.workspace }} + run: | + cd build64 + msbuild /m /p:Configuration=Release PACKAGE.vcxproj + cp *.exe ../Cockatrice-${{ env.GIT_TAG }}-${{ env.GIT_HASH }}-64bit-installer.exe + - name: 'Run Tests' + working-directory: ${{ github.workspace }}/build64 + run: ctest -T Test -C Release + - name: 'Publish' + if: success() + uses: actions/upload-artifact@v2 + with: + name: 'Cockatrice-${{ env.GIT_TAG }}-64bit' + path: './*.exe' + win32: + name: 'Windows 32-bit' + runs-on: [windows-latest] + env: + QT_VERSION: '5.12.9' + CMAKE_GENERATOR: "Visual Studio 16 2019" + steps: + - name: 'Add msbuild to PATH' + uses: microsoft/setup-msbuild@v1.0.2 + - name: 'Checkout' + uses: actions/checkout@v2 + with: + submodules: 'recursive' + - name: 'Get Cockatrice git info' + shell: bash + working-directory: ${{ github.workspace }} + run: | + git fetch --prune --unshallow + echo "GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_ENV + echo "GIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV + echo "GIT_TAG=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV + - name: 'Restore Qt from cache' + id: cache-qt32 + uses: actions/cache@v2 + with: + path: | + ${{ runner.workspace }}/Qt32 + key: ${{ runner.os }}-QtCache-32bit + - name: 'Install 32-bit Qt' + uses: jurplel/install-qt-action@v2 + with: + cached: ${{ steps.cache-qt.outputs.cache-hit }} + version: '${{ env.QT_VERSION }}' + arch: 'win32_msvc2017' + dir: ${{ runner.workspace }}/Qt32 + - name: 'Restore or setup vcpkg' + uses: lukka/run-vcpkg@v6 + with: + vcpkgArguments: '@${{ github.workspace }}/vcpkg.txt' + vcpkgDirectory: '${{ github.workspace }}/vcpkg' + appendedCacheKey: ${{ hashFiles('**/vcpkg.txt') }} + vcpkgTriplet: x86-windows + - name: 'Configure Cockatrice 32-bit' + working-directory: ${{ github.workspace }} + run: | + New-Item build32 -type directory -force + cd build32 + cmake .. -G "${{ env.CMAKE_GENERATOR }}" -A "Win32" -DQTDIR="${{ runner.workspace }}\Qt32\Qt\5.12.9\msvc2017" -DCMAKE_BUILD_TYPE="Release" -DWITH_SERVER=1 -DTEST=1 + - name: 'Build Cockatrice 32-bit' + working-directory: ${{ github.workspace }} + run: msbuild /m /p:Configuration=Release .\build32\Cockatrice.sln + - name: 'Build Cockatrice Installer Package 32-bit' + working-directory: ${{ github.workspace }} + run: | + cd build32 + msbuild /m /p:Configuration=Release PACKAGE.vcxproj + cp *.exe ../Cockatrice-${{ env.GIT_TAG }}-${{ env.GIT_HASH }}-32bit-installer.exe + - name: 'Run Tests' + working-directory: ${{ github.workspace }}/build32 + run: ctest -T Test -C Release + - name: 'Publish' + if: success() + uses: actions/upload-artifact@v2 + with: + name: 'Cockatrice-${{ env.GIT_TAG }}-32bit' + path: './*.exe' + make-release: + name: 'Create and upload release' + runs-on: [ubuntu-latest] + if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') + needs: [win32,win64] + steps: + - name: 'Checkout' + uses: actions/checkout@v2 + with: + submodules: 'recursive' + - name: 'Fetch git tags and generate file name' + shell: bash + run: | + git fetch --prune --unshallow + echo "GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_ENV + echo "GIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV + echo "GIT_TAG=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV + - name: 'Checking if beta' + if: contains(env.GIT_TAG, 'beta') + shell: bash + run: | + echo 'IS_BETA=true' >> $GITHUB_ENV + - name: 'Checking if beta' + if: "!contains(env.GIT_TAG, 'beta')" + shell: bash + run: | + echo 'IS_BETA=false' >> $GITHUB_ENV + - name: 'Create Release' + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ env.GIT_TAG }} + release_name: Cockatrice ${{ env.GIT_TAG }} + draft: true + prerelease: ${{ env.IS_BETA }} + - name: 'Generate filenames' + shell: bash + run: | + FILE_NAME=Cockatrice-${{ env.GIT_TAG }}-${{ env.GIT_HASH }} + echo "FILE_NAME=${FILE_NAME}" >> $GITHUB_ENV + - name: 'Download artifacts' + uses: actions/download-artifact@v2 + with: + path: ./ + - name: 'Upload 32bit to release' + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./Cockatrice-${{ env.GIT_TAG }}-32bit/${{ env.FILE_NAME }}-32bit-installer.exe + asset_name: Cockatrice-${{ env.GIT_TAG }}-32bit-installer.exe + asset_content_type: application/octet-stream + - name: 'Upload 64bit to release' + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./Cockatrice-${{ env.GIT_TAG }}-64bit/${{ env.FILE_NAME }}-64bit-installer.exe + asset_name: Cockatrice-${{ env.GIT_TAG }}-64bit-installer.exe + asset_content_type: application/octet-stream + diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..a0a57f3d --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "vcpkg"] + path = vcpkg + url = https://github.com/microsoft/vcpkg.git diff --git a/CMakeLists.txt b/CMakeLists.txt index f4a678d3..ded6b956 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,15 +6,7 @@ # like the installation path, compilation flags etc.. # Cmake 3.1 is required to enable C++11 support correctly -cmake_minimum_required(VERSION 3.1) - -if(POLICY CMP0064) - cmake_policy(SET CMP0064 NEW) -endif() - -if(POLICY CMP0071) - cmake_policy(SET CMP0071 NEW) -endif() +cmake_minimum_required(VERSION 3.10) # Default to "Release" build type # User-provided value for CMAKE_BUILD_TYPE must be checked before the PROJECT() call @@ -35,6 +27,17 @@ if(USE_CCACHE) endif() endif() +if(WIN32) + # Use vcpkg toolchain on Windows + set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake + CACHE STRING "Vcpkg toolchain file") + # Qt path set by user or env var + if (QTDIR OR DEFINED ENV{QTDIR} OR DEFINED ENV{QTDIR32} OR DEFINED ENV{QTDIR64}) + else() + set(QTDIR "" CACHE PATH "Path to Qt (e.g. C:/Qt/5.7/msvc2015_64)") + message(WARNING "QTDIR variable is missing. Please set this variable to specify path to Qt (e.g. C:/Qt/5.7/msvc2015_64)") + endif() +endif() # A project name is needed for CPack # Version can be overriden by git tags, see cmake/getversion.cmake PROJECT("Cockatrice" VERSION 2.7.6) @@ -139,8 +142,15 @@ ENDIF() FIND_PACKAGE(Threads REQUIRED) # Find Qt5 -OPTION(UPDATE_TRANSLATIONS "Update translations on compile" OFF) -MESSAGE(STATUS "UPDATE TRANSLATIONS: ${UPDATE_TRANSLATIONS}") +if(DEFINED QTDIR${_lib_suffix}) + list(APPEND CMAKE_PREFIX_PATH "${QTDIR${_lib_suffix}}") +elseif(DEFINED QTDIR) + list(APPEND CMAKE_PREFIX_PATH "${QTDIR}") +elseif(DEFINED ENV{QTDIR${_lib_suffix}}) + list(APPEND CMAKE_PREFIX_PATH "$ENV{QTDIR${_lib_suffix}}") +elseif(DEFINED ENV{QTDIR}) + list(APPEND CMAKE_PREFIX_PATH "$ENV{QTDIR}") +endif() FIND_PACKAGE(Qt5Core 5.5.0 REQUIRED) @@ -161,6 +171,10 @@ ELSE() MESSAGE(FATAL_ERROR "No Qt5 found!") ENDIF() +# Check for translation updates +OPTION(UPDATE_TRANSLATIONS "Update translations on compile" OFF) +MESSAGE(STATUS "UPDATE TRANSLATIONS: ${UPDATE_TRANSLATIONS}") + set(CMAKE_AUTOMOC TRUE) # Find other needed libraries @@ -215,7 +229,7 @@ if(UNIX) endif() elseif(WIN32) set(CPACK_GENERATOR NSIS ${CPACK_GENERATOR}) - if("${CMAKE_GENERATOR}" MATCHES "(Win64|IA64)") + if("${CMAKE_GENERATOR_PLATFORM}" MATCHES "(x64)") set(TRICE_IS_64_BIT 1) else() set(TRICE_IS_64_BIT 0) diff --git a/vcpkg b/vcpkg new file mode 160000 index 00000000..62fe6ffb --- /dev/null +++ b/vcpkg @@ -0,0 +1 @@ +Subproject commit 62fe6ffbbbae9149fb8c48cde2a34b809e2a3008 diff --git a/vcpkg.txt b/vcpkg.txt new file mode 100644 index 00000000..359f420d --- /dev/null +++ b/vcpkg.txt @@ -0,0 +1,4 @@ +protobuf +liblzma +zlib +gtest \ No newline at end of file