Skip to content

feat: add dual SDL2/SDL3 support with CMake option - #129

Open
doncollins1985 wants to merge 10 commits into
projectM-visualizer:masterfrom
doncollins1985:sdl3-upgrade
Open

feat: add dual SDL2/SDL3 support with CMake option#129
doncollins1985 wants to merge 10 commits into
projectM-visualizer:masterfrom
doncollins1985:sdl3-upgrade

Conversation

@doncollins1985

Copy link
Copy Markdown
  • Add USE_SDL CMake option (Auto/SDL2/SDL3) — prefers SDL3 when available
  • All source files use #ifdef USE_SDL3 guards for API differences: Event types, key struct members, modifier keys, timer/window functions, ImGui backend (sdl2/sdl3), GLSL version (150/300 es), audio capture API, OpenGL proc loader, drop file handling
  • Conditional SDL linkage: SDL3::SDL3 vs SDL2::SDL2 + SDL2::SDL2main
  • New cmake/SDL3Target.cmake for SDL3 target verification
  • Updated ImGui.cmake for conditional backend and kept ImGuiDemo target
  • Updated dependencies_check.cmake and packaging-linux.cmake for SDL version
  • Added audio device hotplug support for SDL3
  • Added CurrentAudioLevel() and RefreshDeviceList() to AudioCapture
  • Refactored drop file handler into HandleDropFile() method
  • SDL3 audio capture uses SDL_AudioStream API
  • SDL key constants remapped via #undef/#define for SDL3 naming
  • Guarded projectm_create_with_opengl_load_proc for older libprojectM
  • CI builds both SDL2 and SDL3 on all four platforms: Ubuntu Linux, Arch Linux, Windows (vcpkg), macOS (Homebrew)
  • vcpkg.json includes both sdl2 and sdl3
  • Windows runner pinned to windows-2022 for VS 2022 compatibility

- Add USE_SDL CMake option (Auto/SDL2/SDL3) — prefers SDL3 when available
- All source files use #ifdef USE_SDL3 guards for API differences:
  Event types, key struct members, modifier keys, timer/window functions,
  ImGui backend (sdl2/sdl3), GLSL version (150/300 es), audio capture API,
  OpenGL proc loader, drop file handling
- Conditional SDL linkage: SDL3::SDL3 vs SDL2::SDL2 + SDL2::SDL2main
- New cmake/SDL3Target.cmake for SDL3 target verification
- Updated ImGui.cmake for conditional backend and kept ImGuiDemo target
- Updated dependencies_check.cmake and packaging-linux.cmake for SDL version
- Added audio device hotplug support for SDL3
- Added CurrentAudioLevel() and RefreshDeviceList() to AudioCapture
- Refactored drop file handler into HandleDropFile() method
- SDL3 audio capture uses SDL_AudioStream API
- SDL key constants remapped via #undef/#define for SDL3 naming
- Guarded projectm_create_with_opengl_load_proc for older libprojectM
- CI builds both SDL2 and SDL3 on all four platforms:
  Ubuntu Linux, Arch Linux, Windows (vcpkg), macOS (Homebrew)
- vcpkg.json includes both sdl2 and sdl3
- Windows runner pinned to windows-2022 for VS 2022 compatibility
@doncollins1985

Copy link
Copy Markdown
Author

?

@kblaschke kblaschke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, a solid upgrade.

I'm not a huge fan of using #ifdefs everywhere, though given how SDL calls are spread over the code base, I don't see any other simple solution than wrapping SDL again, which doesn't make lots of sense.

I've added some comments, mostly related to the build files, packaging and check workflow. The most important one is adding features to the vcpkg manifest to prevent pulling in both libraries when only one of them is ever needed.

Comment thread CMakeLists.txt
Comment thread vcpkg.json Outdated
Comment thread packaging-linux.cmake Outdated
Comment thread .github/workflows/buildcheck.yaml Outdated
Comment thread .github/workflows/buildcheck.yaml Outdated
Comment thread .github/workflows/buildcheck.yaml Outdated
Comment thread .github/workflows/buildcheck.yaml Outdated
Comment thread .github/workflows/buildcheck.yaml Outdated
Comment thread .github/workflows/buildcheck.yaml Outdated
@kblaschke

Copy link
Copy Markdown
Member

Sorry for the late reply, I was swamped with other work in the past weeks/months, and the PRs just kept piling up.
You've not been forgotten!

doncollins1985 and others added 9 commits September 5, 2026 10:12
Co-authored-by: Kai Blaschke <kai.blaschke@kb-dev.net>
Co-authored-by: Kai Blaschke <kai.blaschke@kb-dev.net>
Co-authored-by: Kai Blaschke <kai.blaschke@kb-dev.net>
Co-authored-by: Kai Blaschke <kai.blaschke@kb-dev.net>
Co-authored-by: Kai Blaschke <kai.blaschke@kb-dev.net>
Co-authored-by: Kai Blaschke <kai.blaschke@kb-dev.net>
Co-authored-by: Kai Blaschke <kai.blaschke@kb-dev.net>
- vcpkg.json: wrap sdl2/sdl3 into 'sdl2'/'sdl3' manifest features instead of hard dependencies
- CMakeLists.txt: set VCPKG_MANIFEST_FEATURES from USE_SDL (prefer SDL3 for Auto)
- buildcheck.yaml: build SDL2 on ubuntu-24.04 and SDL3 on ubuntu-26.04 using OS packages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants