Clean up and tweak build system
[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, and Android are not tested!
20 # Linux tested and works
21
22 if(WIN32)
23         if(CYGWIN)
24                 find_path(OPENGLES2_INCLUDE_DIR GLES2/gl2.h)
25                 find_library(OPENGLES2_LIBRARY libGLESv2)
26         else()
27                 if(BORLAND)
28                         set(OPENGLES2_LIBRARY import32 CACHE STRING "OpenGL ES 2.x library for Win32")
29                 else()
30                         # TODO
31                         # set(OPENGLES_LIBRARY ${SOURCE_DIR}/Dependencies/lib/release/libGLESv2.lib CACHE STRING "OpenGL ES 2.x library for win32"
32                 else()
33         endif()
34 elseif(APPLE)
35         create_search_paths(/Developer/Platforms)
36         findpkg_framework(OpenGLES2)
37         set(OPENGLES2_LIBRARY "-framework OpenGLES")
38 else()
39         find_path(OPENGLES2_INCLUDE_DIR GLES2/gl2.h
40                 PATHS /usr/openwin/share/include
41                         /opt/graphics/OpenGL/include
42                         /usr/X11R6/include
43                         /usr/include
44         )
45
46         find_library(OPENGLES2_LIBRARY
47                 NAMES GLESv2
48                 PATHS /opt/graphics/OpenGL/lib
49                         /usr/openwin/lib
50                         /usr/shlib /usr/X11R6/lib
51                         /usr/lib
52         )
53
54         if(NOT BUILD_ANDROID)
55                 find_path(EGL_INCLUDE_DIR EGL/egl.h
56                         PATHS /usr/openwin/share/include
57                                 /opt/graphics/OpenGL/include
58                                 /usr/X11R6/include
59                                 /usr/include
60                 )
61
62                 find_library(EGL_LIBRARY
63                         NAMES EGL
64                         PATHS /opt/graphics/OpenGL/lib
65                                 /usr/openwin/lib
66                                 /usr/shlib
67                                 /usr/X11R6/lib
68                                 /usr/lib
69                 )
70
71                 # On Unix OpenGL usually requires X11.
72                 # It doesn't require X11 on OSX.
73
74                 if(OPENGLES2_LIBRARY)
75                         if(NOT X11_FOUND)
76                                 include(FindX11)
77                         endif()
78                         if(X11_FOUND)
79                                 set(OPENGLES2_LIBRARIES ${X11_LIBRARIES})
80                         endif()
81                 endif()
82         endif()
83 endif()
84
85 set(OPENGLES2_LIBRARIES ${OPENGLES2_LIBRARIES} ${OPENGLES2_LIBRARY})
86
87 if(BUILD_ANDROID)
88         if(OPENGLES2_LIBRARY)
89                 set(EGL_LIBRARIES)
90                 set(OPENGLES2_FOUND TRUE)
91         endif()
92 else()
93         if(OPENGLES2_LIBRARY AND EGL_LIBRARY)
94                 set(OPENGLES2_LIBRARIES ${OPENGLES2_LIBRARY} ${OPENGLES2_LIBRARIES})
95                 set(EGL_LIBRARIES ${EGL_LIBRARY} ${EGL_LIBRARIES})
96                 set(OPENGLES2_FOUND TRUE)
97         endif()
98 endif()
99
100 mark_as_advanced(
101         OPENGLES2_INCLUDE_DIR
102         OPENGLES2_LIBRARY
103         EGL_INCLUDE_DIR
104         EGL_LIBRARY
105 )
106
107 if(OPENGLES2_FOUND)
108         message(STATUS "Found system OpenGL ES 2 library: ${OPENGLES2_LIBRARIES}")
109 else()
110         set(OPENGLES2_LIBRARIES "")
111 endif()
112