SDL: Just use the khronos headers for the checks that need them

From 5db543a66a510858b7888bd7f17fab64eefdfc42 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Fri, 19 Jan 2024 23:55:05 -0800
Subject: [PATCH] Just use the khronos headers for the checks that need them

---
 CMakeLists.txt        |  1 -
 cmake/sdlchecks.cmake | 12 ++++++++----
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5d116812f5e0..5985005551fa 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -448,7 +448,6 @@ if(USE_GCC OR USE_INTELCC OR (USE_CLANG AND NOT MSVC_CLANG))
 else()
   sdl_include_directories(NO_EXPORT SYSTEM PUBLIC "$<BUILD_INTERFACE:${SDL3_SOURCE_DIR}/src/video/khronos>")
 endif()
-list(APPEND CMAKE_REQUIRED_INCLUDES "${SDL3_SOURCE_DIR}/src/video/khronos")
 
 # General source files
 sdl_glob_sources(
diff --git a/cmake/sdlchecks.cmake b/cmake/sdlchecks.cmake
index 52f4e8ff9527..c91df3f395e2 100644
--- a/cmake/sdlchecks.cmake
+++ b/cmake/sdlchecks.cmake
@@ -652,6 +652,7 @@ macro(CheckEGL)
     cmake_push_check_state()
     find_package(OpenGL MODULE)
     list(APPEND CMAKE_REQUIRED_INCLUDES ${OPENGL_EGL_INCLUDE_DIRS})
+    list(APPEND CMAKE_REQUIRED_INCLUDES "${SDL3_SOURCE_DIR}/src/video/khronos")
     check_c_source_compiles("
         #define EGL_API_FB
         #define MESA_EGL_NO_X11_HEADERS
@@ -686,18 +687,21 @@ endmacro()
 # - nada
 macro(CheckOpenGLES)
   if(SDL_OPENGLES)
+    cmake_push_check_state()
+    list(APPEND CMAKE_REQUIRED_INCLUDES "${SDL3_SOURCE_DIR}/src/video/khronos")
     check_c_source_compiles("
         #include <GLES/gl.h>
         #include <GLES/glext.h>
         int main (int argc, char** argv) { return 0; }" HAVE_OPENGLES_V1)
-    if(HAVE_OPENGLES_V1)
-      set(HAVE_OPENGLES TRUE)
-      set(SDL_VIDEO_OPENGL_ES 1)
-    endif()
     check_c_source_compiles("
       #include <GLES2/gl2.h>
       #include <GLES2/gl2ext.h>
       int main (int argc, char** argv) { return 0; }" HAVE_OPENGLES_V2)
+    cmake_pop_check_state()
+    if(HAVE_OPENGLES_V1)
+      set(HAVE_OPENGLES TRUE)
+      set(SDL_VIDEO_OPENGL_ES 1)
+    endif()
     if(HAVE_OPENGLES_V2)
       set(HAVE_OPENGLES TRUE)
       set(SDL_VIDEO_OPENGL_ES2 1)