From 8cf1b2b53acfd26014d0b7370b8c45708dd35faf Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Wed, 26 Jul 2023 14:37:09 +0200 Subject: [PATCH] CMake: Make sure to follow BuildInternals CMAKE_BUILD_TYPE on Windows A regression was introduced in 48841c34d2e86a741ec9992b9704c0fa5973503c 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 33af62db3747bb6fcb7490ef2d2abc5bb53925b6 Amends 48841c34d2e86a741ec9992b9704c0fa5973503c Fixes: QTBUG-114958 Change-Id: I5e0a27b4d77512494c026dd911ec5757889a5a1a Reviewed-by: Laszlo Agocs Reviewed-by: Alexey Edelev (cherry picked from commit 8c912cddebe544010e7da3f87af5b21f3328d7ec) --- cmake/QtBuildInternalsExtra.cmake.in | 1 + cmake/QtSetup.cmake | 1 + 2 files changed, 2 insertions(+) diff --git a/cmake/QtBuildInternalsExtra.cmake.in b/cmake/QtBuildInternalsExtra.cmake.in index 2917c2290fd..c035a216f5b 100644 --- a/cmake/QtBuildInternalsExtra.cmake.in +++ b/cmake/QtBuildInternalsExtra.cmake.in @@ -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() diff --git a/cmake/QtSetup.cmake b/cmake/QtSetup.cmake index f9ddd87313e..ab8d158f342 100644 --- a/cmake/QtSetup.cmake +++ b/cmake/QtSetup.cmake @@ -61,6 +61,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)