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.
This commit is contained in:
37
cmake/overlays/README.md
Normal file
37
cmake/overlays/README.md
Normal file
@@ -0,0 +1,37 @@
|
||||
# vcpkg Port Overlays
|
||||
|
||||
This directory contains custom vcpkg port overlays that modify the behavior of specific packages during installation.
|
||||
|
||||
## Purpose
|
||||
|
||||
vcpkg overlays allow us to patch specific ports without forking the entire vcpkg repository. These overlays are automatically used when `VCPKG_OVERLAY_PORTS` is set in the CMake configuration.
|
||||
|
||||
## Current Overlays
|
||||
|
||||
### sdl2/
|
||||
|
||||
**Problem**: The official SDL2 vcpkg port runs `vcpkg_fixup_pkgconfig()` on Windows, which attempts to download `pkgconf` from MSYS2 mirrors. These URLs frequently return 404 errors, causing build failures.
|
||||
|
||||
**Solution**: Patched portfile that skips pkgconfig fixup on Windows platforms while maintaining it for Linux/macOS where it's needed.
|
||||
|
||||
**Impact**: Prevents SDL2 installation failures on Windows without affecting functionality (pkgconfig isn't needed for Windows static builds).
|
||||
|
||||
## Usage
|
||||
|
||||
The overlays are automatically applied via the GitHub Actions workflows:
|
||||
|
||||
```cmake
|
||||
-DVCPKG_OVERLAY_PORTS=${github.workspace}/cmake/overlays
|
||||
```
|
||||
|
||||
For local development on Windows:
|
||||
```bash
|
||||
cmake -B build -DVCPKG_OVERLAY_PORTS=cmake/overlays ...
|
||||
```
|
||||
|
||||
## Maintenance
|
||||
|
||||
- Overlays are version-specific (currently SDL2 2.30.9)
|
||||
- When updating SDL2 version in vcpkg.json, check if the overlay needs updating
|
||||
- Monitor upstream vcpkg for fixes that would allow removing these overlays
|
||||
|
||||
83
cmake/overlays/sdl2/portfile.cmake
Normal file
83
cmake/overlays/sdl2/portfile.cmake
Normal file
@@ -0,0 +1,83 @@
|
||||
# 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")
|
||||
|
||||
8
cmake/overlays/sdl2/usage
Normal file
8
cmake/overlays/sdl2/usage
Normal file
@@ -0,0 +1,8 @@
|
||||
SDL2 provides CMake targets:
|
||||
|
||||
find_package(SDL2 CONFIG REQUIRED)
|
||||
target_link_libraries(main PRIVATE $<IF:$<TARGET_EXISTS:SDL2::SDL2>,SDL2::SDL2,SDL2::SDL2-static>)
|
||||
|
||||
# SDL2::SDL2main may be optionally added manually to provide a main() function wrapper.
|
||||
# If you use this, don't use SDL_MAIN_HANDLED.
|
||||
|
||||
68
cmake/overlays/sdl2/vcpkg.json
Normal file
68
cmake/overlays/sdl2/vcpkg.json
Normal file
@@ -0,0 +1,68 @@
|
||||
{
|
||||
"name": "sdl2",
|
||||
"version": "2.30.9",
|
||||
"description": "Simple DirectMedia Layer (patched to skip pkgconfig on Windows)",
|
||||
"homepage": "https://www.libsdl.org/",
|
||||
"license": "Zlib",
|
||||
"dependencies": [
|
||||
{
|
||||
"name": "vcpkg-cmake",
|
||||
"host": true
|
||||
},
|
||||
{
|
||||
"name": "vcpkg-cmake-config",
|
||||
"host": true
|
||||
}
|
||||
],
|
||||
"default-features": [],
|
||||
"features": {
|
||||
"alsa": {
|
||||
"description": "Support for alsa audio",
|
||||
"dependencies": [
|
||||
{
|
||||
"name": "alsa",
|
||||
"platform": "linux"
|
||||
}
|
||||
]
|
||||
},
|
||||
"ibus": {
|
||||
"description": "Build with support for IBus",
|
||||
"dependencies": [
|
||||
{
|
||||
"name": "ibus",
|
||||
"platform": "linux"
|
||||
}
|
||||
]
|
||||
},
|
||||
"samplerate": {
|
||||
"description": "Use libsamplerate for audio rate conversion",
|
||||
"dependencies": [
|
||||
"libsamplerate"
|
||||
]
|
||||
},
|
||||
"wayland": {
|
||||
"description": "Build with support for Wayland",
|
||||
"dependencies": [
|
||||
{
|
||||
"name": "wayland",
|
||||
"platform": "linux"
|
||||
},
|
||||
{
|
||||
"name": "wayland-protocols",
|
||||
"host": true,
|
||||
"platform": "linux"
|
||||
}
|
||||
]
|
||||
},
|
||||
"x11": {
|
||||
"description": "Build with support for X11",
|
||||
"dependencies": [
|
||||
{
|
||||
"name": "libxext",
|
||||
"platform": "linux"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user