diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake index d014ebf5d9..bcb76d4256 100644 --- a/src/corelib/Qt6CoreMacros.cmake +++ b/src/corelib/Qt6CoreMacros.cmake @@ -1673,9 +1673,11 @@ function(_qt_internal_expose_deferred_files_to_ide target) endforeach() 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) if(existing_sources) set(existing_sources_real "") + set(realf "") foreach(f IN LISTS existing_sources) get_filename_component(realf "${f}" REALPATH BASE_DIR ${target_source_dir}) list(APPEND existing_sources_real ${realf}) @@ -1685,12 +1687,20 @@ function(_qt_internal_expose_deferred_files_to_ide target) if("${new_sources_real}" STREQUAL "") return() endif() - target_sources(${target} PRIVATE ${new_sources_real}) + # 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}) set(scope_args) if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.18") set(scope_args TARGET_DIRECTORY "${target}") endif() - set_source_files_properties(${new_sources_real} ${scope_args} PROPERTIES HEADER_FILE_ONLY ON) + set_source_files_properties(${new_sources} ${scope_args} PROPERTIES HEADER_FILE_ONLY ON) endfunction() #