sdl12-compat: change building test programs into an option, defaulting to off.

From a719acd09903a3917340f93ce223a28961d27652 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Fri, 12 Mar 2021 17:56:04 +0300
Subject: [PATCH] change building test programs into an option, defaulting to
 off.

---
 CMakeLists.txt | 35 ++++++++++++++++++++---------------
 1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index abb30ed..de3a974 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,10 +1,15 @@
 # NOTE:  If you installed SDL2 at an unusual place and FindSDL2 fails,
 #        you can define SDL2_INCLUDE_DIR on the cmdline.  For example:
 #        cmake -DSDL2_INCLUDE_DIR=/opt/SDL2/include/SDL2 [other stuff]
+#
+# NOTE:  To build SDL1.2 test programs enable SDL12TESTS. For example:
+#        cmake -DSDL12TESTS=1 [other stuff]
 
 cmake_minimum_required(VERSION 3.0.0)
 project(sdl12_compat)
 
+option(SDL12TESTS "Enable to build SDL-1.2 test programs" OFF)
+
 if(APPLE)
   set(OSX_SRCS "src/SDL12_compat_objc.m")
   set_source_files_properties(${OSX_SRCS} PROPERTIES LANGUAGE C)
@@ -73,20 +78,20 @@ if(MSVC)
 endif()
 
 
-# test programs...
-
-include(FindSDL)
-if(NOT (WIN32 OR APPLE OR CYGWIN OR HAIKU OR BEOS))
-  find_library(MATH_LIBRARY m)
-endif()
-
-macro(test_program _NAME _SRCS)
-    add_executable(${_NAME} ${_SRCS})
-    target_include_directories(${_NAME} PRIVATE ${SDL_INCLUDE_DIR})
-    target_link_libraries(${_NAME} SDL)
-    if(MATH_LIBRARY)
-      target_link_libraries(${_NAME} ${MATH_LIBRARY})
+if(SDL12TESTS)
+    include(FindSDL)
+    if(NOT (WIN32 OR APPLE OR CYGWIN OR HAIKU OR BEOS))
+      find_library(MATH_LIBRARY m)
     endif()
-endmacro()
 
-test_program(testsprite "test/testsprite.c")
+    macro(test_program _NAME _SRCS)
+        add_executable(${_NAME} ${_SRCS})
+        target_include_directories(${_NAME} PRIVATE ${SDL_INCLUDE_DIR})
+        target_link_libraries(${_NAME} SDL)
+        if(MATH_LIBRARY)
+          target_link_libraries(${_NAME} ${MATH_LIBRARY})
+        endif()
+    endmacro()
+
+    test_program(testsprite "test/testsprite.c")
+endif()