[cmake] enforce a supported build type

We check for build types internally to enable/disable debug options.
Ensure the CMAKE_BUILD_TYPE is either not set or set to a supported
value.
This commit is contained in:
Armin Novak 2024-10-23 16:15:13 +02:00 committed by akallabeth
parent ae5f655f12
commit 0d7edfd884
No known key found for this signature in database
GPG Key ID: A49454A3FC909FD5

View File

@ -29,6 +29,8 @@ if (NOT ANDROID)
option(CMAKE_INTERPROCEDURAL_OPTIMIZATION "build with link time optimization" ${supported})
endif()
set(SUPPORTED_BUILD_TYPES "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
# Default to release build type
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
# Set a default build type if none was specified
@ -39,7 +41,13 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY
STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
STRINGS ${SUPPORTED_BUILD_TYPES})
endif()
if (CMAKE_BUILD_TYPE)
if (NOT "${CMAKE_BUILD_TYPE}" IN_LIST SUPPORTED_BUILD_TYPES)
message(FATAL_ERROR "CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} not supported. Set to any of ${SUPPORTED_BUILD_TYPES}")
endif()
endif()
include(PlatformDefaults)