CMake: Support build config-related configure options

This add support for the following options: -debug, -release,
-debug-and-release. For the latter, the "Ninja Multi-Config" generator
is auto-detected, if ninja is available.

Task-number: QTBUG-85373
Change-Id: Ide0ca44e5f4c74657147e89d71e8d71c4f6a4c45
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Joerg Bornemann 2020-07-03 18:23:47 +02:00
parent ab559e25af
commit dd77597252

View File

@ -31,6 +31,7 @@ list(FILTER configure_args EXCLUDE REGEX "^[ \t]*$")
list(TRANSFORM configure_args STRIP)
unset(generator)
set(auto_detect_generator TRUE)
unset(build_configs)
while(configure_args)
list(POP_FRONT configure_args arg)
if(arg STREQUAL "-cmake")
@ -105,6 +106,12 @@ while(configure_args)
elseif(arg STREQUAL "-plugindir")
list(POP_FRONT configure_args dir)
push("-DINSTALL_PLUGINSDIR=${dir}")
elseif(arg STREQUAL "-release")
set(build_configs "Release")
elseif(arg STREQUAL "-debug")
set(build_configs "Debug")
elseif(arg STREQUAL "-debug-and-release")
set(build_configs Debug Release)
elseif(arg STREQUAL "--")
# Everything after this argument will be passed to CMake verbatim.
push(${configure_args})
@ -114,10 +121,24 @@ while(configure_args)
endif()
endwhile()
list(LENGTH build_configs nr_of_build_configs)
if(nr_of_build_configs EQUAL 1)
push("-DCMAKE_BUILD_TYPE=${build_configs}")
elseif(nr_of_build_configs GREATER 1)
set(multi_config ON)
string(REPLACE ";" "\\;" escaped_build_configs "${build_configs}")
# We must not use the push macro here to avoid variable expansion.
# That would destroy our escaping.
list(APPEND cmake_args "-DCMAKE_CONFIGURATION_TYPES=${escaped_build_configs}")
endif()
if(NOT generator AND auto_detect_generator)
find_program(ninja ninja)
if(ninja)
set(generator Ninja)
if(multi_config)
string(APPEND generator " Multi-Config")
endif()
else()
if(CMAKE_HOST_UNIX)
set(generator "Unix Makefiles")