Browse Source

CMake: properly default build type to Standard

This wasn't being set properly because it needs to be set before the project() call
rdb 5 years ago
parent
commit
565f97b3b9
2 changed files with 33 additions and 30 deletions
  1. 33 0
      CMakeLists.txt
  2. 0 30
      dtool/Config.cmake

+ 33 - 0
CMakeLists.txt

@@ -19,6 +19,39 @@ if(POLICY CMP0091)
   cmake_policy(SET CMP0091 NEW)
 endif()
 
+# Determine whether we are using a multi-config generator.
+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.
+set(_configs Standard Release RelWithDebInfo Debug MinSizeRel)
+if(CMAKE_CXX_COMPILER_ID MATCHES "(AppleClang|Clang|GCC)")
+  list(APPEND _configs Coverage)
+endif()
+
+if(IS_MULTICONFIG)
+  message(STATUS "Using multi-configuration generator")
+  set(CMAKE_CONFIGURATION_TYPES ${_configs})
+else()
+  # Set the default CMAKE_BUILD_TYPE before calling project().
+  if(NOT CMAKE_BUILD_TYPE)
+    set(CMAKE_BUILD_TYPE Standard CACHE STRING "Choose the type of build." FORCE)
+    message(STATUS "Using default build type ${CMAKE_BUILD_TYPE}")
+  else()
+    message(STATUS "Using build type ${CMAKE_BUILD_TYPE}")
+  endif()
+  set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${_configs})
+endif()
+
 # Figure out the version
 set(_s "[\\t ]*") # CMake doesn't support \s*
 file(STRINGS "setup.cfg" _version REGEX "^version${_s}=${_s}")

+ 0 - 30
dtool/Config.cmake

@@ -22,36 +22,6 @@ 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.
-
-set(_configs Standard Release RelWithDebInfo Debug MinSizeRel)
-if(DEFINED CMAKE_CXX_FLAGS_COVERAGE)
-  list(APPEND _configs Coverage)
-endif()
-
-if(IS_MULTICONFIG)
-  set(CMAKE_CONFIGURATION_TYPES ${_configs})
-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 Standard)
-  endif()
-  set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${_configs})
-endif()
-
 set(PER_CONFIG_OPTIONS)
 
 # Are we building with static or dynamic linking?