From 6fc1214133eab642aaefd1481f28fce4f58e43e6 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Fri, 13 Jan 2023 15:14:03 +0100 Subject: [PATCH] CMake: Fix exposing sources with absolute path to IDE _qt_internal_expose_deferred_files_to_ide must add the source files to the target exactly as they were passed to _qt_internal_expose_source_file_to_ide. Otherwise, CMake might be fooled into thinking that we're adding a new file here, and source file properties would not be readable. Instead of back-calculating the relative paths from the absolute paths, we use the already existing list of relative paths. Fixes: QTBUG-109678 Change-Id: I81510f37eacb409eb5c03e3ff032926c3ca25a1f Reviewed-by: Alexey Edelev (cherry picked from commit c146d25a87bcb94ed4eefae749a96ed3550b7af2) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/Qt6CoreMacros.cmake | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake index f5e93d6b14b..f8d532f579c 100644 --- a/src/corelib/Qt6CoreMacros.cmake +++ b/src/corelib/Qt6CoreMacros.cmake @@ -1737,6 +1737,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) @@ -1747,25 +1748,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() #