Add _qt_internal_set_source_file_generated function

Create a function `_qt_internal_set_source_file_generated` that sets the
source file property `GENERATED` along with Qt relevant properties:
- `SKIP_LINTING` if CMake>=3.27 and `QT_FEATURE_lint_generated_code`

Task-number: QTBUG-125077
Change-Id: I0ef5f7901f502366aaf2d020554c72e4845101b6
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
(cherry picked from commit f654519c7bd142d5cc9f81e0c826dfd31956791d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Cristian Le 2025-01-06 17:14:40 +01:00 committed by Qt Cherry-pick Bot
parent f32dbf337d
commit 3ad691586e
2 changed files with 94 additions and 0 deletions

View File

@ -424,3 +424,93 @@ function(_qt_internal_warn_about_example_add_subdirectory)
)
endif()
endfunction()
# Mark source files as generated.
#
# This sets `GENERATED` property to TRUE, along with other Qt relevant properties,
# e.g. `SKIP_LINTING`.
#
# Synopsis
#
# _qt_internal_set_source_file_generated(SOURCE <src1> ...
# [CONFIGURE_GENERATED]
# [SKIP_AUTOGEN]
# [DIRECTORY <dirs> ...]
# [TARGET_DIRECTORY <targets> ...]
# )
#
# Arguments
#
# `SOURCES`
# Source files that are generated.
#
# Equivalent to `set_source_files_properties(<files>)`.
#
# `DIRECTORY`
# Equivalent to `set_source_files_properties(DIRECTORY)`.
#
# `TARGET_DIRECTORY`
# Equivalent to `set_source_files_properties(TARGET_DIRECTORY)`.
#
# `SKIP_AUTOGEN`
# Set SKIP_AUTOGEN property to True as well.
#
# `CONFIGURE_GENERATED`
# Files are generated with `configure_file`.
# Does not set `GENERATED TRUE` property. This is needed to avoid removing the file when
# running the clean target.
function(_qt_internal_set_source_file_generated)
set(option_args
SKIP_AUTOGEN
CONFIGURE_GENERATED
)
set(single_args "")
set(multi_args
SOURCES
DIRECTORY
TARGET_DIRECTORY
)
cmake_parse_arguments(PARSE_ARGV 0 arg
"${option_args}" "${single_args}" "${multi_args}"
)
# Parse required variables
if(NOT arg_SOURCES AND QT_FEATURE_developer_build)
message(WARNING
"Unexpected call _qt_internal_set_source_file_generated with empty `SOURCES`."
)
endif()
# Prepend again the appropriate keywords to pass to `set_source_files_properties`
if(arg_DIRECTORY)
list(PREPEND arg_DIRECTORY DIRECTORY)
endif()
if(arg_TARGET_DIRECTORY)
list(PREPEND arg_TARGET_DIRECTORY TARGET_DIRECTORY)
endif()
# Construct the properties list
set(properties "")
if(NOT arg_CONFIGURE_GENERATED)
list(APPEND properties
GENERATED TRUE
)
endif()
if(arg_SKIP_AUTOGEN)
list(APPEND properties
SKIP_AUTOGEN TRUE
)
endif()
# Add SKIP_LINTING if possible. We do not add it unconditionally here to avoid
# confusion when CMake ignores this variable.
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.27" AND NOT QT_FEATURE_lint_generated_code)
list(APPEND properties
SKIP_LINTING TRUE
)
endif()
set_source_files_properties(${arg_SOURCES}
${arg_DIRECTORY}
${arg_TARGET_DIRECTORY}
PROPERTIES ${properties}
)
endfunction()

View File

@ -580,6 +580,10 @@ qt_feature("no-prefix"
AUTODETECT NOT QT_WILL_INSTALL
CONDITION NOT QT_WILL_INSTALL
)
qt_feature("lint_generated_code"
LABEL "Lint qt-generated code"
AUTODETECT QT_FEATURE_developer_build
)
qt_feature("private_tests" PRIVATE
LABEL "Developer build: private_tests"
CONDITION QT_FEATURE_developer_build