From baddc0a1958c8ea9cb946465c93ecdd62bde9d3d Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Tue, 7 Jan 2025 18:16:29 +0100 Subject: [PATCH] CMake: Build executables in single-config debug-and-release builds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If qtbase is configured with -debug-and-release -force-debug-info, which maps to '-GNinja Multi-Config' '-DCMAKE_CONFIGURATION_TYPES=RelWIthDebInfo;Debug' and then qtopcua is configured with -GNinja -DCMAKE_BUILD_TYPE=Release building the 'all' target would not build executables or tools. That's because the targets have their EXCLUDE_FROM_ALL property set to exclude any non-first multi-config, and Release doesn't match RelWithDebInfo. Such a scenario can happen for our multi-config windows builds, when someone tries to build a repo not with qt-configure-module but rather with cmake directly. They would then not specify the same build types or generator, which can happen when opening in an IDE like Qt Creator. Make sure to also check if the current generator is a multi-config one, in addition to whether QT_FEATURE_debug_and_release is ON, before adding the genex to the EXCLUDE_FROM_ALL property. This allows building and installing executables and tools in such a scenario, because in a single config build, the genex would not be added, even if QT_FEATURE_debug_and_release is ON. Pick-to: 6.8 6.9 Fixes: QTBUG-132609 Task-number: QTBUG-132338 Change-Id: Iaee1a0afb19df97ee1263dbaf27c8e29fc127831 Reviewed-by: Jannis Völker Reviewed-by: Alexey Edelev --- cmake/QtExecutableHelpers.cmake | 7 ++++++- cmake/QtToolHelpers.cmake | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cmake/QtExecutableHelpers.cmake b/cmake/QtExecutableHelpers.cmake index 4c96c811e96..608d52437ea 100644 --- a/cmake/QtExecutableHelpers.cmake +++ b/cmake/QtExecutableHelpers.cmake @@ -71,7 +71,12 @@ function(qt_internal_add_executable name) endif() endif() - if(arg_QT_APP AND QT_FEATURE_debug_and_release AND CMAKE_VERSION VERSION_GREATER_EQUAL "3.19.0") + get_cmake_property(is_multi_config GENERATOR_IS_MULTI_CONFIG) + if(arg_QT_APP + AND QT_FEATURE_debug_and_release + AND CMAKE_VERSION VERSION_GREATER_EQUAL "3.19.0" + AND is_multi_config + ) set_property(TARGET "${name}" PROPERTY EXCLUDE_FROM_ALL "$>") endif() diff --git a/cmake/QtToolHelpers.cmake b/cmake/QtToolHelpers.cmake index 641b44f73a3..0b85ec58af1 100644 --- a/cmake/QtToolHelpers.cmake +++ b/cmake/QtToolHelpers.cmake @@ -168,7 +168,10 @@ function(qt_internal_add_tool target_name) APPEND PROPERTY EXPORT_PROPERTIES "_qt_package_version") - if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.19.0" AND QT_FEATURE_debug_and_release) + get_cmake_property(is_multi_config GENERATOR_IS_MULTI_CONFIG) + if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.19.0" + AND QT_FEATURE_debug_and_release + AND is_multi_config) set_property(TARGET "${target_name}" PROPERTY EXCLUDE_FROM_ALL "$>") endif()