From 27fd87983a398cd009d841a71d5265010182150f Mon Sep 17 00:00:00 2001 From: Donny Lawrence Date: Wed, 5 Jun 2019 12:49:42 -0500 Subject: [PATCH] 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. --- dtool/Config.cmake | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/dtool/Config.cmake b/dtool/Config.cmake index 9e14cd31b4..e8bfd4c0ac 100644 --- a/dtool/Config.cmake +++ b/dtool/Config.cmake @@ -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")