fix(cmake): respect multi-config generators

- Set a default CMAKE_BUILD_TYPE only for single-config generators
- Stop overriding CMAKE_CONFIGURATION_TYPES
- Do not require CMAKE_BUILD_TYPE when generating the package config

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Claude
2026-11-09 22:13:08 +00:00
committed by Dennis Klein
parent b6407c53a4
commit 29060378b7
2 changed files with 12 additions and 5 deletions

View File

@@ -13,10 +13,12 @@ include(GNUInstallDirs)
string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWER)
string(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPER)
# Set a default build type
if(NOT CMAKE_BUILD_TYPE)
# Set a default build type (multi-config generators select it at build time)
get_property(_is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(NOT _is_multi_config AND NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif()
unset(_is_multi_config)
set(PROJECT_MIN_CXX_STANDARD 17)
@@ -111,7 +113,6 @@ if(_sanitizers)
endif()
# Configure build types
set(CMAKE_CONFIGURATION_TYPES "Debug" "Release" "RelWithDebInfo")
set(_warnings "-Wshadow -Wall -Wextra -Wpedantic")
set(CMAKE_CXX_FLAGS_DEBUG "-Og -g ${_warnings} ${_sanitizers}")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")