CMake: add a DISCARD_FILE_CONTENTS option to qt_add_resources

[ChangeLog][CMake] Added a DISCARD_FILE_CONTENTS option to
qt_add_resources().

Change-Id: I75e28b1b885b66da826c72fedcb34ae0d911e6d0
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Aurélien Brooke 2025-02-25 21:29:39 +01:00
parent 1008628b34
commit 1b3b62d1b9
2 changed files with 11 additions and 3 deletions

View File

@ -2260,8 +2260,11 @@ endfunction()
# targets pass a value to the OUTPUT_TARGETS parameter.
#
function(_qt_internal_process_resource target resourceName)
cmake_parse_arguments(rcc "BIG_RESOURCES"
"PREFIX;LANG;BASE;OUTPUT_TARGETS;DESTINATION" "FILES;OPTIONS" ${ARGN})
set(options BIG_RESOURCES DISCARD_FILE_CONTENTS)
set(oneValueArgs PREFIX LANG BASE OUTPUT_TARGETS DESTINATION)
set(multiValueArgs FILES OPTIONS)
cmake_parse_arguments(rcc "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if("${rcc_OPTIONS}" MATCHES "-binary")
set(isBinary TRUE)
@ -2377,7 +2380,7 @@ function(_qt_internal_process_resource target resourceName)
)
string(APPEND qrcContents " <file alias=\"${escaped_file_resource_path}\"")
if(is_empty)
if(is_empty OR rcc_DISCARD_FILE_CONTENTS)
string(APPEND qrcContents " empty=\"true\"")
endif()
string(APPEND qrcContents ">${escaped_file}</file>\n")

View File

@ -29,6 +29,7 @@ qt_add_resources(<TARGET> <RESOURCE_NAME>
[LANG <LANGUAGE>]
[BASE <PATH>]
[BIG_RESOURCES]
[DISCARD_FILE_CONTENTS]
[OUTPUT_TARGETS <VARIABLE_NAME>]
[FILES ...] [OPTIONS ...])
\endcode
@ -85,6 +86,10 @@ be generated. Should you wish to perform additional processing on these targets,
pass a variable name to the \c OUTPUT_TARGETS parameter. The \c qt_add_resources
function stores the names of the special targets in the specified variable.
If \c DISCARD_FILE_CONTENTS is specified, the resource files will be added to
the resource system without embedding their actual contents. Instead, these
files will be stored as empty placeholders within the generated resource.
\section1 Arguments of both variants
You can set additional \c{OPTIONS} that should be added to the \c{rcc} calls.