Use _qt_internal_set_source_file_generated

Migrate implementations that set `GENERATED` source property

Task-number: QTBUG-125077
Change-Id: Ia77ecf8422bf3983f7746c26e5a9994d1f6415f2
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
(cherry picked from commit 6865c21e41be5d86b5a04889bfe28fac55c89f29)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Cristian Le 2025-01-06 19:08:39 +01:00 committed by Qt Cherry-pick Bot
parent 78dd1c5cd0
commit d61c784273
6 changed files with 69 additions and 85 deletions

View File

@ -170,7 +170,7 @@ function(qt_internal_generate_fake_framework_header target)
file(GENERATE OUTPUT "${fake_header}" CONTENT "// ignore this file\n" file(GENERATE OUTPUT "${fake_header}" CONTENT "// ignore this file\n"
CONDITION "$<CONFIG:${main_config}>") CONDITION "$<CONFIG:${main_config}>")
target_sources(${target} PRIVATE "${fake_header}") target_sources(${target} PRIVATE "${fake_header}")
set_source_files_properties("${fake_header}" PROPERTIES GENERATED ON) _qt_internal_set_source_file_generated(SOURCES "${fake_header}")
set_property(TARGET ${target} APPEND PROPERTY PUBLIC_HEADER "${fake_header}") set_property(TARGET ${target} APPEND PROPERTY PUBLIC_HEADER "${fake_header}")
endfunction() endfunction()

View File

@ -251,10 +251,9 @@ function(qt_internal_add_module target)
set(module_config_private_header "qt${arg_CONFIG_MODULE_NAME}-config_p.h") set(module_config_private_header "qt${arg_CONFIG_MODULE_NAME}-config_p.h")
# qt<module>-config.h/-config_p.h header files are not marked as GENERATED automatically # qt<module>-config.h/-config_p.h header files are not marked as GENERATED automatically
# for old CMake versions. Set the property explicitly here. # for old CMake versions. Set the property explicitly here.
set_source_files_properties("${module_config_header}" "${module_config_private_header}" _qt_internal_set_source_file_generated(
PROPERTIES SOURCES "${module_config_header}" "${module_config_private_header}"
GENERATED TRUE SKIP_AUTOGEN
SKIP_AUTOGEN TRUE
) )
# Module define needs to take into account the config module name. # Module define needs to take into account the config module name.
@ -445,7 +444,7 @@ function(qt_internal_add_module target)
set(module_depends_header set(module_depends_header
"${module_build_interface_include_dir}/${module_include_name}Depends") "${module_build_interface_include_dir}/${module_include_name}Depends")
set_source_files_properties("${module_depends_header}" PROPERTIES GENERATED TRUE) _qt_internal_set_source_file_generated(SOURCES "${module_depends_header}")
set_target_properties(${target} PROPERTIES _qt_module_depends_header set_target_properties(${target} PROPERTIES _qt_module_depends_header
"${module_depends_header}") "${module_depends_header}")
if(NOT arg_HEADER_MODULE) if(NOT arg_HEADER_MODULE)
@ -1496,6 +1495,11 @@ function(qt_internal_generate_cpp_global_exports target module_define_infix)
set(${out_public_header} "${generated_header_path}" PARENT_SCOPE) set(${out_public_header} "${generated_header_path}" PARENT_SCOPE)
target_sources(${target} PRIVATE "${generated_header_path}") target_sources(${target} PRIVATE "${generated_header_path}")
_qt_internal_set_source_file_generated(
SOURCES "${generated_header_path}"
CONFIGURE_GENERATED
)
# `GENERATED` property is set in order to be processed by `qt_internal_collect_module_headers`
set_source_files_properties("${generated_header_path}" PROPERTIES GENERATED TRUE) set_source_files_properties("${generated_header_path}" PROPERTIES GENERATED TRUE)
endfunction() endfunction()

View File

@ -248,10 +248,7 @@ function(__qt_internal_add_static_plugin_init_object_library
CONTENT "${import_content}" CONTENT "${import_content}"
) )
# CMake versions earlier than 3.18.0 can't find the generated file for some reason, _qt_internal_set_source_file_generated(SOURCES "${generated_qt_plugin_file_name}")
# failing at generation phase.
# Explicitly marking the file as GENERATED fixes the issue.
set_source_files_properties("${generated_qt_plugin_file_name}" PROPERTIES GENERATED TRUE)
__qt_internal_get_static_plugin_init_target_name("${plugin_target}" plugin_init_target) __qt_internal_get_static_plugin_init_target_name("${plugin_target}" plugin_init_target)

View File

@ -142,12 +142,7 @@ function(_qt_internal_create_moc_command infile outfile moc_flags moc_options
${_moc_working_dir} ${_moc_working_dir}
VERBATIM) VERBATIM)
set_source_files_properties(${infile} PROPERTIES SKIP_AUTOMOC ON) set_source_files_properties(${infile} PROPERTIES SKIP_AUTOMOC ON)
set_source_files_properties(${outfile} PROPERTIES SKIP_AUTOMOC ON _qt_internal_set_source_file_generated(SOURCES ${outfile} ${extra_output_files} SKIP_AUTOGEN)
SKIP_AUTOUIC ON
)
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.27")
set_source_files_properties(${outfile} PROPERTIES SKIP_LINTING ON)
endif()
endfunction() endfunction()
function(qt6_generate_moc infile outfile ) function(qt6_generate_moc infile outfile )
@ -439,9 +434,9 @@ function(qt6_add_resources outfiles )
MAIN_DEPENDENCY ${infile} MAIN_DEPENDENCY ${infile}
DEPENDS ${_rc_depends} "${_out_depends}" ${QT_CMAKE_EXPORT_NAMESPACE}::rcc DEPENDS ${_rc_depends} "${_out_depends}" ${QT_CMAKE_EXPORT_NAMESPACE}::rcc
VERBATIM) VERBATIM)
set_source_files_properties(${outfile} PROPERTIES SKIP_AUTOMOC ON
SKIP_AUTOUIC ON _qt_internal_set_source_file_generated(SOURCES "${outfile}" SKIP_AUTOGEN)
SKIP_UNITY_BUILD_INCLUSION ON set_source_files_properties(${outfile} PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON
SKIP_PRECOMPILE_HEADERS ON SKIP_PRECOMPILE_HEADERS ON
) )
list(APPEND ${outfiles} ${outfile}) list(APPEND ${outfiles} ${outfile})
@ -526,15 +521,13 @@ function(qt6_add_big_resources outfiles )
_qt6_parse_qrc_file(${infile} _out_depends _rc_depends) _qt6_parse_qrc_file(${infile} _out_depends _rc_depends)
set_source_files_properties(${infile} PROPERTIES SKIP_AUTOGEN ON) set_source_files_properties(${infile} PROPERTIES SKIP_AUTOGEN ON)
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.27")
set_source_files_properties(${tmpoutfile} PROPERTIES SKIP_LINTING ON)
endif()
add_custom_command(OUTPUT ${tmpoutfile} add_custom_command(OUTPUT ${tmpoutfile}
COMMAND ${QT_CMAKE_EXPORT_NAMESPACE}::rcc ${rcc_options} --name ${outfilename} --pass 1 --output ${tmpoutfile} ${infile} COMMAND ${QT_CMAKE_EXPORT_NAMESPACE}::rcc ${rcc_options} --name ${outfilename} --pass 1 --output ${tmpoutfile} ${infile}
DEPENDS ${infile} ${_rc_depends} "${out_depends}" ${QT_CMAKE_EXPORT_NAMESPACE}::rcc DEPENDS ${infile} ${_rc_depends} "${out_depends}" ${QT_CMAKE_EXPORT_NAMESPACE}::rcc
COMMENT "Running rcc pass 1 for resource ${outfilename}" COMMENT "Running rcc pass 1 for resource ${outfilename}"
VERBATIM) VERBATIM)
add_custom_target(big_resources_${outfilename} ALL DEPENDS ${tmpoutfile}) add_custom_target(big_resources_${outfilename} ALL DEPENDS ${tmpoutfile})
_qt_internal_set_source_file_generated(SOURCES ${tmpoutfile} SKIP_AUTOGEN)
_qt_internal_add_rcc_pass2( _qt_internal_add_rcc_pass2(
RESOURCE_NAME ${outfilename} RESOURCE_NAME ${outfilename}
RCC_OPTIONS ${rcc_options} RCC_OPTIONS ${rcc_options}
@ -1357,8 +1350,8 @@ function(qt6_extract_metatypes target)
# The content shouldn't be empty so we don't trigger AUTOMOC warnings about it. # The content shouldn't be empty so we don't trigger AUTOMOC warnings about it.
file(GENERATE OUTPUT "${dummy_out_file}" CONTENT "//") file(GENERATE OUTPUT "${dummy_out_file}" CONTENT "//")
set_source_files_properties("${dummy_out_file}" PROPERTIES set_source_files_properties("${dummy_out_file}" PROPERTIES
GENERATED TRUE
SKIP_AUTOGEN OFF) SKIP_AUTOGEN OFF)
_qt_internal_set_source_file_generated(SOURCES "${dummy_out_file}")
target_sources("${target}" PRIVATE "${dummy_out_file}") target_sources("${target}" PRIVATE "${dummy_out_file}")
endif() endif()
@ -1483,13 +1476,9 @@ function(qt6_extract_metatypes target)
) )
endif() endif()
# We can't rely on policy CMP0118 since user project controls it _qt_internal_set_source_file_generated(
set(scope_args) SOURCES ${metatypes_file_gen} ${metatypes_file}
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.18") TARGET_DIRECTORY ${target}
set(scope_args TARGET_DIRECTORY ${target})
endif()
set_source_files_properties(${metatypes_file_gen} ${metatypes_file} ${scope_args}
PROPERTIES GENERATED TRUE
) )
# We still need to add this file as a source of the target, otherwise the file # We still need to add this file as a source of the target, otherwise the file
@ -1768,11 +1757,6 @@ END
target_link_libraries(${target} PRIVATE $<TARGET_OBJECTS:${target}_rc>) target_link_libraries(${target} PRIVATE $<TARGET_OBJECTS:${target}_rc>)
endif() endif()
set(scope_args)
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.18")
set(scope_args TARGET_DIRECTORY ${end_target})
endif()
while(outputs) while(outputs)
list(POP_FRONT cfgs cfg) list(POP_FRONT cfgs cfg)
list(POP_FRONT outputs output) list(POP_FRONT outputs output)
@ -1782,9 +1766,13 @@ END
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${input}" "${output}" COMMAND ${CMAKE_COMMAND} -E copy_if_different "${input}" "${output}"
VERBATIM VERBATIM
) )
# We can't rely on policy CMP0118 since user project controls it _qt_internal_set_source_file_generated(
set_source_files_properties(${output} ${scope_args} PROPERTIES SOURCES ${output}
GENERATED TRUE TARGET_DIRECTORY ${end_target}
)
set_source_files_properties(${output}
TARGET_DIRECTORY ${end_target}
PROPERTIES
COMPILE_FLAGS "${extra_rc_flags}" COMPILE_FLAGS "${extra_rc_flags}"
) )
target_sources(${end_target} PRIVATE "$<$<CONFIG:${cfg}>:${output}>") target_sources(${end_target} PRIVATE "$<$<CONFIG:${cfg}>:${output}>")
@ -1828,11 +1816,8 @@ function(_qt_internal_generate_longpath_win32_rc_file_and_manifest target)
endif() endif()
list(APPEND outputs "${mn_file_output}") list(APPEND outputs "${mn_file_output}")
foreach(output IN LISTS outputs) target_sources(${target} PRIVATE ${outputs})
# Needed for CMake versions < 3.19 _qt_internal_set_source_file_generated(SOURCES ${outputs})
set_source_files_properties(${output} PROPERTIES GENERATED TRUE)
target_sources(${target} PRIVATE "${output}")
endforeach()
endfunction() endfunction()
function(__qt_get_relative_resource_path_for_file output_alias file) function(__qt_get_relative_resource_path_for_file output_alias file)
@ -2107,12 +2092,14 @@ function(__qt_internal_generate_init_resource_source_file out_var target resourc
configure_file("${template_file}" "${resource_init_path}" @ONLY) configure_file("${template_file}" "${resource_init_path}" @ONLY)
set(scope_args "") _qt_internal_set_source_file_generated(
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.18") SOURCES ${resource_init_path}
set(scope_args TARGET_DIRECTORY ${target}) TARGET_DIRECTORY ${target}
endif() SKIP_AUTOGEN CONFIGURE_GENERATED
set_source_files_properties(${resource_init_path} ${scope_args} PROPERTIES )
SKIP_AUTOGEN TRUE set_source_files_properties(${resource_init_path}
TARGET_DIRECTORY ${target}
PROPERTIES
SKIP_UNITY_BUILD_INCLUSION TRUE SKIP_UNITY_BUILD_INCLUSION TRUE
SKIP_PRECOMPILE_HEADERS TRUE SKIP_PRECOMPILE_HEADERS TRUE
) )
@ -2494,21 +2481,17 @@ function(_qt_internal_process_resource target resourceName)
return() return()
endif() endif()
# We can't rely on policy CMP0118 since user project controls it. _qt_internal_set_source_file_generated(
# We also want SKIP_AUTOGEN known in the target's scope, where we can. SOURCES ${generatedOutfile}
set(scope_args) TARGET_DIRECTORY ${target}
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.18") SKIP_AUTOGEN
set(scope_args TARGET_DIRECTORY ${target}) )
endif() set_source_files_properties(${generatedOutfile}
set_source_files_properties(${generatedOutfile} ${scope_args} PROPERTIES TARGET_DIRECTORY ${target}
SKIP_AUTOGEN TRUE PROPERTIES
GENERATED TRUE
SKIP_UNITY_BUILD_INCLUSION TRUE SKIP_UNITY_BUILD_INCLUSION TRUE
SKIP_PRECOMPILE_HEADERS TRUE SKIP_PRECOMPILE_HEADERS TRUE
) )
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.27")
set_source_files_properties(${generatedOutfile} ${scope_args} PROPERTIES SKIP_LINTING ON)
endif()
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)

View File

@ -39,9 +39,9 @@ function(qt6_add_dbus_interface _sources _interface _relativename)
VERBATIM VERBATIM
) )
set_source_files_properties("${_impl}" "${_header}" PROPERTIES _qt_internal_set_source_file_generated(
SKIP_AUTOMOC TRUE SOURCES "${_impl}" "${_header}"
SKIP_AUTOUIC TRUE SKIP_AUTOGEN
) )
qt6_generate_moc("${_header}" "${_moc}") qt6_generate_moc("${_header}" "${_moc}")
@ -182,11 +182,11 @@ function(qt6_add_dbus_adaptor _sources _xml_file _include) # _optionalParentClas
) )
endif() endif()
qt6_generate_moc("${_header}" "${_moc}") _qt_internal_set_source_file_generated(
set_source_files_properties("${_impl}" "${_header}" PROPERTIES SOURCES "${_impl}" "${_header}"
SKIP_AUTOMOC TRUE SKIP_AUTOGEN
SKIP_AUTOUIC TRUE
) )
qt6_generate_moc("${_header}" "${_moc}")
macro_add_file_dependencies("${_impl}" "${_moc}") macro_add_file_dependencies("${_impl}" "${_moc}")
list(APPEND ${_sources} "${_impl}" "${_header}") list(APPEND ${_sources} "${_impl}" "${_header}")

View File

@ -31,10 +31,12 @@ function(qt6_wrap_ui outfiles )
ARGS ${ui_options} -o ${outfile} ${infile} ARGS ${ui_options} -o ${outfile} ${infile}
MAIN_DEPENDENCY ${infile} VERBATIM) MAIN_DEPENDENCY ${infile} VERBATIM)
set_source_files_properties(${infile} PROPERTIES SKIP_AUTOUIC ON) set_source_files_properties(${infile} PROPERTIES SKIP_AUTOUIC ON)
set_source_files_properties(${outfile} PROPERTIES SKIP_AUTOMOC ON)
set_source_files_properties(${outfile} PROPERTIES SKIP_AUTOUIC ON)
list(APPEND ${outfiles} ${outfile}) list(APPEND ${outfiles} ${outfile})
endforeach() endforeach()
_qt_internal_set_source_file_generated(
SOURCES ${${outfiles}}
SKIP_AUTOGEN
)
set(${outfiles} ${${outfiles}} PARENT_SCOPE) set(${outfiles} ${${outfiles}} PARENT_SCOPE)
endfunction() endfunction()
@ -197,13 +199,6 @@ function(qt6_add_ui target)
endif() endif()
set_source_files_properties(${infile} PROPERTIES SKIP_AUTOUIC ON) set_source_files_properties(${infile} PROPERTIES SKIP_AUTOUIC ON)
macro(_qt_internal_set_output_file_properties file)
set_source_files_properties(${file} PROPERTIES
SKIP_AUTOMOC TRUE
SKIP_AUTOUIC TRUE
SKIP_LINTING TRUE)
endmacro()
set(outfile "${output_directory}/ui_${outfile}.h") set(outfile "${output_directory}/ui_${outfile}.h")
# Before CMake 3.27, there was a bug when using $<CONFIG> in a generated # Before CMake 3.27, there was a bug when using $<CONFIG> in a generated
# file with Ninja Multi-Config generator. To avoid this issue, we need # file with Ninja Multi-Config generator. To avoid this issue, we need
@ -220,12 +215,17 @@ function(qt6_add_ui target)
foreach(config ${CMAKE_CONFIGURATION_TYPES}) foreach(config ${CMAKE_CONFIGURATION_TYPES})
string(REPLACE "$<CONFIG>" "${config}" outfile_with_config string(REPLACE "$<CONFIG>" "${config}" outfile_with_config
"${outfile}") "${outfile}")
_qt_internal_set_output_file_properties( _qt_internal_set_source_file_generated(
${outfile_with_config}) SOURCES ${outfile_with_config}
SKIP_AUTOGEN
)
target_sources(${target} PRIVATE ${outfile_with_config}) target_sources(${target} PRIVATE ${outfile_with_config})
endforeach() endforeach()
else() else()
_qt_internal_set_output_file_properties(${outfile}) _qt_internal_set_source_file_generated(
SOURCES ${outfile}
SKIP_AUTOGEN
)
target_sources(${target} PRIVATE ${outfile}) target_sources(${target} PRIVATE ${outfile})
endif() endif()
# remove double slashes # remove double slashes