From cd89b7b61976a5302a683998b60dc66c8bc3018d Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Fri, 16 Jul 2021 18:22:35 +0200 Subject: [PATCH] CMake: Fix Windows -debug-and-release builds with CMake 3.21.0 CMake 3.21.0 introduced a regression where per-config sources can't be specified for object libs when building Qt with Ninja Multi-Config and cross-config mode on. We hit that in our Windows resource compiler handling. To work around the issue, pass the config-specific sources directly to the target rather than via an object library, when using CMake 3.20 or later. The original issue of not being able to do that has been fixed in 3.20. Amends ba6175eb731927f2489cdd7d899616a9889aba67 Amends a1ccedeb440216dce87fad01746935a89fd8715e Amends 657fa0462d552110e2ba14bcac46275e6066993f Pick-to: 6.2 Fixes: QTBUG-95229 Change-Id: Idea6d5bcc54b3124c66c45538c2e06e92f288f5f Reviewed-by: Cristian Adam --- src/corelib/Qt6CoreMacros.cmake | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake index f9393a2b07..42116cba69 100644 --- a/src/corelib/Qt6CoreMacros.cmake +++ b/src/corelib/Qt6CoreMacros.cmake @@ -1361,10 +1361,24 @@ END # We would like to do the following: # target_sources(${target} PRIVATE "$<$:${output}>") - # However, https://gitlab.kitware.com/cmake/cmake/-/issues/20682 doesn't let us. - # Work-around by compiling the resources in an object lib and linking that. - add_library(${target}_rc OBJECT "${output}") - target_link_libraries(${target} PRIVATE $) + # + # However, https://gitlab.kitware.com/cmake/cmake/-/issues/20682 doesn't let us do that + # in CMake 3.19 and earlier. + # We can do it in CMake 3.20 and later. + # And we have to do it with CMake 3.21.0 to avoid a different issue + # https://gitlab.kitware.com/cmake/cmake/-/issues/22436 + # + # So use the object lib work around for <= 3.19 and target_sources directly for later + # versions. + set(use_obj_lib FALSE) + set(end_target "${target}") + if(CMAKE_VERSION VERSION_LESS 3.20) + set(use_obj_lib TRUE) + set(end_target "${target}_rc") + add_library(${target}_rc OBJECT "${output}") + target_link_libraries(${target} PRIVATE $) + endif() + while(outputs) list(POP_FRONT cfgs cfg) list(POP_FRONT outputs output) @@ -1373,7 +1387,7 @@ END DEPENDS "${input}" COMMAND ${CMAKE_COMMAND} -E copy_if_different "${input}" "${output}" ) - target_sources(${target}_rc PRIVATE "$<$:${output}>") + target_sources(${end_target} PRIVATE "$<$:${output}>") endwhile() endif() endfunction()