CMake: Only use a default CMAKE_BUILD_TYPE if using a single-config generator.

Create a variable that can be used to tell if a generator is multiconfig or not. Since this variable is only available on CMake 3.9 or higher, we'll try to make an educated guess on a lower CMake version.
This commit is contained in:
Donny Lawrence 2019-06-05 12:49:42 -05:00 committed by Sam Edwards
parent cb0def4eb3
commit 27fd87983a

View File

@ -22,13 +22,30 @@ if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
set(IS_FREEBSD 1)
endif()
if(CMAKE_VERSION VERSION_GREATER "3.8")
get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
else()
message(WARNING "Multi-configuration builds may not work properly when using
a CMake < 3.9. Making a guess if this is a multi-config generator.")
if(DEFINED CMAKE_CONFIGURATION_TYPES)
set(IS_MULTICONFIG ON)
else()
set(IS_MULTICONFIG OFF)
endif()
endif()
# Define the type of build we are setting up.
if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
if(IS_MULTICONFIG)
set(CMAKE_CONFIGURATION_TYPES Release RelWithDebInfo Debug MinSizeRel Distribution)
else()
# CMAKE_BUILD_TYPE can't just be set using the usual set(CACHE) method since
# it's an empty string by default.
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif()
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
Release RelWithDebInfo Debug MinSizeRel Distribution)
endif()
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
Release RelWithDebInfo Debug MinSizeRel Distribution)
# Provide convenient boolean expression based on build type
if(CMAKE_BUILD_TYPE MATCHES "Debug")