Skip to content

macOS: prefer package-manager SDL2 over a stale system framework#1134

Open
quarrel07 wants to merge 1 commit into
Kenix3:mainfrom
quarrel07:macos-sdl2-pr
Open

macOS: prefer package-manager SDL2 over a stale system framework#1134
quarrel07 wants to merge 1 commit into
Kenix3:mainfrom
quarrel07:macos-sdl2-pr

Conversation

@quarrel07

@quarrel07 quarrel07 commented Jun 22, 2026

Copy link
Copy Markdown

Problem

On macOS, a stale or partial /Library/Frameworks/SDL2.framework (left behind by some installers) shadows a working Homebrew/MacPorts SDL2 and breaks configuration:

File or directory /Library/Headers referenced by variable SDL2_INCLUDE_DIR does not exist !

The framework's bundled CMake config sets SDL2_INCLUDE_DIR to a non-existent /Library/Headers, so find_package(SDL2 REQUIRED) fails even though a perfectly good SDL2 is installed via Homebrew. The only current workaround is to pass -DSDL2_DIR=... (or delete the system framework) manually.

Fix

In cmake/dependencies/mac.cmake, search frameworks last and add the Homebrew prefix to the search path, so the package-manager SDL2 (and its CMake config) is preferred automatically:

set(CMAKE_FIND_FRAMEWORK LAST)
find_program(BREW_EXECUTABLE brew)
if (BREW_EXECUTABLE)
    execute_process(COMMAND ${BREW_EXECUTABLE} --prefix
                    OUTPUT_VARIABLE BREW_PREFIX OUTPUT_STRIP_TRAILING_WHITESPACE)
    if (BREW_PREFIX)
        list(APPEND CMAKE_PREFIX_PATH "${BREW_PREFIX}")
    endif()
endif()

Scoped to the macOS dependency path; no effect on other platforms. One file changed; branched off current main.

A stale or partial /Library/Frameworks/SDL2.framework (left by some installers)
shadows a working Homebrew/MacPorts SDL2 and breaks configuration:

    File or directory /Library/Headers referenced by variable
    SDL2_INCLUDE_DIR does not exist !

The framework's bundled CMake config sets SDL2_INCLUDE_DIR to a non-existent
/Library/Headers, so find_package(SDL2 REQUIRED) fails even though a working
SDL2 is installed via Homebrew/MacPorts.

Set CMAKE_FIND_FRAMEWORK LAST so package-manager installs win, and add the
Homebrew prefix to CMAKE_PREFIX_PATH so SDL2's CMake config is found without
requiring the user to pass -DSDL2_DIR manually. Only affects the macOS path.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

1 participant