CMake: Make sure to follow BuildInternals CMAKE_BUILD_TYPE on Windows

A regression was introduced in
48841c34d2
when configuring qtshadertools with -prefix -debug and
no -developer-build.
qtbase would have been built as Debug, but qtshadertools as release.

This caused qsb.exe to link to a debug c++ runtime via QtCore, and a
release one via QtShaderTools libraries and thus cause heap corruption
crashes during runtime due to the mismatch.

This happened because the check in cmake/QtSetup.cmake thought Debug
was the default build type (nothing was specified on the command line)
without knowing it was explicitly set BuildInternals.

Set a variable when BuildInternals sets CMAKE_BUILD_TYPE and make
sure QtSetup does not override it then.

Augments 33af62db37
Amends 48841c34d2

Fixes: QTBUG-114958
Change-Id: I5e0a27b4d77512494c026dd911ec5757889a5a1a
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
Alexandru Croitor 2023-07-26 14:37:09 +02:00
parent 35d0f012ee
commit 8c912cddeb
2 changed files with 2 additions and 0 deletions

View File

@ -166,6 +166,7 @@ function(qt_internal_force_set_cmake_build_type_conditionally value)
AND NOT QT_NO_FORCE_SET_CMAKE_BUILD_TYPE
AND NOT __qt_internal_extras_is_multi_config)
set(CMAKE_BUILD_TYPE "${value}" CACHE STRING "Choose the type of build." FORCE)
set(__qt_build_internals_cmake_build_type "${value}" PARENT_SCOPE)
endif()
endfunction()

View File

@ -67,6 +67,7 @@ get_property(QT_GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CON
# to set the build type when building other repos or tests.
if("${CMAKE_BUILD_TYPE}" STREQUAL "${CMAKE_BUILD_TYPE_INIT}"
AND NOT __qt_auto_detect_cmake_build_type_before_project_call
AND NOT __qt_build_internals_cmake_build_type
AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${_default_build_type}' as none was specified.")
set(CMAKE_BUILD_TYPE "${_default_build_type}" CACHE STRING "Choose the type of build." FORCE)