diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake index dc5afae6c5..206ce8f21e 100644 --- a/src/corelib/Qt6CoreMacros.cmake +++ b/src/corelib/Qt6CoreMacros.cmake @@ -1744,6 +1744,7 @@ function(_qt_internal_expose_deferred_files_to_ide target) list(APPEND new_sources_real ${realf}) endforeach() + set(filtered_new_sources "") get_target_property(target_source_dir ${target} SOURCE_DIR) get_filename_component(target_source_dir "${target_source_dir}" REALPATH) get_target_property(existing_sources ${target} SOURCES) @@ -1754,25 +1755,28 @@ function(_qt_internal_expose_deferred_files_to_ide target) get_filename_component(realf "${f}" REALPATH BASE_DIR ${target_source_dir}) list(APPEND existing_sources_real ${realf}) endforeach() - list(REMOVE_ITEM new_sources_real ${existing_sources_real}) + + list(LENGTH new_sources max_i) + math(EXPR max_i "${max_i} - 1") + foreach(i RANGE 0 ${max_i}) + list(GET new_sources_real ${i} realf) + if(NOT realf IN_LIST existing_sources_real) + list(GET new_sources ${i} f) + list(APPEND filtered_new_sources ${f}) + endif() + endforeach() endif() - if("${new_sources_real}" STREQUAL "") + if("${filtered_new_sources}" STREQUAL "") return() endif() - # Need to convert real paths back to relative paths because the use of absolute paths for these - # files causes invalid generation of build.ninja on Windows platforms. - set(new_sources "") - foreach(realf IN LISTS new_sources_real) - file(RELATIVE_PATH f "${target_source_dir}" "${realf}") - list(APPEND new_sources "${f}") - endforeach() - target_sources(${target} PRIVATE ${new_sources}) + target_sources(${target} PRIVATE ${filtered_new_sources}) set(scope_args) if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.18") set(scope_args TARGET_DIRECTORY "${target}") endif() - set_source_files_properties(${new_sources} ${scope_args} PROPERTIES HEADER_FILE_ONLY ON) + set_source_files_properties(${filtered_new_sources} + ${scope_args} PROPERTIES HEADER_FILE_ONLY ON) endfunction() #