Browse Source

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.
Donny Lawrence 6 years ago
parent
commit
27fd87983a
1 changed files with 21 additions and 4 deletions
  1. 21 4
      dtool/Config.cmake

+ 21 - 4
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")