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
+31 -1
View File
@@ -102,9 +102,39 @@ add_executable(rgbgfx $<TARGET_OBJECTS:common>
"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.
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".
RUNTIME_OUTPUT_DIRECTORY $<1:${CMAKE_SOURCE_DIR}>)
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.