From 6416595375ba7530c987f410d05551a85e6df114 Mon Sep 17 00:00:00 2001 From: vulcandth Date: Sun, 8 Mar 2026 21:14:34 -0500 Subject: [PATCH] Use CPack for Windows packaging --- .../workflows/create-release-artifacts.yml | 4 ++-- .github/workflows/testing.yml | 6 +++-- CMakeLists.txt | 22 ++++++++++++++++++- src/CMakeLists.txt | 10 +++++---- test/CMakeLists.txt | 4 +--- 5 files changed, 34 insertions(+), 12 deletions(-) diff --git a/.github/workflows/create-release-artifacts.yml b/.github/workflows/create-release-artifacts.yml index 159179c35..24a721da3 100644 --- a/.github/workflows/create-release-artifacts.yml +++ b/.github/workflows/create-release-artifacts.yml @@ -61,12 +61,12 @@ jobs: cmake --install build --verbose --prefix install_dir --strip - name: Package binaries run: | - 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" + cpack --config build/CPackConfig.cmake -G ZIP -C Release --verbose - name: Upload Windows binaries uses: actions/upload-artifact@v4 with: name: win${{ matrix.bits }} - path: rgbds-win${{ matrix.bits }}.zip + path: build/rgbds-win${{ matrix.bits }}.zip macos: runs-on: macos-14 diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index adfb18295..b943f58fa 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -177,13 +177,15 @@ jobs: - name: Package binaries shell: bash run: | + cpack --config build/CPackConfig.cmake -G ZIP -C Release --verbose mkdir bins - cp install_dir/bin/{rgbasm.exe,rgblink.exe,rgbfix.exe,rgbgfx.exe,z.dll,libpng16.dll} bins + cp install_dir/bin/rgb{asm,link,fix,gfx}.exe bins + cp install_dir/bin/*.dll bins - name: Upload Windows binaries uses: actions/upload-artifact@v4 with: name: rgbds-canary-w${{ matrix.bits }}-${{ matrix.os }} - path: bins + path: build/rgbds-win${{ matrix.bits }}.zip - name: Compute test dependency cache params id: test-deps-cache-params shell: bash diff --git a/CMakeLists.txt b/CMakeLists.txt index 25852c02f..074b58164 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,7 +84,10 @@ else(GIT) endif(GIT) find_package(PkgConfig) -if(MSVC OR NOT PKG_CONFIG_FOUND) +if(MSVC) + find_package(ZLIB REQUIRED CONFIG) + find_package(PNG REQUIRED CONFIG) +elseif(NOT PKG_CONFIG_FOUND) # fallback to find_package # cmake's FindPNG is very fragile; it breaks when multiple versions are installed # this is most evident on macOS but can occur on Linux too @@ -132,3 +135,20 @@ foreach(SECTION "man1" "man5" "man7") set(DEST "${MANDIR}/${SECTION}") install(FILES ${${SECTION}} DESTINATION ${DEST}) endforeach() + +if(WIN32 AND CMAKE_VERSION VERSION_GREATER_EQUAL "3.21") + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(CPACK_SYSTEM_NAME "win64") + else() + set(CPACK_SYSTEM_NAME "win32") + endif() + + set(CPACK_GENERATOR "ZIP") + set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF) + set(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}") + set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${CPACK_SYSTEM_NAME}") + set(CPACK_INSTALL_CMAKE_PROJECTS "${CMAKE_BINARY_DIR};${CMAKE_PROJECT_NAME};runtime;/") + set(CPACK_STRIP_FILES TRUE) + set(CPACK_VERBATIM_VARIABLES YES) + include(CPack) +endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 26d9dd4dc..52d4ef86d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -110,7 +110,7 @@ foreach(PROG "asm" "fix" "gfx" "link") ${rgb${PROG}_src} ${common_src} ) - install(TARGETS rgb${PROG} RUNTIME DESTINATION bin) + install(TARGETS rgb${PROG} RUNTIME DESTINATION bin COMPONENT runtime) # Required to run tests set_target_properties(rgb${PROG} PROPERTIES # hack for MSVC: no-op generator expression to stop generation of "per-configuration subdirectory" @@ -122,9 +122,11 @@ if(LIBPNG_FOUND) # pkg-config target_link_directories(rgbgfx PRIVATE ${LIBPNG_LIBRARY_DIRS}) target_link_libraries(rgbgfx PRIVATE ${LIBPNG_LIBRARIES}) else() - target_compile_definitions(rgbgfx PRIVATE ${PNG_DEFINITIONS}) - target_include_directories(rgbgfx PRIVATE ${PNG_INCLUDE_DIRS}) - target_link_libraries(rgbgfx PRIVATE ${PNG_LIBRARIES}) + target_link_libraries(rgbgfx PRIVATE PNG::PNG) +endif() + +if(WIN32 AND CMAKE_VERSION VERSION_GREATER_EQUAL "3.21") + install(FILES "$" DESTINATION bin COMPONENT runtime) endif() include(CheckLibraryExists) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b054f5861..345e727bd 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -27,9 +27,7 @@ foreach(TARGET randtilegen rgbgfx_test) target_link_directories(${TARGET} PRIVATE ${LIBPNG_LIBRARY_DIRS}) target_link_libraries(${TARGET} PRIVATE ${LIBPNG_LIBRARIES}) else() - target_compile_definitions(${TARGET} PRIVATE ${PNG_DEFINITIONS}) - target_include_directories(${TARGET} PRIVATE ${PNG_INCLUDE_DIRS}) - target_link_libraries(${TARGET} PRIVATE ${PNG_LIBRARIES}) + target_link_libraries(${TARGET} PRIVATE PNG::PNG) endif() endforeach()