Files
yaze/cmake/overlays/sdl2/portfile.cmake
scawful a20a4832d2 chore(cmake): add vcpkg overlay support for SDL2
- Introduced custom vcpkg port overlays to address SDL2 installation issues on Windows by skipping pkgconfig fixup.
- Updated CI and release workflows to include the new `VCPKG_OVERLAY_PORTS` configuration for enhanced build reliability.
- Added documentation for the overlays, detailing their purpose and usage.

Benefits:
- Prevents build failures related to SDL2 on Windows, improving the overall stability of the build process.
- Streamlines the integration of patched ports without forking the vcpkg repository, enhancing maintainability.
2025-10-15 22:50:44 -04:00

84 lines
2.9 KiB
CMake

# Patched SDL2 portfile that skips pkgconfig fixup on Windows
# This prevents MSYS2 download failures during vcpkg installation
# Based on official SDL2 port with pkgconfig fixup removed
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO libsdl-org/SDL
REF "release-${VERSION}"
SHA512 bbf9e35dc1cb1b47d1e452ef23bd3b49bdfd83c6e291e7e7f61c45fb07b33e01cc77811c8c854a599bcdafc2e98b03015fc5e9c6e4c1db8ec61a9e90ff17ed83
HEAD_REF main
PATCHES
deps.patch
alsa-dep-fix.patch
cxx-linkage-pkgconfig.diff
)
string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "static" SDL_STATIC)
string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "dynamic" SDL_SHARED)
string(COMPARE EQUAL "${VCPKG_CRT_LINKAGE}" "static" FORCE_STATIC_VCRT)
vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
FEATURES
alsa SDL_ALSA
ibus SDL_IBUS
samplerate SDL_LIBSAMPLERATE
wayland SDL_WAYLAND
x11 SDL_X11
)
if(VCPKG_TARGET_IS_UWP)
set(configure_opts WINDOWS_USE_MSBUILD)
endif()
vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
${configure_opts}
OPTIONS ${FEATURE_OPTIONS}
-DSDL_STATIC=${SDL_STATIC}
-DSDL_SHARED=${SDL_SHARED}
-DSDL_FORCE_STATIC_VCRT=${FORCE_STATIC_VCRT}
-DSDL_LIBC=ON
-DSDL_TEST=OFF
-DSDL_INSTALL_CMAKEDIR=share/sdl2
MAYBE_UNUSED_VARIABLES
SDL_FORCE_STATIC_VCRT
)
vcpkg_cmake_install()
vcpkg_cmake_config_fixup(CONFIG_PATH share/sdl2)
file(REMOVE_RECURSE
"${CURRENT_PACKAGES_DIR}/debug/include"
"${CURRENT_PACKAGES_DIR}/debug/share"
"${CURRENT_PACKAGES_DIR}/bin/sdl2-config"
"${CURRENT_PACKAGES_DIR}/debug/bin/sdl2-config"
"${CURRENT_PACKAGES_DIR}/share/licenses"
"${CURRENT_PACKAGES_DIR}/share/aclocal"
)
# Skip pkgconfig fixup on Windows to avoid MSYS2 download issues
if(NOT VCPKG_TARGET_IS_WINDOWS)
vcpkg_fixup_pkgconfig()
endif()
if(VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_UWP)
if(NOT VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/lib/manual-link")
file(RENAME "${CURRENT_PACKAGES_DIR}/lib/SDL2main.lib" "${CURRENT_PACKAGES_DIR}/lib/manual-link/SDL2main.lib")
endif()
if(NOT VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/debug/lib/manual-link")
file(RENAME "${CURRENT_PACKAGES_DIR}/debug/lib/SDL2maind.lib" "${CURRENT_PACKAGES_DIR}/debug/lib/manual-link/SDL2maind.lib")
endif()
file(GLOB SHARE_FILES "${CURRENT_PACKAGES_DIR}/share/sdl2/*.cmake")
foreach(SHARE_FILE ${SHARE_FILES})
vcpkg_replace_string("${SHARE_FILE}" "lib/SDL2main" "lib/manual-link/SDL2main")
endforeach()
endif()
file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE.txt")