I’ve been using CMake for quite a while and it’s quite common that I enforce the possible different build/configuration type on my project using similar code to this:
set(CMAKE_CONFIGURATION_TYPES "Debug" "Release")
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${CMAKE_CONFIGURATION_TYPES})
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build Type of the project" FORCE)
elseif(NOT CMAKE_BUILD_TYPE IN_LIST CMAKE_CONFIGURATION_TYPES)
message(FATAL_ERROR "Invalid build type \'${CMAKE_BUILD_TYPE}\'. Possible values: ${CMAKE_CONFIGURATION_TYPES}")
endif()
I wonder if that’s the correct way to handle strict enforcement/management of possible build types and it’s correct, why isn’t there standard command or procedure to do such? I don’t want people to build my project with incorrect build type, it makes no sense. And I do want to be able to support generation on both single and multiple configuration generators.
Is there something I’m missing?
I have not seen this use case come up often. Most projects I’ve seen just use the default behavior and don’t try to restrict the set of configurations like this. Doing so can make it harder to embed projects as subdirectories in other projects.