FindOpenGL¶
FindModule for OpenGL and OpenGL Utility Library (GLU).
在 3.2 版的變更: X11 is no longer added as a dependency on Unix/Linux systems.
在 3.10 版被加入: GLVND support on Linux. See the Linux-specific section below.
Optional COMPONENTS¶
在 3.10 版被加入.
This module respects several optional COMPONENTS:
EGLThe EGL interface between OpenGL, OpenGL ES and the underlying windowing system.
GLXAn extension to X that interfaces OpenGL, OpenGL ES with X window system.
OpenGLThe cross platform API for 3D graphics.
GLES2在 3.27 版被加入.
A subset of OpenGL API for embedded systems with limited capabilities.
GLES3在 3.27 版被加入.
A subset of OpenGL API for embedded systems with more capabilities.
Imported Targets¶
在 3.8 版被加入.
This module defines the IMPORTED targets:
OpenGL::GLDefined to the platform-specific OpenGL libraries if the system has OpenGL.
OpenGL::GLUDefined if the system has OpenGL Utility Library (GLU).
在 3.10 版被加入: Additionally, the following GLVND-specific library targets are defined:
OpenGL::OpenGLDefined to libOpenGL if the system is GLVND-based.
OpenGL::GLXDefined if the system has OpenGL Extension to the X Window System (GLX).
OpenGL::EGLDefined if the system has EGL.
OpenGL::GLES2在 3.27 版被加入.
Defined if the system has GLES2.
OpenGL::GLES3在 3.27 版被加入.
Defined if the system has GLES3.
Result Variables¶
This module sets the following variables:
OPENGL_FOUNDTrue, if the system has OpenGL and all components are found.
OPENGL_XMESA_FOUNDTrue, if the system has XMESA.
OPENGL_GLU_FOUNDTrue, if the system has GLU.
OpenGL_OpenGL_FOUNDTrue, if the system has an OpenGL library.
OpenGL_GLX_FOUNDTrue, if the system has GLX.
OpenGL_EGL_FOUNDTrue, if the system has EGL.
OpenGL::GLES2Defined if the system has GLES2.
OpenGL::GLES3Defined if the system has GLES3.
OPENGL_INCLUDE_DIRPath to the OpenGL include directory. The
OPENGL_INCLUDE_DIRSvariable is preferred.OPENGL_EGL_INCLUDE_DIRSPath to the EGL include directory.
OPENGL_LIBRARIESPaths 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.OPENGL_INCLUDE_DIRS在 3.29 版被加入.
Paths to the OpenGL include directories.
在 3.10 版被加入: Variables for GLVND-specific libraries OpenGL, EGL and GLX.
Cache variables¶
The following cache variables may also be set:
OPENGL_egl_LIBRARYPath to the EGL library.
OPENGL_glu_LIBRARYPath to the GLU library.
OPENGL_glx_LIBRARYPath to the GLVND 'GLX' library.
OPENGL_opengl_LIBRARYPath to the GLVND 'OpenGL' library
OPENGL_gl_LIBRARYPath to the OpenGL library. New code should prefer the
OpenGL::*import targets.OPENGL_gles2_LIBRARY在 3.27 版被加入.
Path to the OpenGL GLES2 library.
OPENGL_gles3_LIBRARY在 3.27 版被加入.
Path to the OpenGL GLES3 library.
OPENGL_GLU_INCLUDE_DIR在 3.29 版被加入.
Path to the OpenGL GLU include directory.
在 3.10 版被加入: Variables for GLVND-specific libraries OpenGL, EGL and GLX.
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.
Projects may use GLVND explicitly with target OpenGL::OpenGL and either
OpenGL::GLX or OpenGL::EGL.
Projects may use the OpenGL::GL target (or OPENGL_LIBRARIES variable)
to use legacy GL interfaces. These will use the legacy GL library located
by OPENGL_gl_LIBRARY, if available. If OPENGL_gl_LIBRARY is empty or
not found and GLVND is available, the OpenGL::GL target will use GLVND
OpenGL::OpenGL and OpenGL::GLX (and the OPENGL_LIBRARIES
variable will use the corresponding libraries). Thus, for non-EGL-based
Linux targets, the OpenGL::GL target is most portable.
A OpenGL_GL_PREFERENCE variable may be set to specify the preferred way
to provide legacy GL interfaces in case multiple choices are available.
The value may be one of:
GLVNDIf the GLVND OpenGL and GLX libraries are available, prefer them. This forces
OPENGL_gl_LIBRARYto be empty.在 3.11 版的變更: This is the default, unless policy
CMP0072is set toOLDand no components are requested (since components correspond to GLVND libraries).LEGACYPrefer to use the legacy libGL library, if available.
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 macOS this module defaults to using the macOS-native framework version of OpenGL. To use the X11 version of OpenGL on macOS, one can disable searching of frameworks. For example:
find_package(X11)
if(APPLE AND X11_FOUND)
set(CMAKE_FIND_FRAMEWORK NEVER)
find_package(OpenGL)
unset(CMAKE_FIND_FRAMEWORK)
else()
find_package(OpenGL)
endif()
An end user building this project may need to point CMake at their
X11 installation, e.g., with -DOpenGL_ROOT=/opt/X11.