From c359af7bfbc3f585326d3933d8d34256e4c285f8 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Wed, 10 Jul 2024 08:36:02 +0200 Subject: [PATCH] CMake: Fix exposing source files after target finalization Calling _qt_internal_expose_source_file_to_ide after a target has already been finalized did run the function's fallback code for targets that are not finalized at all. That added the source files under a new ${target}_other_files target, which is a tad ugly in an IDE. A situation where this occurs is for instance: - qt_add_executable in a subdirectory - adding additional files (licenses, documentation, .ts files) to the "main" target in the top-level CMakeLists.txt The code flow is like this: - enter subdirectory - qt6_add_executable(foo) - leave subdirectory - qt6_finalize_target(foo) - calls _qt_internal_expose_deferred_files_to_ide(foo) - _qt_internal_expose_source_file_to_ide(foo bar.txt) - sees that the target does not need finalization and runs the fallback code Fix this by immediately running _qt_internal_expose_deferred_files_to_ide if a target was already finalized. Task-number: QTBUG-127052 Change-Id: I1eda9acd48442ba35c6c61d9a185f6ed9ed6307f Reviewed-by: Alexandru Croitor (cherry picked from commit 469533fe8108cc56e90201919126502235c5cee6) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/Qt6CoreMacros.cmake | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake index ff499016096..81ee285aded 100644 --- a/src/corelib/Qt6CoreMacros.cmake +++ b/src/corelib/Qt6CoreMacros.cmake @@ -2115,8 +2115,17 @@ endfunction() function(_qt_internal_expose_source_file_to_ide target file) get_target_property(target_expects_finalization ${target} _qt_expects_finalization) if(target_expects_finalization AND CMAKE_VERSION VERSION_GREATER_EQUAL "3.19") + # The target is not yet finalized. The target finalizer will call the exposure function. set_property(TARGET ${target} APPEND PROPERTY _qt_deferred_files ${file}) return() + else() + get_target_property(is_finalized "${target}" _qt_is_finalized) + if(is_finalized) + # The target already has been finalized. Run the exposure function immediately. + set_property(TARGET ${target} APPEND PROPERTY _qt_deferred_files ${file}) + _qt_internal_expose_deferred_files_to_ide(${target}) + return() + endif() endif() # Fallback for targets that are not finalized: Create fake target under which the file is added.