Skip to content

Commit 2445808

Browse files
committed
cmake: Use dedicated GENERATOR_IS_MULTI_CONFIG property
Available in CMake 3.9+.
1 parent 9f8703e commit 2445808

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

CMakeLists.txt

+18-15
Original file line numberDiff line numberDiff line change
@@ -171,21 +171,24 @@ mark_as_advanced(
171171
CMAKE_SHARED_LINKER_FLAGS_COVERAGE
172172
)
173173

174-
if(CMAKE_CONFIGURATION_TYPES)
175-
set(CMAKE_CONFIGURATION_TYPES "RelWithDebInfo" "Release" "Debug" "MinSizeRel" "Coverage")
176-
endif()
177-
178-
get_property(cached_cmake_build_type CACHE CMAKE_BUILD_TYPE PROPERTY TYPE)
179-
if(cached_cmake_build_type)
174+
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
175+
set(default_build_type "RelWithDebInfo")
176+
if(is_multi_config)
177+
set(CMAKE_CONFIGURATION_TYPES "${default_build_type}" "Release" "Debug" "MinSizeRel" "Coverage" CACHE STRING
178+
"Supported configuration types."
179+
FORCE
180+
)
181+
else()
180182
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY
181-
STRINGS "RelWithDebInfo" "Release" "Debug" "MinSizeRel" "Coverage"
183+
STRINGS "${default_build_type}" "Release" "Debug" "MinSizeRel" "Coverage"
182184
)
183-
endif()
184-
185-
set(default_build_type "RelWithDebInfo")
186-
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
187-
message(STATUS "Setting build type to \"${default_build_type}\" as none was specified")
188-
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE)
185+
if(NOT CMAKE_BUILD_TYPE)
186+
message(STATUS "Setting build type to \"${default_build_type}\" as none was specified")
187+
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING
188+
"Choose the type of build."
189+
FORCE
190+
)
191+
endif()
189192
endif()
190193

191194
include(TryAddCompileOption)
@@ -279,15 +282,15 @@ message("CFLAGS ................................ ${CMAKE_C_FLAGS}")
279282
get_directory_property(compile_options COMPILE_OPTIONS)
280283
string(REPLACE ";" " " compile_options "${compile_options}")
281284
message("Compile options ....................... " ${compile_options})
282-
if(DEFINED CMAKE_BUILD_TYPE)
285+
if(NOT is_multi_config)
283286
message("Build type:")
284287
message(" - CMAKE_BUILD_TYPE ................... ${CMAKE_BUILD_TYPE}")
285288
string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type)
286289
message(" - CFLAGS ............................. ${CMAKE_C_FLAGS_${build_type}}")
287290
message(" - LDFLAGS for executables ............ ${CMAKE_EXE_LINKER_FLAGS_${build_type}}")
288291
message(" - LDFLAGS for shared libraries ....... ${CMAKE_SHARED_LINKER_FLAGS_${build_type}}")
289292
else()
290-
message("Available configurations .............. ${CMAKE_CONFIGURATION_TYPES}")
293+
message("Supported configurations .............. ${CMAKE_CONFIGURATION_TYPES}")
291294
message("RelWithDebInfo configuration:")
292295
message(" - CFLAGS ............................. ${CMAKE_C_FLAGS_RELWITHDEBINFO}")
293296
message(" - LDFLAGS for executables ............ ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}")

0 commit comments

Comments
 (0)