From 683dca1948f883d8f83c2839e6fae2960e1bfc77 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Mon, 22 Jan 2024 17:18:41 +0100 Subject: CMake: Fix sqldrivers project to allow building as Debug MSVC config When the user: - has a non-developer-build -debug-and-release Qt - and tries to configure the sqldrivers project with -DCMAKE_BUILD_TYPE=Debug our build system discarded the user request, and defaulted to 'Release'. That happens because CMake sets CMAKE_BUILD_TYPE_INIT to 'Debug' by default on Windows-MSVC, and we have no marker to differentiate that the 'Debug' value was user-specified. We have such a marker - via the __qt_auto_detect_cmake_build_type_before_project_call variable when configuring qtbase / top-level qt - via the __qt_toolchain_cmake_build_type_before_project_call variable when configuring via the qt toolchain file (although that doesn't apply when configuring a multi-config build for obscure reasons, which should be addressed). A conservative fix is to add a new variable / marker called __qt_internal_standalone_project_cmake_build_type_before_project_call which the 'sqldrivers' project will set with the build type that is detected before the first project() call, and use that to decide whether to override the build type, similar how we do with toolchain file variable. We could reuse one of the previous variables, but I figured it's better to be explicit with a new one. And hopefully we can clean up the whole logic in a follow-up commit. Amends 48841c34d2e86a741ec9992b9704c0fa5973503c Amends 8c912cddebe544010e7da3f87af5b21f3328d7ec Pick-to: 6.5 Fixes: QTBUG-120436 Task-number: QTBUG-114958 Change-Id: I37e3d8041088fe6084a9976ecc80ddd62d73ef81 Reviewed-by: Alexey Edelev (cherry picked from commit 5b5fa7b75a2465e085c7df61c64755bb65b51f1c) Reviewed-by: Qt Cherry-pick Bot (cherry picked from commit e07404343de80f8c3d3046322ec45ca469508a49) --- src/plugins/sqldrivers/CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/plugins') diff --git a/src/plugins/sqldrivers/CMakeLists.txt b/src/plugins/sqldrivers/CMakeLists.txt index 7f44072da0..e3254a762d 100644 --- a/src/plugins/sqldrivers/CMakeLists.txt +++ b/src/plugins/sqldrivers/CMakeLists.txt @@ -4,6 +4,14 @@ cmake_minimum_required(VERSION 3.16) if (NOT CMAKE_PROJECT_NAME STREQUAL "QtBase" AND NOT CMAKE_PROJECT_NAME STREQUAL "Qt") include(.cmake.conf) + # Store initial build type (if any is specified) to be read by + # qt_internal_set_default_build_type(). + # See qt_internal_set_default_build_type() for details. + if(DEFINED CACHE{CMAKE_BUILD_TYPE}) + set(__qt_internal_standalone_project_cmake_build_type_before_project_call + "${CMAKE_BUILD_TYPE}") + endif() + project(QSQLiteDriverPlugins VERSION "${QT_REPO_MODULE_VERSION}" DESCRIPTION "Qt6 SQL driver plugins" -- cgit v1.2.3