diff --git a/CMakeLists.txt b/CMakeLists.txt index 7fc538067c..f5f03be4d3 100644 --- a/CMakeLists.txt +++ b/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}") diff --git a/dtool/Config.cmake b/dtool/Config.cmake index 24f5680cf4..1b04a19936 100644 --- a/dtool/Config.cmake +++ b/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?