FindOpenGL

FindModule for OpenGL and GLU.

Optional COMPONENTS

This module respects several optional COMPONENTS: EGL, GLX, and OpenGL. There are corresponding import targets for each of these flags.

IMPORTED Targets

This module defines the IMPORTED targets:

OpenGL::GL
Defined to the platform-specific OpenGL libraries if the system has OpenGL.
OpenGL::OpenGL
Defined to libOpenGL if the system is GLVND-based. OpenGL::GL
OpenGL::GLU
Defined if the system has GLU.
OpenGL::GLX
Defined if the system has GLX.
OpenGL::EGL
Defined if the system has EGL.

Result Variables

This module sets the following variables:

OPENGL_FOUND
True, if the system has OpenGL and all components are found.
OPENGL_XMESA_FOUND
True, if the system has XMESA.
OPENGL_GLU_FOUND
True, if the system has GLU.
OpenGL_OpenGL_FOUND
True, if the system has an OpenGL library.
OpenGL_GLX_FOUND
True, if the system has GLX.
OpenGL_EGL_FOUND
True, if the system has EGL.
OPENGL_INCLUDE_DIR
Path to the OpenGL include directory.
OPENGL_EGL_INCLUDE_DIRS
Path to the EGL include directory.
OPENGL_LIBRARIES
Paths to the OpenGL library, windowing system libraries, and GLU libraries. On Linux, this assumes glX and is never correct for EGL-based targets. Clients are encouraged to use the OpenGL::* import targets instead.

Cache variables

The following cache variables may also be set:

OPENGL_egl_LIBRARY
Path to the EGL library.
OPENGL_glu_LIBRARY
Path to the GLU library.
OPENGL_glx_LIBRARY
Path to the GLVND ‘GLX’ library.
OPENGL_opengl_LIBRARY
Path to the GLVND ‘OpenGL’ library
OPENGL_gl_LIBRARY
Path to the OpenGL library. New code should prefer the OpenGL::* import targets.

Linux-specific

Some Linux systems utilize GLVND as a new ABI for OpenGL. GLVND separates context libraries from OpenGL itself; OpenGL lives in “libOpenGL”, and contexts are defined in “libGLX” or “libEGL”. GLVND is currently the only way to get OpenGL 3+ functionality via EGL in a manner portable across vendors.

On Linux systems FindOpenGL defaults to using GLVND if available. Users can utilize GLVND explicitly with targets OpenGL::OpenGL, OpenGL::GLX, and OpenGL::EGL. Additionally, when GLVND is available the OpenGL::GL target is equivalent to OpenGL::OpenGL OpenGL::GLX. When the system is not GLVND-based, OpenGL::GL expands to libGL as it has historically done. Thus, for non-EGL-based Linux targets, the OpenGL::GL target is most portable.

For EGL targets the client must rely on GLVND support on the user’s system. Linking should use the OpenGL::OpenGL OpenGL::EGL targets. Using GLES* libraries is theoretically possible in place of OpenGL::OpenGL, but this module does not currently support that; contributions welcome.

OPENGL_egl_LIBRARY and OPENGL_EGL_INCLUDE_DIRS are defined in the case of GLVND. For non-GLVND Linux and other systems these are left undefined.

macOS-Specific

On OSX FindOpenGL defaults to using the framework version of OpenGL. People will have to change the cache values of OPENGL_glu_LIBRARY and OPENGL_gl_LIBRARY to use OpenGL with X11 on OSX.