From 847b4915203e5f4a6d9c1f7d0c4f548e068842fe Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Wed, 30 Oct 2024 16:51:10 +0100 Subject: [PATCH] CMake: Fix qt_add_resources calls in different directory scopes "Different" meaning here "different from the target's directory scope". Consider a qt_add_resources call in a directory scope that's different from the target's directory scope. Then CMake's AUTORCC would pick up the generated .qrc file. This leads to duplicate symbols errors in the linking phase. The reason for that is that we add the .qrc file as source file to the target, and the SKIP_AUTOGEN property is ineffective, because we're setting it without the TARGET_DIRECTORY option. This situation occurs, for example, with a qt_add_translations call in the top-level CMakeLists.txt on a AUTORCC-enabled target that's defined in a subdirectory. Fix this by adding the TARGET_DIRECTORY option when setting SKIP_AUTOGEN on the generated .qrc file. Pick-to: 6.5 Fixes: QTBUG-130056 Change-Id: Iedc847eb85d918c5a1df20cb477e3192d1138b7f Reviewed-by: Alexandru Croitor (cherry picked from commit d516a452232bd9b969db19a62586e969dfc54b39) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/Qt6CoreMacros.cmake | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake index 489a489efd0..47b3b42150e 100644 --- a/src/corelib/Qt6CoreMacros.cmake +++ b/src/corelib/Qt6CoreMacros.cmake @@ -2383,7 +2383,12 @@ function(_qt_internal_process_resource target resourceName) list(APPEND rccArgsAllPasses "--no-zstd") endif() - set_property(SOURCE "${generatedResourceFile}" PROPERTY SKIP_AUTOGEN ON) + # Disable AUTOGEN on the generated .qrc file. + set(scope_args "") + if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.18") + set(scope_args TARGET_DIRECTORY ${target}) + endif() + set_property(SOURCE "${generatedResourceFile}" ${scope_args} PROPERTY SKIP_AUTOGEN ON) # Set output file name for rcc command if(isBinary)