Installing SDL2_config.cmake etc. on MacOS

I’m building a cross-platform game that should build on both Windows and Mac. I’d really like to use the same CMakeLists.txt on both. It’s proving difficult.

On Windows, the obvious choice was to install SDL2 and its friends using the package manager they came with MSYS2, pacman. Great. SDL2_config.cmake and his friends were installed in the proper place, and find_package just works! (All except SDL2_gfx , for the moment I’m having to hardcode the path to that library. Yuck!)

On Macintosh, the recommended approach is to download and install the SDL2 libraries as Frameworks. Clearly very desirable for building a distributable app. However – this installation method provides no opportunity to install SDL2_config.cmake or anything of the sort. And find_package doesn’t know what to do. Online I found a FindSDL2.cmake. Unofficially, someone had made a FindSDL2_image.cmake; it doesn’t work very well. I find myself hard-coding the path to most of the SDL2 related libraries.

Main question: how is this actually supposed to work ? Is there any nice method for getting those *config.cmake files on Macintosh, so that finding just works as nicely as it does on Windows?

The last time I messed with CMake to try to include SDL on macOS, I basically just put SDL3.framework in the source code repo, then pointed CMake at it and told it to link to it as a framework.

The generated Xcode project file built an app that included the framework in the app bundle, so users don’t have to install (potentially conflicting versions) of SDL.