From 90b07054f6de3ad101416b1ab5a10d7fee801a1c Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Tue, 8 Feb 2022 17:23:20 +0100 Subject: CMake: Assign proper postfixes in multi-config builds In a single-config build on Linux, we usually don't want a debug postfix in library names (as opposed to Windows/macOS). But when doing a multi-config build on Linux, assigning no postfixes causes CMake to generate rules for a single config only, the first one specified in CMAKE_CONFIGURATION_TYPES. This leads to being unable to build all configurations from the same build.ninja file as well as other obscure issues like race-conditions when generating prl files. To address this, when doing a multi-config build, always assign a postfix for each config except the first release-like one, while preserving the existing rules we had for debug postfix names. Pick-to: 6.2 6.3 Fixes: QTBUG-100493 Change-Id: Ie9c88e074abdcf2961d7b3dee19a5694292717b8 Reviewed-by: Alexey Edelev --- cmake/QtSetup.cmake | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'cmake') diff --git a/cmake/QtSetup.cmake b/cmake/QtSetup.cmake index ee42e9e785..7db9612cd9 100644 --- a/cmake/QtSetup.cmake +++ b/cmake/QtSetup.cmake @@ -39,8 +39,35 @@ else() message(STATUS "CMAKE_BUILD_TYPE was set to: '${CMAKE_BUILD_TYPE}'") endif() -# Appends a 'debug postfix' to library targets (not executables) -# e.g. lib/libQt6DBus_debug.5.12.0.dylib +# Append a config-specific postfix to library names to ensure distinct names +# in a multi-config build. +# e.g. lib/libQt6DBus_relwithdebinfo.6.3.0.dylib +# Don't apply the postfix to the first encountered release-like config, so we have at least one +# config without a postifx. +if(QT_GENERATOR_IS_MULTI_CONFIG AND CMAKE_CONFIGURATION_TYPES) + set(__qt_setup_release_configs Release RelWithDebInfo MinSizeRel) + set(__qt_setup_found_first_release_config FALSE) + foreach(__qt_setup_config_type IN LISTS CMAKE_CONFIGURATION_TYPES) + # Skip assigning postfix for the first release-like config. + if(NOT __qt_setup_found_first_release_config + AND __qt_setup_config_type IN_LIST __qt_setup_release_configs) + set(__qt_setup_found_first_release_config TRUE) + continue() + endif() + + string(TOLOWER "${__qt_setup_config_type}" __qt_setup_config_type_lower) + string(TOUPPER "${__qt_setup_config_type}" __qt_setup_config_type_upper) + set(CMAKE_${__qt_setup_config_type_upper}_POSTFIX "_${__qt_setup_config_type_lower}") + if(APPLE) + set(CMAKE_FRAMEWORK_MULTI_CONFIG_POSTFIX_${__qt_setup_config_type_upper} + "_${__qt_setup_config_type_lower}") + endif() + endforeach() +endif() + +# Override the generic debug postfixes above with custom debug postfixes (even in a single config +# build) to follow the conventions we had since Qt 5. +# e.g. lib/libQt6DBus_debug.6.3.0.dylib if(WIN32) if(MINGW) # On MinGW we don't have "d" suffix for debug libraries like on Linux, -- cgit v1.2.1