SDL_ttf: cmake: make RelWithDebInfo the default configuration

From a53486b68289d9ebd2ed13150144eea43a12fb3e Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Sat, 28 Dec 2024 01:26:35 +0100
Subject: [PATCH] cmake: make RelWithDebInfo the default configuration

---
 CMakeLists.txt | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2f95bc2a..d4a66144 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,9 @@
 cmake_minimum_required(VERSION 3.16)
 
+if(NOT DEFINED CMAKE_BUILD_TYPE)
+  set(cmake_build_type_undefined 1)
+endif()
+
 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
 
 # See docs/release_checklist.md
@@ -26,6 +30,23 @@ else()
     set(SDLTTF_ROOTPROJECT OFF)
 endif()
 
+# By default, configure in RelWithDebInfo configuration
+if(SDLTTF_ROOTPROJECT)
+  get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+  if(is_multi_config)
+    # The first item in CMAKE_CONFIGURATION_TYPES is the default configuration
+    if(DEFINED CMAKE_CONFIGURATION_TYPES AND "RelWithDebInfo" IN_LIST CMAKE_CONFIGURATION_TYPES)
+      list(REMOVE_ITEM CMAKE_CONFIGURATION_TYPES "RelWithDebInfo")
+      list(INSERT CMAKE_CONFIGURATION_TYPES 0 "RelWithDebInfo")
+      set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING "CMake configuration types" FORCE)
+    endif()
+  else()
+    if(cmake_build_type_undefined)
+      set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "CMake build type" FORCE)
+    endif()
+  endif()
+endif()
+
 # Assume MSVC projects don't have a package manager and need vendored dependencies (by default).
 # Most other platforms have some kind of package manager.
 # FIXME: consider a package manager such as conan/vcpkg instead of vendoring