summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandru Croitor <[email protected]>2025-06-27 14:30:29 +0200
committerAlexandru Croitor <[email protected]>2025-06-28 12:08:15 +0200
commit9e05e86f973fc820f8fba4ea6edbfb210eeae1b5 (patch)
tree84da43526c70b85e7301f1417d5234b596224702
parente5510913a14d5a92a64a8e6ebf7524c01b1f739e (diff)
CMake: Work around AUTOGEN discarded dependencies for in-tree examplesHEADdev
When building qt examples in-tree, in a cross-compiling case, with a CMake version lower than 4.0, we lose AUTOGEN dependencies due to a bug in cmake. To ensure the dependencies are not lost, we need to apply the same workaround we did for internal Qt targets. For targets created by Qt's public API, we now query the target's LINK_LIBRARIES and INTERFACE_LINK_LIBRARIES at finalizer time, and add them to the AUTOGEN dependencies. The implementation is also modified to remove duplicates. We only apply the behavior in public API when QT_BUILDING_QT is true, to reduce the risk for regular user projects. The assumption here is when building a user project, Qt is already fully built, so we don't need to ensure that Qt's sync headers and autogen targets are up to date. Pick-to: 6.5 6.8 6.9 6.10 Fixes: QTBUG-137587 Task-number: QTBUG-133725 Change-Id: I61bd799ca39d92702ca0fc48d54bb517fc55baeb Reviewed-by: Alexey Edelev <[email protected]>
-rw-r--r--cmake/QtPublicTargetHelpers.cmake33
-rw-r--r--src/corelib/Qt6CoreMacros.cmake2
2 files changed, 34 insertions, 1 deletions
diff --git a/cmake/QtPublicTargetHelpers.cmake b/cmake/QtPublicTargetHelpers.cmake
index e0be0b740e7..27f7c3acf79 100644
--- a/cmake/QtPublicTargetHelpers.cmake
+++ b/cmake/QtPublicTargetHelpers.cmake
@@ -61,10 +61,41 @@ function(_qt_internal_work_around_autogen_discarded_dependencies target)
endif()
endforeach()
if(final_libraries)
- set_property(TARGET ${target} APPEND PROPERTY AUTOGEN_TARGET_DEPENDS "${final_libraries}")
+ _qt_internal_append_to_target_property_without_duplicates("${target}"
+ AUTOGEN_TARGET_DEPENDS ${final_libraries})
endif()
endfunction()
+# This function is similar to _qt_internal_work_around_autogen_discarded_dependencies
+# but it instead queries the libs to process from the target's LINK_LIBRARIES and
+# INTERFACE_LINK_LIBRARIES.
+# It only applies the logic while building Qt itself.
+# It's meant to be used in public API like qt_finalize_target, so that the workaround is applied
+# to examples that are built as part of the qt build tree.
+function(_qt_internal_work_around_autogen_discarded_dependencies_from_target_libs target)
+ if(NOT QT_BUILDING_QT)
+ return()
+ endif()
+
+ set(libraries "")
+
+ get_target_property(link_libs "${target}" LINK_LIBRARIES)
+ if(link_libs)
+ list(APPEND libraries "${link_libs}")
+ endif()
+ get_target_property(interface_link_libs "${target}" INTERFACE_LINK_LIBRARIES)
+
+ if(interface_link_libs)
+ list(APPEND libraries "${interface_link_libs}")
+ endif()
+
+ if(NOT libraries)
+ return()
+ endif()
+
+ _qt_internal_work_around_autogen_discarded_dependencies("${target}" ${libraries})
+endfunction()
+
# Tests if linker could resolve circular dependencies between object files and static libraries.
function(__qt_internal_static_link_order_public_test result)
# We could trust iOS linker
diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake
index fd938f0b1c2..3f5f9180805 100644
--- a/src/corelib/Qt6CoreMacros.cmake
+++ b/src/corelib/Qt6CoreMacros.cmake
@@ -831,6 +831,8 @@ function(qt6_finalize_target target)
endif()
endif()
+ _qt_internal_work_around_autogen_discarded_dependencies_from_target_libs("${target}")
+
get_target_property(is_immediately_finalized "${target}" _qt_is_immediately_finalized)
get_target_property(uses_automoc ${target} AUTOMOC)
if(uses_automoc)