sdl12-compat: cmake: fixes for OPENGL_FOUND stuff

From 366603756d46fd7647c46b4b09585ce051a317f8 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Mon, 14 Jun 2021 01:40:04 +0300
Subject: [PATCH] cmake: fixes for OPENGL_FOUND stuff

tested with cmake versions down to 3.0.0
---
 CMakeLists.txt | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index c7da0d9..7139f96 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -96,7 +96,7 @@ if(SDL12TESTS)
     endif()
 
     find_package(OpenGL COMPONENTS OpenGL)
-    if(OpenGL_FOUND)
+    if(OPENGL_FOUND)
       set(HAVE_OPENGL_DEFINE "HAVE_OPENGL")
       if(WIN32)
         set(OPENGL_gl_LIBRARY "opengl32")
@@ -111,6 +111,8 @@ if(SDL12TESTS)
         # Turn off MSVC's aggressive C runtime warnings for the old test programs.
         if(MSVC)
           set_target_properties(${_NAME} PROPERTIES COMPILE_DEFINITIONS "${HAVE_OPENGL_DEFINE};_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE")
+        elseif(APPLE)
+          set_target_properties(${_NAME} PROPERTIES COMPILE_DEFINITIONS "${HAVE_OPENGL_DEFINE};GL_SILENCE_DEPRECATION=1")
         else()
           set_target_properties(${_NAME} PROPERTIES COMPILE_DEFINITIONS "${HAVE_OPENGL_DEFINE}")
         endif()
@@ -149,12 +151,9 @@ if(SDL12TESTS)
     test_program(testwm "test/testwm.c")
     test_program(threadwin "test/threadwin.c")
     test_program(torturethread "test/torturethread.c")
-
-    if(OpenGL_FOUND)
-      test_program(testdyngl "test/testdyngl.c")
-
-      # testgl links directly to OpenGL (yuck), whereas testdyngl doesn't.
-      test_program(testgl "test/testgl.c")
+    test_program(testdyngl "test/testdyngl.c")
+    test_program(testgl "test/testgl.c")
+    if(OPENGL_FOUND)
       if(CMAKE_VERSION VERSION_LESS 3.10)
         target_link_libraries(testgl ${OPENGL_gl_LIBRARY})
       else()
@@ -162,10 +161,6 @@ if(SDL12TESTS)
       endif()
     endif()
 
-    if(APPLE)
-        set_target_properties(testgl PROPERTIES COMPILE_DEFINITIONS "GL_SILENCE_DEPRECATION=1")
-    endif()
-
     foreach(fname "icon.bmp" "moose.dat" "picture.xbm" "sail.bmp" "sample.bmp" "sample.wav" "utf8.txt")
         file(COPY "${CMAKE_SOURCE_DIR}/test/${fname}" DESTINATION "${CMAKE_BINARY_DIR}")
     endforeach(fname)