From ececf337f2b0969e009943c0442b2e3f401cde96 Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Sat, 27 Jul 2024 17:22:35 +0200 Subject: [PATCH] Build Windows CI builds with vcpkg and Qt 6 (#2112) If using Qt 6 becomes a problem in terms of compatibility, toggle it off in the CMakePresets.json. --- .github/workflows/build-windows.yml | 38 +++++------- CMakePresets.json | 23 ++++++- cmake/ConfigureVcpkg.cmake | 18 +++++- .../x64-mingw-static-release.cmake | 7 +++ vcpkg.json | 62 ++++++++++++------- 5 files changed, 102 insertions(+), 46 deletions(-) create mode 100644 cmake/overlay-triplets/x64-mingw-static-release.cmake diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml index a4d84a1c..b224d62a 100644 --- a/.github/workflows/build-windows.yml +++ b/.github/workflows/build-windows.yml @@ -8,36 +8,30 @@ on: branches: - master -env: - BUILD_TYPE: Release - jobs: build: - runs-on: windows-latest - defaults: run: shell: msys2 {0} steps: - - uses: actions/checkout@v1 - - uses: msys2/setup-msys2@v2 + - name: Check out sources + uses: actions/checkout@v3 + - name: Set up MSYS2 + uses: msys2/setup-msys2@v2 with: - msystem: MINGW64 - update: true - - - name: Install dependencies - run: pacman -Sq --noconfirm git pkgconf mingw-w64-x86_64-{cmake,SDL2,qt5-static,libarchive,toolchain} - + msystem: ucrt64 + update: true + pacboy: gcc:p cmake:p ninja:p make:p + - name: Set up vcpkg + uses: lukka/run-vcpkg@v11 + with: + vcpkgGitCommitId: 53bef8994c541b6561884a8395ea35715ece75db - name: Configure - working-directory: ${{runner.workspace}} - run: cmake -B build $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_STATIC=ON -DCMAKE_PREFIX_PATH=C:/tools/msys64/mingw64/qt5-static - - - name: Make - working-directory: ${{runner.workspace}}/build - run: cmake --build . - - - uses: actions/upload-artifact@v1 + run: cmake --preset=release-mingw-x86_64 + - name: Build + run: cmake --build --preset=release-mingw-x86_64 + - uses: actions/upload-artifact@v4 with: name: melonDS-windows-x86_64 - path: ${{runner.workspace}}\build\melonDS.exe + path: .\build\release-mingw-x86_64\melonDS.exe diff --git a/CMakePresets.json b/CMakePresets.json index e14eda24..2144417b 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -20,6 +20,23 @@ } } }, + { + "name": "release-mingw-x86_64", + "inherits": "release-vcpkg", + "displayName": "Windows MinGW release (x86_64)", + "binaryDir": "${sourceDir}/build/release-mingw-x86_64", + "generator": "Ninja", + "cacheVariables": { + "USE_QT6": { + "type": "BOOL", + "value": "ON" + }, + "BUILD_STATIC": { + "type": "BOOL", + "value": "ON" + } + } + }, { "name": "release-mac-x86_64", "inherits": "release-vcpkg", @@ -44,6 +61,10 @@ "name": "release-vcpkg", "configurePreset": "release-vcpkg" }, + { + "name": "release-mingw-x86_64", + "configurePreset": "release-mingw-x86_64" + }, { "name": "release-mac-x86_64", "configurePreset": "release-mac-x86_64" @@ -85,4 +106,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/cmake/ConfigureVcpkg.cmake b/cmake/ConfigureVcpkg.cmake index c9f3e92f..c08e42cb 100644 --- a/cmake/ConfigureVcpkg.cmake +++ b/cmake/ConfigureVcpkg.cmake @@ -4,7 +4,9 @@ set(_DEFAULT_VCPKG_ROOT "${CMAKE_SOURCE_DIR}/vcpkg") set(VCPKG_ROOT "${_DEFAULT_VCPKG_ROOT}" CACHE STRING "The path to the vcpkg repository") if (VCPKG_ROOT STREQUAL "${_DEFAULT_VCPKG_ROOT}") - file(LOCK "${_DEFAULT_VCPKG_ROOT}" DIRECTORY GUARD FILE) + if (APPLE) # this doesn't work on non-macOS + file(LOCK "${_DEFAULT_VCPKG_ROOT}" DIRECTORY GUARD FILE) + endif() FetchContent_Declare(vcpkg GIT_REPOSITORY "https://github.com/Microsoft/vcpkg.git" GIT_TAG 2024.01.12 @@ -16,6 +18,18 @@ set(VCPKG_OVERLAY_TRIPLETS "${CMAKE_SOURCE_DIR}/cmake/overlay-triplets") option(USE_RECOMMENDED_TRIPLETS "Use the recommended triplets that are used for official builds" ON) +# Duplicated here because it needs to be set before project() +if (NOT WIN32) + option(USE_QT6 "Build using Qt 6 instead of 5" ON) +else() + option(USE_QT6 "Build using Qt 6 instead of 5" OFF) +endif() + +if (NOT USE_QT6) + list(APPEND VCPKG_MANIFEST_FEATURES qt5) + set(VCPKG_MANIFEST_NO_DEFAULT_FEATURES ON) +endif() + if (CMAKE_OSX_ARCHITECTURES MATCHES ";") message(FATAL_ERROR "macOS universal builds are not supported. Build them individually and combine afterwards instead.") endif() @@ -47,7 +61,7 @@ if (USE_RECOMMENDED_TRIPLETS) elseif(WIN32) # TODO Windows arm64 if possible set(_CAN_TARGET_AS_HOST ON) - set(_WANTED_TRIPLET x64-mingw-static) + set(_WANTED_TRIPLET x64-mingw-static-release) endif() # Don't override it if the user set something else diff --git a/cmake/overlay-triplets/x64-mingw-static-release.cmake b/cmake/overlay-triplets/x64-mingw-static-release.cmake new file mode 100644 index 00000000..19c2aeb0 --- /dev/null +++ b/cmake/overlay-triplets/x64-mingw-static-release.cmake @@ -0,0 +1,7 @@ +set(VCPKG_TARGET_ARCHITECTURE x64) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE static) +set(VCPKG_ENV_PASSTHROUGH PATH) +set(VCPKG_BUILD_TYPE release) + +set(VCPKG_CMAKE_SYSTEM_NAME MinGW) diff --git a/vcpkg.json b/vcpkg.json index fafa0868..ab89176e 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,26 +1,46 @@ { + "default-features": ["qt6"], "dependencies": [ "sdl2", - { - "name": "libarchive", - "default-features": false, - "features": ["bzip2", "crypto", "lz4", "zstd"] + "libarchive", + "zstd" + ], + "features": { + "qt6": { + "description": "Use Qt 6 for the frontend.", + "dependencies": [ + { + "name": "qtbase", + "default-features": false, + "features": ["gui", "png", "thread", "widgets", "opengl", "zstd"] + }, + { + "name": "qtbase", + "host": true, + "default-features": false + }, + { + "name": "qtmultimedia", + "default-features": false + }, + "qtsvg" + ] }, - "zstd", - { - "name": "qtbase", - "default-features": false, - "features": ["gui", "png", "thread", "widgets", "opengl", "zstd"] - }, - { - "name": "qtbase", - "host": true, - "default-features": false - }, - { - "name": "qtmultimedia", - "default-features": false - }, - "qtsvg" - ] + "qt5": { + "description": "Use Qt 5 for the frontend.", + "dependencies": [ + { + "name": "qt5-base", + "default-features": false + }, + { + "name": "qt5-base", + "host": true, + "default-features": false + }, + "qt5-multimedia", + "qt5-svg" + ] + } + } }