From: Julian Ospald <hasufell@gentoo.org>
Date: Fri Nov 29 19:34:37 UTC 2013

This patch is currently not needed in this form, because gentoo irrlicht
does not yet have gles2 support. However this will be needed
once it does, so we can add a gles2 useflag.

Also fixes
https://bugs.gentoo.org/show_bug.cgi?id=492804

--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -7,6 +7,7 @@
 mark_as_advanced(JSON_INCLUDE_DIR JSON_LIBRARY)
 
 option(ENABLE_CURL "Enable cURL support for fetching media" 1)
+option(ENABLE_GLES2 "Enable GLES2 support with irrlicht" 0)
 
 if (NOT ENABLE_CURL)
 	mark_as_advanced(CLEAR CURL_LIBRARY CURL_INCLUDE_DIR)
@@ -170,7 +171,10 @@
 
 find_package(Sqlite3 REQUIRED)
 find_package(Json REQUIRED)
-find_package(OpenGLES2)
+if(ENABLE_GLES2 AND BUILD_CLIENT)
+	find_package(OpenGLES2 REQUIRED)
+	add_definitions( -DWITH_GLES2 )
+endif(ENABLE_GLES2 AND BUILD_CLIENT)
 
 if(USE_FREETYPE)
 	find_package(Freetype REQUIRED)
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1331,10 +1331,12 @@
 	else if(driverstring == "ogles1")
 		driverType = video::EDT_OGLES1;
 #endif
+#ifdef WITH_GLES2
 #ifdef _IRR_COMPILE_WITH_OGLES2_
 	else if(driverstring == "ogles2")
 		driverType = video::EDT_OGLES2;
 #endif
+#endif
 	else
 	{
 		errorstream<<"WARNING: Invalid video_driver specified; defaulting "
--- a/cmake/Modules/FindOpenGLES2.cmake
+++ b/cmake/Modules/FindOpenGLES2.cmake
@@ -19,6 +19,7 @@
 # win32, apple, android NOT TESED
 # linux tested and works
 
+
 IF (WIN32)
   IF (CYGWIN)
 
@@ -47,51 +48,57 @@
 
   ELSE(APPLE)
 
-    FIND_PATH(OPENGLES2_INCLUDE_DIR GLES2/gl2.h
-      /usr/openwin/share/include
-      /opt/graphics/OpenGL/include /usr/X11R6/include
-      /usr/include
-    )
-
-    FIND_LIBRARY(OPENGLES2_gl_LIBRARY
-      NAMES GLESv2
-      PATHS /opt/graphics/OpenGL/lib
+    # prefer pkg-config
+    INCLUDE(FindPkgConfig)
+    IF (PKG_CONFIG_FOUND)
+        pkg_check_modules(OPENGLES2 QUIET glesv2 egl)
+    ELSE (PKG_CONFIG_FOUND)
+        FIND_PATH(OPENGLES2_INCLUDE_DIR GLES2/gl2.h
+            /usr/openwin/share/include
+            /opt/graphics/OpenGL/include /usr/X11R6/include
+            /usr/include
+            )
+
+        FIND_LIBRARY(OPENGLES2_gl_LIBRARY
+            NAMES GLESv2
+            PATHS /opt/graphics/OpenGL/lib
             /usr/openwin/lib
             /usr/shlib /usr/X11R6/lib
             /usr/lib
-    )
+            )
 
-    IF (NOT BUILD_ANDROID)
-		FIND_PATH(EGL_INCLUDE_DIR EGL/egl.h
-		  /usr/openwin/share/include
-		  /opt/graphics/OpenGL/include /usr/X11R6/include
-		  /usr/include
-		)
-
-		FIND_LIBRARY(EGL_egl_LIBRARY
-		  NAMES EGL
-		  PATHS /opt/graphics/OpenGL/lib
-				/usr/openwin/lib
-				/usr/shlib /usr/X11R6/lib
-				/usr/lib
-		)
-
-		# On Unix OpenGL most certainly always requires X11.
-		# Feel free to tighten up these conditions if you don't 
-		# think this is always true.
-		# It's not true on OSX.
-
-		IF (OPENGLES2_gl_LIBRARY)
-		  IF(NOT X11_FOUND)
-			INCLUDE(FindX11)
-		  ENDIF(NOT X11_FOUND)
-		  IF (X11_FOUND)
-			IF (NOT APPLE)
-			  SET (OPENGLES2_LIBRARIES ${X11_LIBRARIES})
-			ENDIF (NOT APPLE)
-		  ENDIF (X11_FOUND)
-		ENDIF (OPENGLES2_gl_LIBRARY)
-    ENDIF ()
+        IF (NOT BUILD_ANDROID)
+            FIND_PATH(EGL_INCLUDE_DIR EGL/egl.h
+                /usr/openwin/share/include
+                /opt/graphics/OpenGL/include /usr/X11R6/include
+                /usr/include
+                )
+
+            FIND_LIBRARY(EGL_egl_LIBRARY
+                NAMES EGL
+                PATHS /opt/graphics/OpenGL/lib
+                /usr/openwin/lib
+                /usr/shlib /usr/X11R6/lib
+                /usr/lib
+                )
+
+            # On Unix OpenGL most certainly always requires X11.
+            # Feel free to tighten up these conditions if you don't 
+            # think this is always true.
+            # It's not true on OSX.
+
+            IF (OPENGLES2_gl_LIBRARY)
+                IF(NOT X11_FOUND)
+                    INCLUDE(FindX11)
+                ENDIF(NOT X11_FOUND)
+                IF (X11_FOUND)
+                    IF (NOT APPLE)
+                        SET (OPENGLES2_LIBRARIES ${X11_LIBRARIES})
+                    ENDIF (NOT APPLE)
+                ENDIF (X11_FOUND)
+            ENDIF (OPENGLES2_gl_LIBRARY)
+        ENDIF (NOT BUILD_ANDROID)
+    ENDIF (PKG_CONFIG_FOUND)
 
   ENDIF(APPLE)
 ENDIF (WIN32)
@@ -126,5 +133,5 @@
 IF(OPENGLES2_FOUND)
     MESSAGE(STATUS "Found system opengles2 library ${OPENGLES2_LIBRARIES}")
 ELSE ()
-    SET(OPENGLES2_LIBRARIES "")
+    MESSAGE(FATAL_ERROR "OpenGLES2 not found!")
 ENDIF ()
