Skip to content

Ignore XQuartz prefixes in find_package() on macOS - #333

Open
OlafRocket wants to merge 1 commit into
AcademySoftwareFoundation:developfrom
OlafRocket:fix/macos-xquartz-opengl
Open

Ignore XQuartz prefixes in find_package() on macOS#333
OlafRocket wants to merge 1 commit into
AcademySoftwareFoundation:developfrom
OlafRocket:fix/macos-xquartz-opengl

Conversation

@OlafRocket

Copy link
Copy Markdown
Contributor

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.

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
OlafRocket force-pushed the fix/macos-xquartz-opengl branch from 8af5cc2 to a766c48 Compare September 4, 2026 15:22
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