Ignore XQuartz prefixes in find_package() on macOS - #333
Open
OlafRocket wants to merge 1 commit into
Open
Conversation
XQuartz installs a Mesa libGL/libGLU plus GL/gl.h under /opt/X11, reachable as /usr/X11 and /usr/X11R6, both of which CMake searches by default via CMAKE_SYSTEM_PREFIX_PATH. CMake's FindOpenGL accepts those names on APPLE, and the vcpkg toolchain sets CMAKE_FIND_FRAMEWORK=LAST, so an installed XQuartz wins over OpenGL.framework and the build picks up Mesa headers and libraries instead of the system ones. The same prefixes also shadow freetype, png and friends, so ignore them wholesale. Signed-off-by: Olaf <8780533+OlafRocket@users.noreply.github.com>
OlafRocket
force-pushed
the
fix/macos-xquartz-opengl
branch
from
September 4, 2026 15:22
8af5cc2 to
a766c48
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summarize your change.
On macOS, add /opt/X11, /usr/X11 and /usr/X11R6 to CMAKE_IGNORE_PREFIX_PATH so find_package() never resolves against an XQuartz installation.
Describe the reason for the change.
XQuartz installs a Mesa libGL/libGLU plus GL/gl.h under /opt/X11, which is also reachable as /usr/X11 and /usr/X11R6. All three are searched by CMake by default via CMAKE_SYSTEM_PREFIX_PATH.
Two things combine to make Mesa win over the system OpenGL:
CMake's FindOpenGL accepts those names on APPLE.
The vcpkg toolchain sets CMAKE_FIND_FRAMEWORK=LAST, which deprioritises OpenGL.framework.
The result is that on any machine with XQuartz installed, the build compiles against Mesa headers and links Mesa libraries instead of the system ones. The same prefixes also shadow freetype, png and other dependencies, so the prefixes are ignored wholesale rather than patching FindOpenGL alone.
XQuartz is common on developer machines (it is pulled in by a number of unrelated tools), so this fails for contributors who have never deliberately installed it.
Describe what you have tested and on which operating system.
Built on Mac Air M1, MacOS Sequoia 15.7.4, with latest XQuartz installed using brew
Add a list of changes, and note any that might need special attention during the review.
CMakeLists.txt: new if(APPLE) block appending the three X11 prefixes to CMAKE_IGNORE_PREFIX_PATH, followed by list(REMOVE_DUPLICATES ...).
Notes for review:
The block is placed immediately after project() and before any find_package() call, which is required for it to take effect.
CMAKE_IGNORE_PREFIX_PATH requires CMake 3.23+.
macOS-only. Guarded by if(APPLE), so Linux and Windows builds are unaffected.