Skip to content

Commit 8923d47

Browse files
committed
cmake: Do not hard-code CMAKE_CONFIGURATION_TYPES
The initial idea was to place the desired default build configuration first in `CMAKE_CONFIGURATION_TYPES`. The "Ninja Multi-Config" generator treats the first configuration as the default, but this is not the case for other generators. This change uses the dedicated `CMAKE_DEFAULT_BUILD_TYPE` variable for the same purpose, avoiding hard-coding `CMAKE_CONFIGURATION_TYPES` and preserving users' settings, if any.
1 parent d2bd95f commit 8923d47

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

CMakeLists.txt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,10 @@ mark_as_advanced(
177177
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
178178
if(PROJECT_IS_TOP_LEVEL)
179179
set(default_build_type "RelWithDebInfo")
180-
if(is_multi_config)
181-
set(CMAKE_CONFIGURATION_TYPES "${default_build_type}" "Release" "Debug" "MinSizeRel" "Coverage" CACHE STRING
182-
"Supported configuration types."
183-
FORCE
184-
)
185-
else()
180+
if(CMAKE_GENERATOR STREQUAL "Ninja Multi-Config")
181+
# Specify the configuration to use by default in the "Ninja Multi-Config" generator.
182+
set(CMAKE_DEFAULT_BUILD_TYPE ${default_build_type} CACHE STRING "")
183+
elseif(NOT is_multi_config)
186184
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY
187185
STRINGS "${default_build_type}" "Release" "Debug" "MinSizeRel" "Coverage"
188186
)
@@ -194,6 +192,7 @@ if(PROJECT_IS_TOP_LEVEL)
194192
)
195193
endif()
196194
endif()
195+
unset(default_build_type)
197196
endif()
198197

199198
include(TryAppendCFlags)

0 commit comments

Comments
 (0)