summaryrefslogtreecommitdiff
path: root/Modules/FindOpenGL.cmake
diff options
context:
space:
mode:
authorMyungJoo Ham <myungjoo.ham@samsung.com>2017-10-11 15:16:57 +0900
committerMyungJoo Ham <myungjoo.ham@samsung.com>2017-10-11 15:16:57 +0900
commit915c76ded744c0f5f151402b9fa69f3fd8452573 (patch)
treeca6a387466543248890f346847acaa8343989b22 /Modules/FindOpenGL.cmake
parent317dbdb79761ef65e45c7358cfc7571c6afa54ad (diff)
downloadcmake-915c76ded744c0f5f151402b9fa69f3fd8452573.tar.gz
cmake-915c76ded744c0f5f151402b9fa69f3fd8452573.tar.bz2
cmake-915c76ded744c0f5f151402b9fa69f3fd8452573.zip
Imported Upstream version 3.9.4upstream/3.9.4
Diffstat (limited to 'Modules/FindOpenGL.cmake')
-rw-r--r--Modules/FindOpenGL.cmake144
1 files changed, 101 insertions, 43 deletions
diff --git a/Modules/FindOpenGL.cmake b/Modules/FindOpenGL.cmake
index 83fcc3dc7..af83fb735 100644
--- a/Modules/FindOpenGL.cmake
+++ b/Modules/FindOpenGL.cmake
@@ -1,32 +1,52 @@
-# - Try to find OpenGL
-# Once done this will define
+# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+# file Copyright.txt or https://cmake.org/licensing for details.
+
+#.rst:
+# FindOpenGL
+# ----------
#
-# OPENGL_FOUND - system has OpenGL
-# OPENGL_XMESA_FOUND - system has XMESA
-# OPENGL_GLU_FOUND - system has GLU
-# OPENGL_INCLUDE_DIR - the GL include directory
-# OPENGL_LIBRARIES - Link these to use OpenGL and GLU
+# FindModule for OpenGL and GLU.
#
-# If you want to use just GL you can use these values
-# OPENGL_gl_LIBRARY - Path to OpenGL Library
-# OPENGL_glu_LIBRARY - Path to GLU Library
+# IMPORTED Targets
+# ^^^^^^^^^^^^^^^^
#
-# On OSX default 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
-
-#=============================================================================
-# Copyright 2001-2009 Kitware, Inc.
+# This module defines the :prop_tgt:`IMPORTED` targets:
+#
+# ``OpenGL::GL``
+# Defined if the system has OpenGL.
+# ``OpenGL::GLU``
+# Defined if the system has GLU.
+#
+# Result Variables
+# ^^^^^^^^^^^^^^^^
+#
+# This module sets the following variables:
+#
+# ``OPENGL_FOUND``
+# True, if the system has OpenGL.
+# ``OPENGL_XMESA_FOUND``
+# True, if the system has XMESA.
+# ``OPENGL_GLU_FOUND``
+# True, if the system has GLU.
+# ``OPENGL_INCLUDE_DIR``
+# Path to the OpenGL include directory.
+# ``OPENGL_LIBRARIES``
+# Paths to the OpenGL and GLU libraries.
#
-# Distributed under the OSI-approved BSD License (the "License");
-# see accompanying file Copyright.txt for details.
+# If you want to use just GL you can use these values:
#
-# This software is distributed WITHOUT ANY WARRANTY; without even the
-# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-# See the License for more information.
-#=============================================================================
-# (To distribute this file outside of CMake, substitute the full
-# License text for the above reference.)
+# ``OPENGL_gl_LIBRARY``
+# Path to the OpenGL library.
+# ``OPENGL_glu_LIBRARY``
+# Path to the GLU library.
+#
+# OSX Specific
+# ^^^^^^^^^^^^
+#
+# On OSX default 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.
+
set(_OpenGL_REQUIRED_VARS OPENGL_gl_LIBRARY)
@@ -51,9 +71,11 @@ elseif (WIN32)
elseif (APPLE)
- find_library(OPENGL_gl_LIBRARY OpenGL DOC "OpenGL lib for OSX")
- find_library(OPENGL_glu_LIBRARY AGL DOC "AGL lib for OSX")
- find_path(OPENGL_INCLUDE_DIR OpenGL/gl.h DOC "Include for OpenGL on OSX")
+ # The OpenGL.framework provides both gl and glu
+ find_library(OPENGL_gl_LIBRARY OpenGL DOC "OpenGL library for OS X")
+ find_library(OPENGL_glu_LIBRARY OpenGL DOC
+ "GLU library for OS X (usually same as OpenGL library)")
+ find_path(OPENGL_INCLUDE_DIR OpenGL/gl.h DOC "Include for OpenGL on OS X")
list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR)
else()
@@ -108,19 +130,6 @@ else()
unset(_OPENGL_INCLUDE_PATH)
unset(_OPENGL_LIB_PATH)
- # On Unix OpenGL most certainly always requires X11.
- # Feel free to tighten up these conditions if you don't
- # think this is always true.
-
- if (OPENGL_gl_LIBRARY)
- if(NOT X11_FOUND)
- include(${CMAKE_CURRENT_LIST_DIR}/FindX11.cmake)
- endif()
- if (X11_FOUND)
- set (OPENGL_LIBRARIES ${X11_LIBRARIES})
- endif ()
- endif ()
-
find_library(OPENGL_glu_LIBRARY
NAMES GLU MesaGLU
PATHS ${OPENGL_gl_LIBRARY}
@@ -142,7 +151,9 @@ if(OPENGL_gl_LIBRARY)
set( OPENGL_LIBRARIES ${OPENGL_gl_LIBRARY} ${OPENGL_LIBRARIES})
if(OPENGL_glu_LIBRARY)
set( OPENGL_GLU_FOUND "YES" )
- set( OPENGL_LIBRARIES ${OPENGL_glu_LIBRARY} ${OPENGL_LIBRARIES} )
+ if(NOT "${OPENGL_glu_LIBRARY}" STREQUAL "${OPENGL_gl_LIBRARY}")
+ set( OPENGL_LIBRARIES ${OPENGL_glu_LIBRARY} ${OPENGL_LIBRARIES} )
+ endif()
else()
set( OPENGL_GLU_FOUND "NO" )
endif()
@@ -155,12 +166,59 @@ endif()
# This deprecated setting is for backward compatibility with CMake1.4
set(OPENGL_INCLUDE_PATH ${OPENGL_INCLUDE_DIR})
-# handle the QUIETLY and REQUIRED arguments and set OPENGL_FOUND to TRUE if
-# all listed variables are TRUE
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenGL REQUIRED_VARS ${_OpenGL_REQUIRED_VARS})
unset(_OpenGL_REQUIRED_VARS)
+# OpenGL:: targets
+if(OPENGL_FOUND)
+ if(NOT TARGET OpenGL::GL)
+ if(IS_ABSOLUTE "${OPENGL_gl_LIBRARY}")
+ add_library(OpenGL::GL UNKNOWN IMPORTED)
+ if(OPENGL_gl_LIBRARY MATCHES "/([^/]+)\\.framework$")
+ set(_gl_fw "${OPENGL_gl_LIBRARY}/${CMAKE_MATCH_1}")
+ if(EXISTS "${_gl_fw}.tbd")
+ string(APPEND _gl_fw ".tbd")
+ endif()
+ set_target_properties(OpenGL::GL PROPERTIES
+ IMPORTED_LOCATION "${_gl_fw}")
+ else()
+ set_target_properties(OpenGL::GL PROPERTIES
+ IMPORTED_LOCATION "${OPENGL_gl_LIBRARY}")
+ endif()
+ else()
+ add_library(OpenGL::GL INTERFACE IMPORTED)
+ set_target_properties(OpenGL::GL PROPERTIES
+ IMPORTED_LIBNAME "${OPENGL_gl_LIBRARY}")
+ endif()
+ set_target_properties(OpenGL::GL PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${OPENGL_INCLUDE_DIR}")
+ endif()
+
+ if(OPENGL_GLU_FOUND AND NOT TARGET OpenGL::GLU)
+ if(IS_ABSOLUTE "${OPENGL_glu_LIBRARY}")
+ add_library(OpenGL::GLU UNKNOWN IMPORTED)
+ if(OPENGL_glu_LIBRARY MATCHES "/([^/]+)\\.framework$")
+ set(_glu_fw "${OPENGL_glu_LIBRARY}/${CMAKE_MATCH_1}")
+ if(EXISTS "${_glu_fw}.tbd")
+ string(APPEND _glu_fw ".tbd")
+ endif()
+ set_target_properties(OpenGL::GLU PROPERTIES
+ IMPORTED_LOCATION "${_glu_fw}")
+ else()
+ set_target_properties(OpenGL::GLU PROPERTIES
+ IMPORTED_LOCATION "${OPENGL_glu_LIBRARY}")
+ endif()
+ else()
+ add_library(OpenGL::GLU INTERFACE IMPORTED)
+ set_target_properties(OpenGL::GLU PROPERTIES
+ IMPORTED_LIBNAME "${OPENGL_glu_LIBRARY}")
+ endif()
+ set_target_properties(OpenGL::GLU PROPERTIES
+ INTERFACE_LINK_LIBRARIES OpenGL::GL)
+ endif()
+endif()
+
mark_as_advanced(
OPENGL_INCLUDE_DIR
OPENGL_xmesa_INCLUDE_DIR