cmake_initialize_per_config_variable does not respect the value of CMAKE_CONFIGURATION_TYPES
This function hardcodes the set of configurations to Debug Release MinSizeRel RelWithDebInfo
. This is obviously not correct in the case where the user has set CMAKE_CONFIGURATION_TYPES to a different list of configuration names.
It doesn't look completely broken, because in the case of a multi-config generator it appends CMAKE_CONFIGURATION_TYPES, and in the case of a single-config generator it appends CMAKE_BUILD_TYPE. So in principle this works. But it makes debugging scripts difficult, because for single config generators only the variable for the config you've specified will be updated, which means if you're debugging your script you have to configure every possible way. How about this logic instead?
if (NOT CMAKE_NOT_USING_CONFIG_FLAGS)
if (CMAKE_CONFIGURATION_TYPES)
set(_CONFIGS ${CMAKE_CONFIGURATION_TYPES})
else()
set(_CONFIGS Debug Release MinSizeRel RelWithDebInfo)
endif()
get_property(_GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if (NOT _GENERATOR_IS_MULTI_CONFIG AND NOT CMAKE_NO_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE_INIT}" CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel ...")
endif()