Use CPack for Windows packaging

This commit is contained in:
vulcandth
2026-03-08 21:14:34 -05:00
committed by Eldred Habert
parent 2cfb2b2533
commit c3b47abcc8
6 changed files with 62 additions and 23 deletions
+2 -1
View File
@@ -21,7 +21,8 @@ case "${1%-*}" in
pkg install -y bash bison cmake git png pkg install -y bash bison cmake git png
;; ;;
windows) windows)
choco install -y winflexbison3 # GitHub Actions' hosted runners ship CMake 3.x, but versions prior to 4.0.0 ignore `CPACK_PACKAGE_FILE_NAME`.
choco install -y winflexbison3 cmake
# The below expects the base name, not the Windows-specific name. # The below expects the base name, not the Windows-specific name.
bison() { win_bison "$@"; } # An alias doesn't work, so we use a function instead. bison() { win_bison "$@"; } # An alias doesn't work, so we use a function instead.
;; ;;
@@ -24,11 +24,6 @@ jobs:
strategy: strategy:
matrix: matrix:
bits: [32, 64] bits: [32, 64]
include:
- bits: 32
arch: x86
- bits: 64
arch: x86_x64
fail-fast: false fail-fast: false
steps: steps:
- name: Checkout repo - name: Checkout repo
@@ -42,14 +37,14 @@ jobs:
cmake -S . -B build --preset msvc${{ matrix.bits }} -DFETCHCONTENT_BASE_DIR="${{ env.DEPS_ROOT_DIR }}" cmake -S . -B build --preset msvc${{ matrix.bits }} -DFETCHCONTENT_BASE_DIR="${{ env.DEPS_ROOT_DIR }}"
cmake --build build --config Release cmake --build build --config Release
- name: Package binaries - name: Package binaries
working-directory: build
run: | run: |
cmake --install build --config Release --prefix install_dir --verbose cpack -DCPACK_PACKAGE_FILE_NAME=rgbds-win${{ matrix.bits }} -G ZIP -C Release --verbose
Compress-Archive -LiteralPath @("install_dir/bin/rgbasm.exe", "install_dir/bin/rgblink.exe", "install_dir/bin/rgbfix.exe", "install_dir/bin/rgbgfx.exe", "install_dir/bin/z.dll", "install_dir/bin/libpng16.dll") "rgbds-win${{ matrix.bits }}.zip"
- name: Upload Windows binaries - name: Upload Windows binaries
uses: actions/upload-artifact@v7 uses: actions/upload-artifact@v7
with: with:
name: win${{ matrix.bits }} name: win${{ matrix.bits }}
path: rgbds-win${{ matrix.bits }}.zip path: build/rgbds-win${{ matrix.bits }}.zip
if-no-files-found: error if-no-files-found: error
macos: macos:
+3 -12
View File
@@ -155,11 +155,6 @@ jobs:
matrix: matrix:
bits: [32, 64] bits: [32, 64]
os: [windows-2022, windows-2025] os: [windows-2022, windows-2025]
include:
- bits: 32
arch: x86
- bits: 64
arch: x86_x64
fail-fast: false fail-fast: false
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
@@ -175,21 +170,19 @@ jobs:
key: dep-srcs-${{ hashFiles('cmake/deps.cmake') }} key: dep-srcs-${{ hashFiles('cmake/deps.cmake') }}
enableCrossOsArchive: true # Currently only used on Windows, but the contents are OS-agnostic. enableCrossOsArchive: true # Currently only used on Windows, but the contents are OS-agnostic.
- name: Build Windows binaries - name: Build Windows binaries
shell: bash
run: | # ASan seems to be broken on Windows, so we disable it. run: | # ASan seems to be broken on Windows, so we disable it.
cmake -S . -B build --preset develop-msvc${{ matrix.bits }} -DFETCHCONTENT_BASE_DIR="${{ env.DEPS_ROOT_DIR }}" -DSANITIZERS=OFF cmake -S . -B build --preset develop-msvc${{ matrix.bits }} -DFETCHCONTENT_BASE_DIR="${{ env.DEPS_ROOT_DIR }}" -DSANITIZERS=OFF
cmake --build build cmake --build build
- name: Package binaries - name: Package binaries
working-directory: build
shell: bash shell: bash
run: | run: |
cmake --install build --config Debug --prefix install_dir --verbose cpack -DCPACK_PACKAGE_FILE_NAME=rgbds-win${{ matrix.bits }} -G ZIP -C Debug --verbose
mkdir bins
cp -v install_dir/bin/{rgb*.exe,*.dll} bins
- name: Upload Windows binaries - name: Upload Windows binaries
uses: actions/upload-artifact@v7 uses: actions/upload-artifact@v7
with: with:
name: rgbds-canary-w${{ matrix.bits }}-${{ matrix.os }} name: rgbds-canary-w${{ matrix.bits }}-${{ matrix.os }}
path: bins path: build/rgbds-win${{ matrix.bits }}.zip
if-no-files-found: error if-no-files-found: error
- name: Compute test dependency cache params - name: Compute test dependency cache params
id: test-deps-cache-params id: test-deps-cache-params
@@ -218,8 +211,6 @@ jobs:
- name: Run tests - name: Run tests
shell: bash shell: bash
run: | run: |
cp bins/* .
cp bins/*.dll test/gfx
test/run-tests.sh --os ${{ matrix.os }} test/run-tests.sh --os ${{ matrix.os }}
windows-mingw-build: windows-mingw-build:
+21 -1
View File
@@ -176,5 +176,25 @@ set(man7 "man/gbz80.7"
"man/rgbds.7") "man/rgbds.7")
foreach(SECTION "man1" "man5" "man7") foreach(SECTION "man1" "man5" "man7")
install(FILES ${${SECTION}} DESTINATION "${CMAKE_INSTALL_MANDIR}/${SECTION}") install(FILES ${${SECTION}} DESTINATION "${CMAKE_INSTALL_MANDIR}/${SECTION}" COMPONENT man)
endforeach() endforeach()
## Packaging.
# We only specify here the package-agnostic options;
# the rest is rather convention from our side, and thus more appropriate for presets or CLI flags.
## CPACK_PACKAGE_NAME: copied from `project()`
set(CPACK_PACKAGE_VENDOR "GBDev")
set(CPACK_PACKAGE_VERSION "${CMAKE_PROJECT_VERSION}") # The individual components are defined implicitly.
set(CPACK_PACKAGE_DESCRIPTION "An assembly toolchain for the Nintendo Game Boy and Game Boy Color") # Same as our repo's description.
## CPACK_PACKAGE_DESCRIPTION_SUMMARY: copied from `project()`
set(CPACK_PACKAGE_HOMEPAGE_URL "https://rgbds.gbdev.io")
## CPACK_PACKAGE_FILE_NAME: should be provided at runtime (`cpack -P`)
set(CPACK_PACKAGE_CHECKSUM SHA256)
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md")
set(CPACK_STRIP_FILES ON) # Only applies to binary packages, not sources.
set(CPACK_VERBATIM_VARIABLES ON)
set(CPACK_THREADS 0) # Use all available CPU cores.
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
include(CPack)
+2
View File
@@ -5,6 +5,7 @@
FetchContent_Declare(PNG FetchContent_Declare(PNG
URL https://download.sourceforge.net/libpng/libpng-1.6.56.tar.xz URL https://download.sourceforge.net/libpng/libpng-1.6.56.tar.xz
URL_HASH SHA256=f7d8bf1601b7804f583a254ab343a6549ca6cf27d255c302c47af2d9d36a6f18 URL_HASH SHA256=f7d8bf1601b7804f583a254ab343a6549ca6cf27d255c302c47af2d9d36a6f18
EXCLUDE_FROM_ALL # We only install the runtime dependencies, and do so separately.
FIND_PACKAGE_ARGS 1.5.4) FIND_PACKAGE_ARGS 1.5.4)
set(PNG_TESTS OFF CACHE INTERNAL "") # We do not care for these two (and they can even cause compile errors!) set(PNG_TESTS OFF CACHE INTERNAL "") # We do not care for these two (and they can even cause compile errors!)
@@ -15,6 +16,7 @@ set(PNG_STATIC OFF CACHE INTERNAL "")
FetchContent_Declare(ZLIB FetchContent_Declare(ZLIB
URL https://www.zlib.net/zlib-1.3.2.tar.xz URL https://www.zlib.net/zlib-1.3.2.tar.xz
URL_HASH SHA256=d7a0654783a4da529d1bb793b7ad9c3318020af77667bcae35f95d0e42a792f3 URL_HASH SHA256=d7a0654783a4da529d1bb793b7ad9c3318020af77667bcae35f95d0e42a792f3
EXCLUDE_FROM_ALL # We only install the runtime dependencies, and do so separately.
# libpng documents requiring "zlib 1.0.4 or later (1.2.13 or later recommended for performance and security reasons)". # libpng documents requiring "zlib 1.0.4 or later (1.2.13 or later recommended for performance and security reasons)".
# We thus enforce 1.0.4, but note that the libpng source code mentions that "it may work with versions as old as zlib 0.95". # We thus enforce 1.0.4, but note that the libpng source code mentions that "it may work with versions as old as zlib 0.95".
FIND_PACKAGE_ARGS 1.0.4) FIND_PACKAGE_ARGS 1.0.4)
+31 -1
View File
@@ -102,9 +102,39 @@ add_executable(rgbgfx $<TARGET_OBJECTS:common>
"verbosity.cpp" "verbosity.cpp"
) )
install(TARGETS rgbasm rgblink rgbfix rgbgfx RUNTIME) install(TARGETS rgbasm rgblink rgbfix rgbgfx RUNTIME COMPONENT binaries)
# Tests expect the binaries to end up in-source; this is more acceptable than the entire artifact dir. # Tests expect the binaries to end up in-source; this is more acceptable than the entire artifact dir.
set_target_properties(rgbasm rgblink rgbfix rgbgfx PROPERTIES set_target_properties(rgbasm rgblink rgbfix rgbgfx PROPERTIES
# The generator expression (even if a no-op) stops muti-config generators using a of "per-configuration subdirectory". # The generator expression (even if a no-op) stops muti-config generators using a of "per-configuration subdirectory".
RUNTIME_OUTPUT_DIRECTORY $<1:${CMAKE_SOURCE_DIR}>) RUNTIME_OUTPUT_DIRECTORY $<1:${CMAKE_SOURCE_DIR}>)
target_link_libraries(rgbgfx PRIVATE PNG::PNG) target_link_libraries(rgbgfx PRIVATE PNG::PNG)
# On Windows, you don't link against DLLs directly, but against an import library for that DLL.
# This leads to, sometimes, the DLL being stored in a directory far away from the import library itself!
set(DLL_SEARCH_DIRS CACHE PATH "List of directories in which DLLs will be searched")
cmake_path(CONVERT "${DLL_SEARCH_DIRS}" TO_CMAKE_PATH_LIST search_dirs NORMALIZE)
# TODO: we've only tested this with MinGW, but it may not work with other uses of the variable.
# Anyone who knows how to handle this better, feel free to submit a patch!
if(DEFINED CMAKE_FIND_ROOT_PATH)
list(APPEND search_dirs "${CMAKE_FIND_ROOT_PATH}/bin")
endif()
# Escape the search paths in a form that makes them suitable for splatting into the CMake install script.
list(TRANSFORM search_dirs REPLACE "([\\$\"])" "\\\\1") # Neutralize escapes and variable refs...
list(TRANSFORM search_dirs REPLACE "^(.+)\$" "\"\\1\"") # ...and quote each argument.
list(JOIN search_dirs " " search_dirs_splat)
# This is a modified version of the install code generated by
# `install(TARGETS rgbgfx RUNTIME_DEPENDENCIES)`.
# Unfortunately, that `install(TARGETS)` is outright not supported when cross-compiling,
# and working around that has CMake fail to resolve the DLL locations with MinGW,
# due to not specifying any `DIRECTORIES` and the system search path being ineffective.
install(CODE "\
file(GET_RUNTIME_DEPENDENCIES
RESOLVED_DEPENDENCIES_VAR rgbgfx_deps
EXECUTABLES \"$<TARGET_FILE:rgbgfx>\"
DIRECTORIES ${search_dirs_splat} \"$<TARGET_FILE_DIR:ZLIB::ZLIB>\" \"$<TARGET_FILE_DIR:PNG::PNG>\"
PRE_EXCLUDE_REGEXES \"^kernel32\\\\.dll$\" \"^msvcrt.?.?\\\\.dll\" \"^api-ms-win-.*\\\\.dll$\")
foreach(rgbgfx_dep IN LISTS rgbgfx_deps)
file(INSTALL DESTINATION \"$<INSTALL_PREFIX>/${CMAKE_INSTALL_BINDIR}\" TYPE SHARED_LIBRARY FILES \${rgbgfx_dep}
FOLLOW_SYMLINK_CHAIN)
endforeach()"
COMPONENT shared-libs EXCLUDE_FROM_ALL) # Most platforms install those separately.