FindOpenGL.cmake 4.98 KB
Newer Older
1
# - Try to find OpenGL
Ian Scott's avatar
Ian Scott committed
2
# Once done this will define
3
#
Ken Martin's avatar
Ken Martin committed
4 5 6 7
#  OPENGL_FOUND        - system has OpenGL
#  OPENGL_XMESA_FOUND  - system has XMESA
#  OPENGL_GLU_FOUND    - system has GLU
#  OPENGL_INCLUDE_DIR  - the GL include directory
8
#  OPENGL_LIBRARIES    - Link these to use OpenGL and GLU
9
#
Ken Martin's avatar
Ken Martin committed
10
# If you want to use just GL you can use these values
11 12
#  OPENGL_gl_LIBRARY   - Path to OpenGL Library
#  OPENGL_glu_LIBRARY  - Path to GLU Library
13
#
14
# On OSX default to using the framework version of opengl
15
# People will have to change the cache values of OPENGL_glu_LIBRARY
Ken Martin's avatar
Ken Martin committed
16
# and OPENGL_gl_LIBRARY to use OpenGL with X11 on OSX
17

18 19 20 21 22 23 24 25 26 27
#=============================================================================
# Copyright 2001-2009 Kitware, Inc.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# 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.
#=============================================================================
28
# (To distribute this file outside of CMake, substitute the full
29 30
#  License text for the above reference.)

31 32
if (WIN32)
  if (CYGWIN)
Ian Scott's avatar
Ian Scott committed
33

34
    find_path(OPENGL_INCLUDE_DIR GL/gl.h )
Ian Scott's avatar
Ian Scott committed
35

36
    find_library(OPENGL_gl_LIBRARY opengl32 )
Ian Scott's avatar
Ian Scott committed
37

38
    find_library(OPENGL_glu_LIBRARY glu32 )
Ian Scott's avatar
Ian Scott committed
39

40
  else ()
Ian Scott's avatar
Ian Scott committed
41

42 43 44
    if(BORLAND)
      set (OPENGL_gl_LIBRARY import32 CACHE STRING "OpenGL library for win32")
      set (OPENGL_glu_LIBRARY import32 CACHE STRING "GLU library for win32")
45
    else()
46 47
      set (OPENGL_gl_LIBRARY opengl32 CACHE STRING "OpenGL library for win32")
      set (OPENGL_glu_LIBRARY glu32 CACHE STRING "GLU library for win32")
48
    endif()
Ian Scott's avatar
Ian Scott committed
49

50
  endif ()
Ian Scott's avatar
Ian Scott committed
51

52
else ()
53

54
  if (APPLE)
55

56 57 58
    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")
59

60
  else()
61 62
    # Handle HP-UX cases where we only want to find OpenGL in either hpux64
    # or hpux32 depending on if we're doing a 64 bit build.
63 64
    if(CMAKE_SIZEOF_VOID_P EQUAL 4)
      set(HPUX_IA_OPENGL_LIB_PATH /opt/graphics/OpenGL/lib/hpux32/)
65
    else()
66
      set(HPUX_IA_OPENGL_LIB_PATH
67 68
        /opt/graphics/OpenGL/lib/hpux64/
        /opt/graphics/OpenGL/lib/pa20_64)
69
    endif()
70 71 72 73 74 75 76 77 78

    # The first line below is to make sure that the proper headers
    # are used on a Linux machine with the NVidia drivers installed.
    # They replace Mesa with NVidia's own library but normally do not
    # install headers and that causes the linking to
    # fail since the compiler finds the Mesa headers but NVidia's library.
    # Make sure the NVIDIA directory comes BEFORE the others.
    #  - Atanas Georgiev <atanas@cs.columbia.edu>

79
    find_path(OPENGL_INCLUDE_DIR GL/gl.h
80 81
      /usr/share/doc/NVIDIA_GLX-1.0/include
      /usr/openwin/share/include
82
      /opt/graphics/OpenGL/include /usr/X11R6/include
83 84
    )

85
    find_path(OPENGL_xmesa_INCLUDE_DIR GL/xmesa.h
86 87
      /usr/share/doc/NVIDIA_GLX-1.0/include
      /usr/openwin/share/include
88
      /opt/graphics/OpenGL/include /usr/X11R6/include
89 90
    )

91
    find_library(OPENGL_gl_LIBRARY
92
      NAMES GL MesaGL
93
      PATHS /opt/graphics/OpenGL/lib
94
            /usr/openwin/lib
95
            /usr/shlib /usr/X11R6/lib
96
            ${HPUX_IA_OPENGL_LIB_PATH}
97 98 99
    )

    # On Unix OpenGL most certainly always requires X11.
100
    # Feel free to tighten up these conditions if you don't
101 102 103
    # think this is always true.
    # It's not true on OSX.

104 105
    if (OPENGL_gl_LIBRARY)
      if(NOT X11_FOUND)
106
        include(${CMAKE_CURRENT_LIST_DIR}/FindX11.cmake)
107
      endif()
108 109 110
      if (X11_FOUND)
        if (NOT APPLE)
          set (OPENGL_LIBRARIES ${X11_LIBRARIES})
111 112 113
        endif ()
      endif ()
    endif ()
114 115

    find_library(OPENGL_glu_LIBRARY
116 117 118 119
      NAMES GLU MesaGLU
      PATHS ${OPENGL_gl_LIBRARY}
            /opt/graphics/OpenGL/lib
            /usr/openwin/lib
120
            /usr/shlib /usr/X11R6/lib
121 122
    )

123 124
  endif()
endif ()
125

126
if(OPENGL_gl_LIBRARY)
Ian Scott's avatar
Ian Scott committed
127

128 129
    if(OPENGL_xmesa_INCLUDE_DIR)
      set( OPENGL_XMESA_FOUND "YES" )
130
    else()
131
      set( OPENGL_XMESA_FOUND "NO" )
132
    endif()
Ian Scott's avatar
Ian Scott committed
133

134 135 136 137
    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} )
138
    else()
139
      set( OPENGL_GLU_FOUND "NO" )
140
    endif()
Ian Scott's avatar
Ian Scott committed
141

142
    # This deprecated setting is for backward compatibility with CMake1.4
143
    set (OPENGL_LIBRARY ${OPENGL_LIBRARIES})
Ian Scott's avatar
Ian Scott committed
144

145
endif()
146

Ken Martin's avatar
Ken Martin committed
147
# This deprecated setting is for backward compatibility with CMake1.4
148
set(OPENGL_INCLUDE_PATH ${OPENGL_INCLUDE_DIR})
149

Ben Boeckel's avatar
Ben Boeckel committed
150 151
# handle the QUIETLY and REQUIRED arguments and set OPENGL_FOUND to TRUE if
# all listed variables are TRUE
152
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
Ben Boeckel's avatar
Ben Boeckel committed
153 154
FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenGL DEFAULT_MSG OPENGL_gl_LIBRARY)

155
mark_as_advanced(
156 157 158 159 160
  OPENGL_INCLUDE_DIR
  OPENGL_xmesa_INCLUDE_DIR
  OPENGL_glu_LIBRARY
  OPENGL_gl_LIBRARY
)