Use `_qt_internal_set_source_file_generated`

Migrate implementations that set `GENERATED` source property

Also standardize the `TARGET_DIRECTORY` passing

Fixes: QTBUG-125077
Pick-to: 6.9 6.10
Change-Id: I0651ad69ec127b615b599707e12ab3840dc1135c
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Cristian Le 2025-06-23 17:08:41 +02:00
parent c9f9e70da7
commit 8e9e23b898
2 changed files with 64 additions and 63 deletions

View File

@ -21,7 +21,7 @@ function(qt_declarative_generate_reg_exp_jit_tables consuming_target)
) )
target_sources(${consuming_target} PRIVATE ${output_file}) target_sources(${consuming_target} PRIVATE ${output_file})
target_include_directories(${consuming_target} PRIVATE $<BUILD_INTERFACE:${generate_dir}>) target_include_directories(${consuming_target} PRIVATE $<BUILD_INTERFACE:${generate_dir}>)
_qt_internal_set_source_file_generated(SOURCES "${output_file}")
set_source_files_properties(${output_file} PROPERTIES set_source_files_properties(${output_file} PROPERTIES
GENERATED TRUE
_qt_non_module_header TRUE) _qt_non_module_header TRUE)
endfunction() endfunction()

View File

@ -804,9 +804,7 @@ Check https://doc.qt.io/qt-6/qt-cmake-policy-qtp0001.html for policy details."
if(NOT arg_NO_GENERATE_QMLDIR) if(NOT arg_NO_GENERATE_QMLDIR)
_qt_internal_target_generate_qmldir(${target}) _qt_internal_target_generate_qmldir(${target})
set_source_files_properties(${arg_OUTPUT_DIRECTORY}/qmldir _qt_internal_set_source_file_generated(SOURCES "${arg_OUTPUT_DIRECTORY}/qmldir")
PROPERTIES GENERATED TRUE
)
if(${arg___QT_INTERNAL_DISAMBIGUATE_QMLDIR_RESOURCE}) if(${arg___QT_INTERNAL_DISAMBIGUATE_QMLDIR_RESOURCE})
# TODO: Make this the default and remove the option # TODO: Make this the default and remove the option
@ -1792,17 +1790,17 @@ function(_qt_internal_target_enable_qmlcachegen target qmlcachegen)
$<TARGET_PROPERTY:${target},_qt_generated_qrc_files> $<TARGET_PROPERTY:${target},_qt_generated_qrc_files>
VERBATIM VERBATIM
) )
# We can't rely on policy CMP0118 since user project controls it
# The current scope sees the file as generated automatically, but the set(scope_args)
# target scope may not if it is different. Force it where we can.
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.18") if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.18")
set_source_files_properties( set(scope_args TARGET_DIRECTORY ${target})
${qmlcache_loader_cpp}
TARGET_DIRECTORY ${target}
PROPERTIES GENERATED TRUE
SKIP_AUTOGEN TRUE
)
endif() endif()
_qt_internal_set_source_file_generated(
SOURCES ${qmlcache_loader_cpp}
${scope_args}
SKIP_AUTOGEN
)
get_target_property(target_source_dir ${target} SOURCE_DIR) get_target_property(target_source_dir ${target} SOURCE_DIR)
if(NOT target_source_dir STREQUAL CMAKE_CURRENT_SOURCE_DIR) if(NOT target_source_dir STREQUAL CMAKE_CURRENT_SOURCE_DIR)
add_custom_target(${target}_qmlcachegen DEPENDS ${qmlcache_loader_cpp}) add_custom_target(${target}_qmlcachegen DEPENDS ${qmlcache_loader_cpp})
@ -2217,20 +2215,18 @@ function(_qt_internal_target_enable_qmltc target)
VERBATIM VERBATIM
) )
_qt_internal_set_source_file_generated(
SOURCES ${compiled_header} ${compiled_cpp}
SKIP_AUTOGEN
)
set_source_files_properties(${compiled_header} ${compiled_cpp} set_source_files_properties(${compiled_header} ${compiled_cpp}
PROPERTIES SKIP_AUTOGEN ON PROPERTIES
SKIP_UNITY_BUILD_INCLUSION ON) SKIP_UNITY_BUILD_INCLUSION ON)
target_sources(${target} PRIVATE ${compiled_header} ${compiled_cpp}) target_sources(${target} PRIVATE ${compiled_header} ${compiled_cpp})
target_include_directories(${target} PUBLIC ${out_dir}) target_include_directories(${target} PUBLIC ${out_dir})
# The current scope automatically sees the file as generated, but the
# target scope may not if it is different. Force it where we can.
# We will also have to add the generated file to a target in this
# scope at the end to ensure correct dependencies.
if(NOT target_source_dir STREQUAL CMAKE_CURRENT_SOURCE_DIR) if(NOT target_source_dir STREQUAL CMAKE_CURRENT_SOURCE_DIR)
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.18")
list(APPEND generated_sources_other_scope ${compiled_header} ${compiled_cpp}) list(APPEND generated_sources_other_scope ${compiled_header} ${compiled_cpp})
endif() endif()
endif()
list(APPEND compiled_files ${compiled_header}) list(APPEND compiled_files ${compiled_header})
endforeach() endforeach()
@ -2251,19 +2247,24 @@ function(_qt_internal_target_enable_qmltc target)
# run MOC manually for the generated files # run MOC manually for the generated files
qt6_wrap_cpp(compiled_moc_files ${compiled_files} TARGET ${target} OPTIONS ${extra_moc_options}) qt6_wrap_cpp(compiled_moc_files ${compiled_files} TARGET ${target} OPTIONS ${extra_moc_options})
set_source_files_properties(${compiled_moc_files} PROPERTIES SKIP_AUTOGEN ON
SKIP_UNITY_BUILD_INCLUSION ON) # We can't rely on policy CMP0118 since user project controls it
set(scope_args)
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.18")
set(scope_args TARGET_DIRECTORY ${target})
endif()
_qt_internal_set_source_file_generated(
SOURCES ${generated_sources_other_scope} ${compiled_moc_files}
${scope_args}
SKIP_AUTOGEN
)
set_source_files_properties(${compiled_moc_files}
${scope_args}
PROPERTIES
SKIP_UNITY_BUILD_INCLUSION ON
)
target_sources(${target} PRIVATE ${compiled_moc_files}) target_sources(${target} PRIVATE ${compiled_moc_files})
if(NOT target_source_dir STREQUAL CMAKE_CURRENT_SOURCE_DIR) if(NOT target_source_dir STREQUAL CMAKE_CURRENT_SOURCE_DIR)
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.18")
set_source_files_properties(${generated_sources_other_scope} ${compiled_moc_files}
TARGET_DIRECTORY ${target}
PROPERTIES
SKIP_AUTOGEN TRUE
GENERATED TRUE
)
endif()
if(NOT TARGET ${target}_tooling) if(NOT TARGET ${target}_tooling)
message(FATAL_ERROR message(FATAL_ERROR
"${target}_tooling is not found, although it should be in this function.") "${target}_tooling is not found, although it should be in this function.")
@ -2809,8 +2810,9 @@ function(qt6_add_qml_plugin target)
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.18") if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.18")
set(scope_args TARGET_DIRECTORY ${target}) set(scope_args TARGET_DIRECTORY ${target})
endif() endif()
set_source_files_properties("${generated_cpp_file}" ${scope_args} _qt_internal_set_source_file_generated(
PROPERTIES GENERATED TRUE SOURCES "${generated_cpp_file}"
${scope_args}
) )
if(WIN32) if(WIN32)
set_source_files_properties("${generated_cpp_file}" ${scope_args} set_source_files_properties("${generated_cpp_file}" ${scope_args}
@ -3647,25 +3649,19 @@ function(qt6_target_qml_sources target)
) )
target_sources(${target} PRIVATE ${compiled_file}) target_sources(${target} PRIVATE ${compiled_file})
set_source_files_properties(${compiled_file} PROPERTIES # We can't rely on policy CMP0118 since user project controls it
SKIP_AUTOGEN ON set(scope_args)
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.18")
set(scope_args TARGET_DIRECTORY ${target})
endif()
_qt_internal_set_source_file_generated(
SOURCES ${compiled_file}
${scope_args}
SKIP_AUTOGEN
) )
# The current scope automatically sees the file as generated, but the
# target scope may not if it is different. Force it where we can.
# We will also have to add the generated file to a target in this
# scope at the end to ensure correct dependencies.
get_target_property(target_source_dir ${target} SOURCE_DIR) get_target_property(target_source_dir ${target} SOURCE_DIR)
if(NOT target_source_dir STREQUAL CMAKE_CURRENT_SOURCE_DIR) if(NOT target_source_dir STREQUAL CMAKE_CURRENT_SOURCE_DIR)
list(APPEND generated_sources_other_scope ${compiled_file}) list(APPEND generated_sources_other_scope ${compiled_file})
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.18")
set_source_files_properties(
${compiled_file}
TARGET_DIRECTORY ${target}
PROPERTIES
SKIP_AUTOGEN TRUE
GENERATED TRUE
)
endif()
endif() endif()
endif() endif()
endforeach() endforeach()
@ -3792,8 +3788,8 @@ Check https://doc.qt.io/qt-6/qt-cmake-policy-qtp0004.html for policy details."
@ONLY @ONLY
) )
set_source_files_properties("${extra_qmldir}" _qt_internal_set_source_file_generated(
PROPERTIES GENERATED TRUE SOURCES "${extra_qmldir}"
) )
endforeach() endforeach()
@ -3881,9 +3877,9 @@ function(qt6_generate_foreign_qml_types source_target destination_qml_target)
VERBATIM VERBATIM
) )
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.27") _qt_internal_set_source_file_generated(
set_source_files_properties(${additional_sources} PROPERTIES SKIP_LINTING ON) SOURCES ${additional_sources}
endif() )
target_sources(${destination_qml_target} PRIVATE ${additional_sources}) target_sources(${destination_qml_target} PRIVATE ${additional_sources})
endfunction() endfunction()
@ -4131,17 +4127,22 @@ function(_qt_internal_qml_type_registration target)
elseif(MSVC) elseif(MSVC)
set(additional_source_files_properties "COMPILE_OPTIONS" "/bigobj") set(additional_source_files_properties "COMPILE_OPTIONS" "/bigobj")
endif() endif()
set_source_files_properties(${type_registration_cpp_file} PROPERTIES
SKIP_AUTOGEN ON # We can't rely on policy CMP0118 since user project controls it
${additional_source_files_properties} set(scope_args)
)
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.18") if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.18")
set(scope_args TARGET_DIRECTORY ${target})
endif()
_qt_internal_set_source_file_generated(
SOURCES ${type_registration_cpp_file}
${scope_args}
SKIP_AUTOGEN
)
if(additional_source_files_properties)
set_source_files_properties( set_source_files_properties(
${type_registration_cpp_file} ${type_registration_cpp_file}
TARGET_DIRECTORY ${effective_target} ${scope_args}
PROPERTIES PROPERTIES
SKIP_AUTOGEN TRUE
GENERATED TRUE
${additional_source_files_properties} ${additional_source_files_properties}
) )
endif() endif()