Fix the way deffered files are added to a CMake source tree

Use relative paths when adding deffered files to the target sources.
The use of real paths causes issues in the build.ninja file on
Windows platforms.

Amends 3df618b8d9

Task-number: QTBUG-99808
Change-Id: I15b7c695e5f281f2a0ee96ba25ef27baa74ebd37
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
bb10
Alexey Edelev 2022-09-16 18:24:35 +02:00
parent 072387edec
commit 3800bcf526
1 changed files with 12 additions and 2 deletions

View File

@ -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()
#