42d31c898f8878cca48e4447a8f7630059cc3b84
[oweals/minetest.git] / cmake / Modules / FindOpenGLES2.cmake
1 #-------------------------------------------------------------------
2 # This file is stolen from part of the CMake build system for OGRE (Object-oriented Graphics Rendering Engine) http://www.ogre3d.org/
3 #
4 # The contents of this file are placed in the public domain. Feel
5 # free to make use of it in any way you like.
6 #-------------------------------------------------------------------
7
8 # - Try to find OpenGLES and EGL
9 # Once done this will define
10 #
11 #  OPENGLES2_FOUND        - system has OpenGLES
12 #  OPENGLES2_INCLUDE_DIR  - the GL include directory
13 #  OPENGLES2_LIBRARIES    - Link these to use OpenGLES
14 #
15 #  EGL_FOUND        - system has EGL
16 #  EGL_INCLUDE_DIR  - the EGL include directory
17 #  EGL_LIBRARIES    - Link these to use EGL
18
19 # win32, apple, android NOT TESED
20 # linux tested and works
21
22 IF (WIN32)
23   IF (CYGWIN)
24
25     FIND_PATH(OPENGLES2_INCLUDE_DIR GLES2/gl2.h )
26
27     FIND_LIBRARY(OPENGLES2_gl_LIBRARY libGLESv2 )
28
29   ELSE (CYGWIN)
30
31     IF(BORLAND)
32       SET (OPENGLES2_gl_LIBRARY import32 CACHE STRING "OpenGL ES 2.x library for win32")
33     ELSE(BORLAND)
34       # todo
35       # SET (OPENGLES_gl_LIBRARY ${SOURCE_DIR}/Dependencies/lib/release/libGLESv2.lib CACHE STRING "OpenGL ES 2.x library for win32"
36     ENDIF(BORLAND)
37
38   ENDIF (CYGWIN)
39
40 ELSE (WIN32)
41
42   IF (APPLE)
43
44         create_search_paths(/Developer/Platforms)
45         findpkg_framework(OpenGLES2)
46     set(OPENGLES2_gl_LIBRARY "-framework OpenGLES")
47
48   ELSE(APPLE)
49
50     FIND_PATH(OPENGLES2_INCLUDE_DIR GLES2/gl2.h
51       /usr/openwin/share/include
52       /opt/graphics/OpenGL/include /usr/X11R6/include
53       /usr/include
54     )
55
56     FIND_LIBRARY(OPENGLES2_gl_LIBRARY
57       NAMES GLESv2
58       PATHS /opt/graphics/OpenGL/lib
59             /usr/openwin/lib
60             /usr/shlib /usr/X11R6/lib
61             /usr/lib
62     )
63
64     IF (NOT BUILD_ANDROID)
65                 FIND_PATH(EGL_INCLUDE_DIR EGL/egl.h
66                   /usr/openwin/share/include
67                   /opt/graphics/OpenGL/include /usr/X11R6/include
68                   /usr/include
69                 )
70
71                 FIND_LIBRARY(EGL_egl_LIBRARY
72                   NAMES EGL
73                   PATHS /opt/graphics/OpenGL/lib
74                                 /usr/openwin/lib
75                                 /usr/shlib /usr/X11R6/lib
76                                 /usr/lib
77                 )
78
79                 # On Unix OpenGL most certainly always requires X11.
80                 # Feel free to tighten up these conditions if you don't 
81                 # think this is always true.
82                 # It's not true on OSX.
83
84                 IF (OPENGLES2_gl_LIBRARY)
85                   IF(NOT X11_FOUND)
86                         INCLUDE(FindX11)
87                   ENDIF(NOT X11_FOUND)
88                   IF (X11_FOUND)
89                         IF (NOT APPLE)
90                           SET (OPENGLES2_LIBRARIES ${X11_LIBRARIES})
91                         ENDIF (NOT APPLE)
92                   ENDIF (X11_FOUND)
93                 ENDIF (OPENGLES2_gl_LIBRARY)
94     ENDIF ()
95
96   ENDIF(APPLE)
97 ENDIF (WIN32)
98
99 #SET( OPENGLES2_LIBRARIES ${OPENGLES2_gl_LIBRARY} ${OPENGLES2_LIBRARIES})
100
101 IF (BUILD_ANDROID)
102   IF(OPENGLES2_gl_LIBRARY)
103       SET( OPENGLES2_LIBRARIES ${OPENGLES2_gl_LIBRARY} ${OPENGLES2_LIBRARIES})
104       SET( EGL_LIBRARIES)
105       SET( OPENGLES2_FOUND "YES" )
106   ENDIF(OPENGLES2_gl_LIBRARY)
107 ELSE ()
108
109   SET( OPENGLES2_LIBRARIES ${OPENGLES2_gl_LIBRARY} ${OPENGLES2_LIBRARIES})
110
111   IF(OPENGLES2_gl_LIBRARY AND EGL_egl_LIBRARY)
112     SET( OPENGLES2_LIBRARIES ${OPENGLES2_gl_LIBRARY} ${OPENGLES2_LIBRARIES})
113     SET( EGL_LIBRARIES ${EGL_egl_LIBRARY} ${EGL_LIBRARIES})
114     SET( OPENGLES2_FOUND "YES" )
115   ENDIF(OPENGLES2_gl_LIBRARY AND EGL_egl_LIBRARY)
116
117 ENDIF ()
118
119 MARK_AS_ADVANCED(
120   OPENGLES2_INCLUDE_DIR
121   OPENGLES2_gl_LIBRARY
122   EGL_INCLUDE_DIR
123   EGL_egl_LIBRARY
124 )
125
126 IF(OPENGLES2_FOUND)
127     MESSAGE(STATUS "Found system opengles2 library ${OPENGLES2_LIBRARIES}")
128 ELSE ()
129     SET(OPENGLES2_LIBRARIES "")
130 ENDIF ()