diff --git a/CMakeLists.txt b/CMakeLists.txt index 9db20705f4..5c15f2f254 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() + # See docs/release_checklist.md project(SDL3 LANGUAGES C VERSION "3.1.7") @@ -9,6 +13,23 @@ else() set(SDL3_SUBPROJECT ON) endif() +# By default, configure SDL3 in RelWithDebInfo configuration +if(NOT SDL3_SUBPROJECT) + 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() + # CMake 3.0 expands the "if(${A})" in "set(OFF 1);set(A OFF);if(${A})" to "if(1)" # CMake 3.24+ emits a warning when not set. unset(OFF)