CMake: Support big resources in qt_add_resources
[ChangeLog][CMake] The target-based variant of qt6_add_resource gained the option BIG_RESOURCES. This can be used instead of qt6_add_big_resources, which is not target-based. Fixes: QTBUG-100268 Change-Id: Ib3fa783cbfbfd10f59c2f952bc88508a91f25e26 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
parent
0ce5c0a996
commit
9ce5709fb1
@ -439,26 +439,58 @@ function(qt6_add_big_resources outfiles )
|
|||||||
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}"
|
||||||
VERBATIM)
|
VERBATIM)
|
||||||
add_custom_target(big_resources_${outfilename} ALL DEPENDS ${tmpoutfile})
|
add_custom_target(big_resources_${outfilename} ALL DEPENDS ${tmpoutfile})
|
||||||
add_library(rcc_object_${outfilename} OBJECT ${tmpoutfile})
|
_qt_internal_add_rcc_pass2(
|
||||||
_qt_internal_set_up_static_runtime_library(rcc_object_${outfilename})
|
RESOURCE_NAME ${outfilename}
|
||||||
target_compile_definitions(rcc_object_${outfilename} PUBLIC "$<TARGET_PROPERTY:Qt6::Core,INTERFACE_COMPILE_DEFINITIONS>")
|
RCC_OPTIONS ${rcc_options}
|
||||||
set_target_properties(rcc_object_${outfilename} PROPERTIES AUTOMOC OFF)
|
OBJECT_LIB rcc_object_${outfilename}
|
||||||
set_target_properties(rcc_object_${outfilename} PROPERTIES AUTOUIC OFF)
|
QRC_FILE ${infile}
|
||||||
|
PASS1_OUTPUT_FILE ${tmpoutfile}
|
||||||
|
OUT_OBJECT_FILE ${outfile}
|
||||||
|
)
|
||||||
add_dependencies(rcc_object_${outfilename} big_resources_${outfilename})
|
add_dependencies(rcc_object_${outfilename} big_resources_${outfilename})
|
||||||
# The modification of TARGET_OBJECTS needs the following change in cmake
|
|
||||||
# https://gitlab.kitware.com/cmake/cmake/commit/93c89bc75ceee599ba7c08b8fe1ac5104942054f
|
|
||||||
add_custom_command(OUTPUT ${outfile}
|
|
||||||
COMMAND ${QT_CMAKE_EXPORT_NAMESPACE}::rcc
|
|
||||||
ARGS ${rcc_options} --name ${outfilename} --pass 2 --temp $<TARGET_OBJECTS:rcc_object_${outfilename}> --output ${outfile} ${infile}
|
|
||||||
DEPENDS rcc_object_${outfilename} $<TARGET_OBJECTS:rcc_object_${outfilename}> ${QT_CMAKE_EXPORT_NAMESPACE}::rcc
|
|
||||||
VERBATIM)
|
|
||||||
list(APPEND ${outfiles} ${outfile})
|
list(APPEND ${outfiles} ${outfile})
|
||||||
endforeach()
|
endforeach()
|
||||||
set(${outfiles} ${${outfiles}} PARENT_SCOPE)
|
set(${outfiles} ${${outfiles}} PARENT_SCOPE)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
function(_qt_internal_add_rcc_pass2)
|
||||||
|
set(options)
|
||||||
|
set(oneValueArgs
|
||||||
|
RESOURCE_NAME
|
||||||
|
OBJECT_LIB
|
||||||
|
QRC_FILE
|
||||||
|
PASS1_OUTPUT_FILE
|
||||||
|
OUT_OBJECT_FILE
|
||||||
|
)
|
||||||
|
set(multiValueArgs
|
||||||
|
RCC_OPTIONS
|
||||||
|
)
|
||||||
|
cmake_parse_arguments(arg "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||||
|
|
||||||
|
add_library(${arg_OBJECT_LIB} OBJECT ${arg_PASS1_OUTPUT_FILE})
|
||||||
|
_qt_internal_set_up_static_runtime_library(${arg_OBJECT_LIB})
|
||||||
|
target_compile_definitions(${arg_OBJECT_LIB} PUBLIC
|
||||||
|
"$<TARGET_PROPERTY:Qt6::Core,INTERFACE_COMPILE_DEFINITIONS>")
|
||||||
|
set_target_properties(${arg_OBJECT_LIB} PROPERTIES
|
||||||
|
AUTOMOC OFF
|
||||||
|
AUTOUIC OFF)
|
||||||
|
# The modification of TARGET_OBJECTS needs the following change in cmake
|
||||||
|
# https://gitlab.kitware.com/cmake/cmake/commit/93c89bc75ceee599ba7c08b8fe1ac5104942054f
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT ${arg_OUT_OBJECT_FILE}
|
||||||
|
COMMAND ${QT_CMAKE_EXPORT_NAMESPACE}::rcc
|
||||||
|
${arg_RCC_OPTIONS} --name ${arg_RESOURCE_NAME} --pass 2
|
||||||
|
--temp $<TARGET_OBJECTS:${arg_OBJECT_LIB}>
|
||||||
|
--output ${arg_OUT_OBJECT_FILE} ${arg_QRC_FILE}
|
||||||
|
DEPENDS ${arg_OBJECT_LIB} $<TARGET_OBJECTS:${arg_OBJECT_LIB}>
|
||||||
|
${QT_CMAKE_EXPORT_NAMESPACE}::rcc
|
||||||
|
COMMENT "Running rcc pass 2 for resource ${arg_RESOURCE_NAME}"
|
||||||
|
VERBATIM)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS)
|
if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS)
|
||||||
function(qt_add_big_resources outfiles)
|
function(qt_add_big_resources outfiles)
|
||||||
if(QT_DEFAULT_MAJOR_VERSION EQUAL 5)
|
if(QT_DEFAULT_MAJOR_VERSION EQUAL 5)
|
||||||
@ -1963,6 +1995,113 @@ function(__qt_get_relative_resource_path_for_file output_alias file)
|
|||||||
set(${output_alias} ${alias} PARENT_SCOPE)
|
set(${output_alias} ${alias} PARENT_SCOPE)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
# Performs linking and propagation of the specified objects via the target's usage requirements.
|
||||||
|
# The objects may be given as generator expression.
|
||||||
|
#
|
||||||
|
# Arguments:
|
||||||
|
# EXTRA_CONDITIONS
|
||||||
|
# Conditions to be checked before linking the object files to the end-point executable.
|
||||||
|
# EXTRA_TARGET_LINK_LIBRARIES_CONDITIONS
|
||||||
|
# Conditions for the target_link_libraries call.
|
||||||
|
# EXTRA_TARGET_SOURCES_CONDITIONS
|
||||||
|
# Conditions for the target_sources call.
|
||||||
|
function(__qt_internal_propagate_object_files target objects)
|
||||||
|
set(options "")
|
||||||
|
set(single_args "")
|
||||||
|
set(extra_conditions_args
|
||||||
|
EXTRA_CONDITIONS
|
||||||
|
EXTRA_TARGET_LINK_LIBRARIES_CONDITIONS
|
||||||
|
EXTRA_TARGET_SOURCES_CONDITIONS
|
||||||
|
)
|
||||||
|
set(multi_args ${extra_conditions_args})
|
||||||
|
cmake_parse_arguments(arg "${options}" "${single_args}" "${multi_args}" ${ARGN})
|
||||||
|
|
||||||
|
# Collect additional conditions.
|
||||||
|
foreach(arg IN LISTS extra_conditions_args)
|
||||||
|
string(TOLOWER "${arg}" lcvar)
|
||||||
|
if(arg_${arg})
|
||||||
|
list(JOIN arg_${arg} "," ${lcvar})
|
||||||
|
else()
|
||||||
|
set(${lcvar} "$<BOOL:TRUE>")
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
# Do not litter the static libraries
|
||||||
|
set(not_static_condition
|
||||||
|
"$<NOT:$<STREQUAL:$<TARGET_PROPERTY:TYPE>,STATIC_LIBRARY>>"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Check if link order matters for the Platform.
|
||||||
|
set(platform_link_order_property
|
||||||
|
"$<TARGET_PROPERTY:${QT_CMAKE_EXPORT_NAMESPACE}::Platform,_qt_link_order_matters>"
|
||||||
|
)
|
||||||
|
set(platform_link_order_condition
|
||||||
|
"$<BOOL:${platform_link_order_property}>"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Check if link options are propagated according to CMP0099
|
||||||
|
# In user builds the _qt_cmp0099_policy_check is set to FALSE or $<TARGET_POLICY:CMP0099>
|
||||||
|
# depending on the used CMake version.
|
||||||
|
# See __qt_internal_check_cmp0099_available for details.
|
||||||
|
set(cmp0099_policy_check_property
|
||||||
|
"$<TARGET_PROPERTY:${QT_CMAKE_EXPORT_NAMESPACE}::Platform,_qt_cmp0099_policy_check>"
|
||||||
|
)
|
||||||
|
set(link_objects_using_link_options_condition
|
||||||
|
"$<BOOL:$<GENEX_EVAL:${cmp0099_policy_check_property}>>"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Collect link conditions for the target_sources call.
|
||||||
|
string(JOIN "" target_sources_genex
|
||||||
|
"$<"
|
||||||
|
"$<AND:"
|
||||||
|
"${not_static_condition},"
|
||||||
|
"${platform_link_order_condition},"
|
||||||
|
"$<NOT:${link_objects_using_link_options_condition}>,"
|
||||||
|
"${extra_target_sources_conditions},"
|
||||||
|
"${extra_conditions}"
|
||||||
|
">"
|
||||||
|
":${objects}>"
|
||||||
|
)
|
||||||
|
target_sources(${target} INTERFACE
|
||||||
|
"${target_sources_genex}"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Collect link conditions for the target_link_options call.
|
||||||
|
string(JOIN "" target_link_options_genex
|
||||||
|
"$<"
|
||||||
|
"$<AND:"
|
||||||
|
"${not_static_condition},"
|
||||||
|
"${platform_link_order_condition},"
|
||||||
|
"${link_objects_using_link_options_condition},"
|
||||||
|
"${extra_conditions}"
|
||||||
|
">"
|
||||||
|
":${objects}>"
|
||||||
|
)
|
||||||
|
# target_link_options works well since CMake 3.17 which has policy CMP0099 set to NEW for the
|
||||||
|
# minimum required CMake version greater than or equal to 3.17. The default is OLD. See
|
||||||
|
# https://cmake.org/cmake/help/git-master/policy/CMP0099.html for details.
|
||||||
|
# This provides yet another way of linking object libraries if user sets the policy to NEW
|
||||||
|
# before calling find_package(Qt...).
|
||||||
|
target_link_options(${target} INTERFACE
|
||||||
|
"${target_link_options_genex}"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Collect link conditions for the target_link_libraries call.
|
||||||
|
string(JOIN "" target_link_libraries_genex
|
||||||
|
"$<"
|
||||||
|
"$<AND:"
|
||||||
|
"${not_static_condition},"
|
||||||
|
"$<NOT:${platform_link_order_condition}>,"
|
||||||
|
"${extra_target_link_libraries_conditions},"
|
||||||
|
"${extra_conditions}"
|
||||||
|
">"
|
||||||
|
":${objects}>"
|
||||||
|
)
|
||||||
|
target_link_libraries(${target} INTERFACE
|
||||||
|
"${target_link_libraries_genex}"
|
||||||
|
)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
# Performs linking and propagation of the object library via the target's usage requirements.
|
# Performs linking and propagation of the object library via the target's usage requirements.
|
||||||
# Arguments:
|
# Arguments:
|
||||||
# NO_LINK_OBJECT_LIBRARY_REQUIREMENTS_TO_TARGET skip linking of ${object_library} to ${target}, only
|
# NO_LINK_OBJECT_LIBRARY_REQUIREMENTS_TO_TARGET skip linking of ${object_library} to ${target}, only
|
||||||
@ -2007,89 +2146,13 @@ function(__qt_internal_propagate_object_library target object_library)
|
|||||||
"$<NOT:$<BOOL:$<TARGET_PROPERTY:_qt_object_libraries_finalizer_mode>>>"
|
"$<NOT:$<BOOL:$<TARGET_PROPERTY:_qt_object_libraries_finalizer_mode>>>"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Collect object library specific conditions.
|
|
||||||
if(arg_EXTRA_CONDITIONS)
|
|
||||||
list(JOIN arg_EXTRA_CONDITIONS "," extra_conditions)
|
|
||||||
else()
|
|
||||||
set(extra_conditions "$<BOOL:TRUE>")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Do not litter the static libraries
|
|
||||||
set(not_static_condition
|
|
||||||
"$<NOT:$<STREQUAL:$<TARGET_PROPERTY:TYPE>,STATIC_LIBRARY>>"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Check if link order matters for the Platform.
|
|
||||||
set(platform_link_order_property
|
|
||||||
"$<TARGET_PROPERTY:${QT_CMAKE_EXPORT_NAMESPACE}::Platform,_qt_link_order_matters>"
|
|
||||||
)
|
|
||||||
set(platform_link_order_condition
|
|
||||||
"$<BOOL:${platform_link_order_property}>"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Check if link options are propagated according to CMP0099
|
|
||||||
# In user builds the _qt_cmp0099_policy_check is set to FALSE or $<TARGET_POLICY:CMP0099>
|
|
||||||
# depending on the used CMake version.
|
|
||||||
# See __qt_internal_check_cmp0099_available for details.
|
|
||||||
set(cmp0099_policy_check_property
|
|
||||||
"$<TARGET_PROPERTY:${QT_CMAKE_EXPORT_NAMESPACE}::Platform,_qt_cmp0099_policy_check>"
|
|
||||||
)
|
|
||||||
set(link_objects_using_link_options_condition
|
|
||||||
"$<BOOL:$<GENEX_EVAL:${cmp0099_policy_check_property}>>"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Use TARGET_NAME to have the correct namespaced name in the exports.
|
# Use TARGET_NAME to have the correct namespaced name in the exports.
|
||||||
set(objects "$<TARGET_OBJECTS:$<TARGET_NAME:${object_library}>>")
|
set(objects "$<TARGET_OBJECTS:$<TARGET_NAME:${object_library}>>")
|
||||||
|
|
||||||
# Collect link conditions for the target_sources call.
|
__qt_internal_propagate_object_files(${target} ${objects}
|
||||||
string(JOIN "" target_sources_genex
|
EXTRA_CONDITIONS ${arg_EXTRA_CONDITIONS}
|
||||||
"$<"
|
EXTRA_TARGET_SOURCES_CONDITIONS ${not_finalizer_mode_condition}
|
||||||
"$<AND:"
|
EXTRA_TARGET_LINK_LIBRARIES_CONDITIONS ${not_finalizer_mode_condition}
|
||||||
"${not_finalizer_mode_condition},"
|
|
||||||
"${not_static_condition},"
|
|
||||||
"${platform_link_order_condition},"
|
|
||||||
"$<NOT:${link_objects_using_link_options_condition}>,"
|
|
||||||
"${extra_conditions}"
|
|
||||||
">"
|
|
||||||
":${objects}>"
|
|
||||||
)
|
|
||||||
target_sources(${target} INTERFACE
|
|
||||||
"${target_sources_genex}"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Collect link conditions for the target_link_options call.
|
|
||||||
string(JOIN "" target_link_options_genex
|
|
||||||
"$<"
|
|
||||||
"$<AND:"
|
|
||||||
"${not_static_condition},"
|
|
||||||
"${platform_link_order_condition},"
|
|
||||||
"${link_objects_using_link_options_condition},"
|
|
||||||
"${extra_conditions}"
|
|
||||||
">"
|
|
||||||
":${objects}>"
|
|
||||||
)
|
|
||||||
# target_link_options works well since CMake 3.17 which has policy CMP0099 set to NEW for the
|
|
||||||
# minimum required CMake version greater than or equal to 3.17. The default is OLD. See
|
|
||||||
# https://cmake.org/cmake/help/git-master/policy/CMP0099.html for details.
|
|
||||||
# This provides yet another way of linking object libraries if user sets the policy to NEW
|
|
||||||
# before calling find_package(Qt...).
|
|
||||||
target_link_options(${target} INTERFACE
|
|
||||||
"${target_link_options_genex}"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Collect link conditions for the target_link_libraries call.
|
|
||||||
string(JOIN "" target_link_libraries_genex
|
|
||||||
"$<"
|
|
||||||
"$<AND:"
|
|
||||||
"${not_finalizer_mode_condition},"
|
|
||||||
"${not_static_condition},"
|
|
||||||
"$<NOT:${platform_link_order_condition}>,"
|
|
||||||
"${extra_conditions}"
|
|
||||||
">"
|
|
||||||
":${objects}>"
|
|
||||||
)
|
|
||||||
target_link_libraries(${target} INTERFACE
|
|
||||||
"${target_link_libraries_genex}"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if(NOT arg_NO_LINK_OBJECT_LIBRARY_REQUIREMENTS_TO_TARGET)
|
if(NOT arg_NO_LINK_OBJECT_LIBRARY_REQUIREMENTS_TO_TARGET)
|
||||||
@ -2199,11 +2262,32 @@ endfunction()
|
|||||||
# targets pass a value to the OUTPUT_TARGETS parameter.
|
# targets pass a value to the OUTPUT_TARGETS parameter.
|
||||||
#
|
#
|
||||||
function(_qt_internal_process_resource target resourceName)
|
function(_qt_internal_process_resource target resourceName)
|
||||||
|
cmake_parse_arguments(rcc "BIG_RESOURCES"
|
||||||
cmake_parse_arguments(rcc "" "PREFIX;LANG;BASE;OUTPUT_TARGETS;DESTINATION" "FILES;OPTIONS" ${ARGN})
|
"PREFIX;LANG;BASE;OUTPUT_TARGETS;DESTINATION" "FILES;OPTIONS" ${ARGN})
|
||||||
|
|
||||||
if("${rcc_OPTIONS}" MATCHES "-binary")
|
if("${rcc_OPTIONS}" MATCHES "-binary")
|
||||||
set(isBinary TRUE)
|
set(isBinary TRUE)
|
||||||
|
if(arg_BIG_RESOURCES)
|
||||||
|
message(FATAL_ERROR "BIG_RESOURCES cannot be used together with the -binary option.")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(arg_BIG_RESOURCES AND CMAKE_GENERATOR STREQUAL "Xcode" AND IOS)
|
||||||
|
message(WARNING
|
||||||
|
"Due to CMake limitations, the BIG_RESOURCES option can't be used when building "
|
||||||
|
"for iOS. "
|
||||||
|
"See https://bugreports.qt.io/browse/QTBUG-103497 for details. "
|
||||||
|
"Falling back to using regular resources. "
|
||||||
|
)
|
||||||
|
set(arg_BIG_RESOURCES OFF)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(arg_BIG_RESOURCES AND CMAKE_VERSION VERSION_LESS "3.17")
|
||||||
|
message(WARNING
|
||||||
|
"The BIG_RESOURCES option does not work reliably with CMake < 3.17. "
|
||||||
|
"Consider upgrading to a more recent CMake version or disable the BIG_RESOURCES "
|
||||||
|
"option for older CMake versions."
|
||||||
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
string(REPLACE "/" "_" resourceName ${resourceName})
|
string(REPLACE "/" "_" resourceName ${resourceName})
|
||||||
@ -2305,9 +2389,10 @@ function(_qt_internal_process_resource target resourceName)
|
|||||||
configure_file("${template_file}" "${generatedResourceFile}")
|
configure_file("${template_file}" "${generatedResourceFile}")
|
||||||
|
|
||||||
set(rccArgs --name "${resourceName}" "${generatedResourceFile}")
|
set(rccArgs --name "${resourceName}" "${generatedResourceFile}")
|
||||||
|
set(rccArgsAllPasses "")
|
||||||
|
|
||||||
if(rcc_OPTIONS)
|
if(rcc_OPTIONS)
|
||||||
list(APPEND rccArgs ${rcc_OPTIONS})
|
list(APPEND rccArgsAllPasses ${rcc_OPTIONS})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# When cross-building, we use host tools to generate target code. If the host rcc was compiled
|
# When cross-building, we use host tools to generate target code. If the host rcc was compiled
|
||||||
@ -2317,7 +2402,7 @@ function(_qt_internal_process_resource target resourceName)
|
|||||||
# If the target does not support zstd (feature is disabled), tell rcc not to generate
|
# If the target does not support zstd (feature is disabled), tell rcc not to generate
|
||||||
# zstd related code.
|
# zstd related code.
|
||||||
if(NOT QT_FEATURE_zstd)
|
if(NOT QT_FEATURE_zstd)
|
||||||
list(APPEND rccArgs "--no-zstd")
|
list(APPEND rccArgsAllPasses "--no-zstd")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set_property(SOURCE "${generatedResourceFile}" PROPERTY SKIP_AUTOGEN ON)
|
set_property(SOURCE "${generatedResourceFile}" PROPERTY SKIP_AUTOGEN ON)
|
||||||
@ -2334,27 +2419,36 @@ function(_qt_internal_process_resource target resourceName)
|
|||||||
set(generatedOutfile "${rcc_DESTINATION}.rcc")
|
set(generatedOutfile "${rcc_DESTINATION}.rcc")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
elseif(rcc_BIG_RESOURCES)
|
||||||
|
set(generatedOutfile "${CMAKE_CURRENT_BINARY_DIR}/.rcc/qrc_${resourceName}_tmp.cpp")
|
||||||
else()
|
else()
|
||||||
set(generatedOutfile "${CMAKE_CURRENT_BINARY_DIR}/.rcc/qrc_${resourceName}.cpp")
|
set(generatedOutfile "${CMAKE_CURRENT_BINARY_DIR}/.rcc/qrc_${resourceName}.cpp")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
set(pass_msg)
|
||||||
|
if(rcc_BIG_RESOURCES)
|
||||||
|
list(PREPEND rccArgs --pass 1)
|
||||||
|
set(pass_msg " pass 1")
|
||||||
|
endif()
|
||||||
|
|
||||||
list(PREPEND rccArgs --output "${generatedOutfile}")
|
list(PREPEND rccArgs --output "${generatedOutfile}")
|
||||||
|
|
||||||
# Process .qrc file:
|
# Process .qrc file:
|
||||||
add_custom_command(OUTPUT "${generatedOutfile}"
|
add_custom_command(OUTPUT "${generatedOutfile}"
|
||||||
COMMAND "${QT_CMAKE_EXPORT_NAMESPACE}::rcc" ${rccArgs}
|
COMMAND "${QT_CMAKE_EXPORT_NAMESPACE}::rcc" ${rccArgs} ${rccArgsAllPasses}
|
||||||
DEPENDS
|
DEPENDS
|
||||||
${resource_dependencies}
|
${resource_dependencies}
|
||||||
${generatedResourceFile}
|
${generatedResourceFile}
|
||||||
"${QT_CMAKE_EXPORT_NAMESPACE}::rcc"
|
"${QT_CMAKE_EXPORT_NAMESPACE}::rcc"
|
||||||
COMMENT "Running rcc for resource ${resourceName}"
|
COMMENT "Running rcc${pass_msg} for resource ${resourceName}"
|
||||||
VERBATIM)
|
VERBATIM)
|
||||||
|
|
||||||
set(output_targets "")
|
|
||||||
if(isBinary)
|
if(isBinary)
|
||||||
# Add generated .rcc target to 'all' set
|
# Add generated .rcc target to 'all' set
|
||||||
add_custom_target(binary_resource_${resourceName} ALL DEPENDS "${generatedOutfile}")
|
add_custom_target(binary_resource_${resourceName} ALL DEPENDS "${generatedOutfile}")
|
||||||
else()
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
# We can't rely on policy CMP0118 since user project controls it.
|
# We can't rely on policy CMP0118 since user project controls it.
|
||||||
# We also want SKIP_AUTOGEN known in the target's scope, where we can.
|
# We also want SKIP_AUTOGEN known in the target's scope, where we can.
|
||||||
set(scope_args)
|
set(scope_args)
|
||||||
@ -2367,6 +2461,7 @@ function(_qt_internal_process_resource target resourceName)
|
|||||||
SKIP_UNITY_BUILD_INCLUSION TRUE
|
SKIP_UNITY_BUILD_INCLUSION TRUE
|
||||||
SKIP_PRECOMPILE_HEADERS TRUE
|
SKIP_PRECOMPILE_HEADERS TRUE
|
||||||
)
|
)
|
||||||
|
|
||||||
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)
|
||||||
# We have to create a separate target in this scope that depends on
|
# We have to create a separate target in this scope that depends on
|
||||||
@ -2375,10 +2470,39 @@ function(_qt_internal_process_resource target resourceName)
|
|||||||
add_custom_target(${target}_${resourceName} DEPENDS ${generatedOutfile})
|
add_custom_target(${target}_${resourceName} DEPENDS ${generatedOutfile})
|
||||||
add_dependencies(${target} ${target}_${resourceName})
|
add_dependencies(${target} ${target}_${resourceName})
|
||||||
endif()
|
endif()
|
||||||
set_property(TARGET ${target} APPEND PROPERTY _qt_generated_qrc_files "${generatedResourceFile}")
|
|
||||||
|
|
||||||
__qt_propagate_generated_resource(${target} ${resourceName} "${generatedOutfile}" output_targets)
|
if(rcc_BIG_RESOURCES)
|
||||||
|
set(pass1OutputFile ${generatedOutfile})
|
||||||
|
set(generatedOutfile
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/.rcc/qrc_${resourceName}${CMAKE_CXX_OUTPUT_EXTENSION}")
|
||||||
|
_qt_internal_add_rcc_pass2(
|
||||||
|
RESOURCE_NAME ${resourceName}
|
||||||
|
RCC_OPTIONS ${rccArgsAllPasses}
|
||||||
|
OBJECT_LIB ${target}_${resourceName}_obj
|
||||||
|
QRC_FILE ${generatedResourceFile}
|
||||||
|
PASS1_OUTPUT_FILE ${pass1OutputFile}
|
||||||
|
OUT_OBJECT_FILE ${generatedOutfile}
|
||||||
|
)
|
||||||
|
get_target_property(type ${target} TYPE)
|
||||||
|
if(type STREQUAL STATIC_LIBRARY)
|
||||||
|
# Create a custom target to trigger the generation of ${generatedOutfile}
|
||||||
|
set(pass2_target ${target}_${resourceName}_pass2)
|
||||||
|
add_custom_target(${pass2_target} DEPENDS ${generatedOutfile})
|
||||||
|
add_dependencies(${target} ${pass2_target})
|
||||||
|
|
||||||
|
# Propagate the object files to the target.
|
||||||
|
__qt_internal_propagate_object_files(${target} "${generatedOutfile}")
|
||||||
|
else()
|
||||||
|
target_sources(${target} PRIVATE ${generatedOutfile})
|
||||||
endif()
|
endif()
|
||||||
|
else()
|
||||||
|
__qt_propagate_generated_resource(${target} ${resourceName} "${generatedOutfile}"
|
||||||
|
output_targets)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set_property(TARGET ${target}
|
||||||
|
APPEND PROPERTY _qt_generated_qrc_files "${generatedResourceFile}")
|
||||||
|
|
||||||
if (rcc_OUTPUT_TARGETS)
|
if (rcc_OUTPUT_TARGETS)
|
||||||
set(${rcc_OUTPUT_TARGETS} "${output_targets}" PARENT_SCOPE)
|
set(${rcc_OUTPUT_TARGETS} "${output_targets}" PARENT_SCOPE)
|
||||||
endif()
|
endif()
|
||||||
|
@ -28,6 +28,7 @@ qt_add_resources(<TARGET> <RESOURCE_NAME>
|
|||||||
[PREFIX <PATH>]
|
[PREFIX <PATH>]
|
||||||
[LANG <LANGUAGE>]
|
[LANG <LANGUAGE>]
|
||||||
[BASE <PATH>]
|
[BASE <PATH>]
|
||||||
|
[BIG_RESOURCES]
|
||||||
[OUTPUT_TARGETS <VARIABLE_NAME>]
|
[OUTPUT_TARGETS <VARIABLE_NAME>]
|
||||||
[FILES ...] [OPTIONS ...])
|
[FILES ...] [OPTIONS ...])
|
||||||
\endcode
|
\endcode
|
||||||
@ -69,6 +70,16 @@ example, if \c BASE is \c{"assets"} and \c FILES is
|
|||||||
Alias settings for files need to be set via the \c QT_RESOURCE_ALIAS source file
|
Alias settings for files need to be set via the \c QT_RESOURCE_ALIAS source file
|
||||||
property.
|
property.
|
||||||
|
|
||||||
|
\c BIG_RESOURCES can be specified to enable support for big resources. This
|
||||||
|
directly generates object files (\c .o, \c .obj) instead of C++ source code.
|
||||||
|
This allows embedding bigger resources, without having to compile generated C++
|
||||||
|
sources, which can be too time consuming and memory intensive.
|
||||||
|
|
||||||
|
Note that \c BIG_RESOURCES is not compatible with iOS due to restrictions of
|
||||||
|
CMake's Xcode project generator. See
|
||||||
|
\l{https://bugreports.qt.io/browse/QTBUG-103497}{QTBUG-103497} for details.
|
||||||
|
Also, \c BIG_RESOURCES only works reliably from CMake 3.17 onwards.
|
||||||
|
|
||||||
When using this command with static libraries, one or more special targets will
|
When using this command with static libraries, one or more special targets will
|
||||||
be generated. Should you wish to perform additional processing on these targets,
|
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
|
pass a variable name to the \c OUTPUT_TARGETS parameter. The \c qt_add_resources
|
||||||
|
@ -280,6 +280,10 @@ endif()
|
|||||||
|
|
||||||
_qt_internal_test_expect_pass(test_add_resources_binary_generated
|
_qt_internal_test_expect_pass(test_add_resources_binary_generated
|
||||||
BINARY test_add_resources_binary_generated)
|
BINARY test_add_resources_binary_generated)
|
||||||
|
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.17")
|
||||||
|
_qt_internal_test_expect_pass(test_add_resources_big_resources
|
||||||
|
BINARY test_add_resources_big_resources)
|
||||||
|
endif()
|
||||||
|
|
||||||
include(test_plugin_shared_static_flavor.cmake)
|
include(test_plugin_shared_static_flavor.cmake)
|
||||||
_qt_internal_test_expect_pass(tst_qaddpreroutine
|
_qt_internal_test_expect_pass(tst_qaddpreroutine
|
||||||
|
@ -0,0 +1,45 @@
|
|||||||
|
# Copyright (C) 2022 The Qt Company Ltd.
|
||||||
|
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.16)
|
||||||
|
|
||||||
|
project(test_add_resources_big_resources)
|
||||||
|
|
||||||
|
if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/FindPackageHints.cmake")
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/FindPackageHints.cmake")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
find_package(Qt6 REQUIRED
|
||||||
|
COMPONENTS Core Test
|
||||||
|
HINTS ${Qt6Tests_PREFIX_PATH}
|
||||||
|
)
|
||||||
|
|
||||||
|
qt6_add_library(leaf_lib STATIC leaf_lib.cpp)
|
||||||
|
qt6_add_resources(leaf_lib resources2
|
||||||
|
FILES resource2.txt PREFIX "/" BIG_RESOURCES)
|
||||||
|
target_link_libraries(leaf_lib PRIVATE Qt6::Core)
|
||||||
|
|
||||||
|
if(NOT TARGET leaf_lib_resources2_obj)
|
||||||
|
message(FATAL_ERROR "Object library for resources2 was not created.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
qt6_add_library(intermediate_lib STATIC intermediate_lib.cpp)
|
||||||
|
qt6_add_resources(intermediate_lib resources3
|
||||||
|
FILES resource3.txt PREFIX "/" BIG_RESOURCES
|
||||||
|
)
|
||||||
|
target_link_libraries(intermediate_lib PRIVATE Qt6::Core leaf_lib)
|
||||||
|
|
||||||
|
if(NOT TARGET intermediate_lib_resources3_obj)
|
||||||
|
message(FATAL_ERROR "Object library for resources3 was not created.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
|
||||||
|
qt6_add_executable(test_add_resources_big_resources main.cpp)
|
||||||
|
qt6_add_resources(test_add_resources_big_resources resources1
|
||||||
|
FILES resource1.txt PREFIX "/" BIG_RESOURCES)
|
||||||
|
target_link_libraries(test_add_resources_big_resources PRIVATE Qt6::Test intermediate_lib)
|
||||||
|
|
||||||
|
if(NOT TARGET test_add_resources_big_resources_resources1_obj)
|
||||||
|
message(FATAL_ERROR "Object library for resources1 was not created.")
|
||||||
|
endif()
|
@ -0,0 +1,20 @@
|
|||||||
|
// Copyright (C) 2022 The Qt Company Ltd.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
|
#include "leaf_lib.h"
|
||||||
|
|
||||||
|
#include <QtCore/qfile.h>
|
||||||
|
|
||||||
|
namespace intermediate_lib {
|
||||||
|
|
||||||
|
bool isLeafLibResourceAvailable()
|
||||||
|
{
|
||||||
|
return leaf_lib::isResourceAvailable();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isResourceAvailable()
|
||||||
|
{
|
||||||
|
return QFile::exists(u":/resource3.txt"_qs);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
@ -0,0 +1,9 @@
|
|||||||
|
// Copyright (C) 2022 The Qt Company Ltd.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace intermediate_lib {
|
||||||
|
bool isLeafLibResourceAvailable();
|
||||||
|
bool isResourceAvailable();
|
||||||
|
} //namespace
|
@ -0,0 +1,13 @@
|
|||||||
|
// Copyright (C) 2022 The Qt Company Ltd.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
|
#include <QtCore/qfile.h>
|
||||||
|
|
||||||
|
namespace leaf_lib {
|
||||||
|
|
||||||
|
bool isResourceAvailable()
|
||||||
|
{
|
||||||
|
return QFile::exists(u":/resource2.txt"_qs);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
@ -0,0 +1,8 @@
|
|||||||
|
// Copyright (C) 2022 The Qt Company Ltd.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace leaf_lib {
|
||||||
|
bool isResourceAvailable();
|
||||||
|
} // namespace
|
35
tests/auto/cmake/test_add_resources_big_resources/main.cpp
Normal file
35
tests/auto/cmake/test_add_resources_big_resources/main.cpp
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
// Copyright (C) 2020 The Qt Company Ltd.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
|
#include "intermediate_lib.h"
|
||||||
|
|
||||||
|
#include <QtCore/qfile.h>
|
||||||
|
#include <QtTest/QtTest>
|
||||||
|
|
||||||
|
class TestAddResourcesBigResources : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
private slots:
|
||||||
|
void resourceInApplicationExists();
|
||||||
|
void resourceInIntermediateLibExists();
|
||||||
|
void resourceInLeafLibExists();
|
||||||
|
};
|
||||||
|
|
||||||
|
void TestAddResourcesBigResources::resourceInApplicationExists()
|
||||||
|
{
|
||||||
|
QVERIFY(QFile::exists(":/resource1.txt"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestAddResourcesBigResources::resourceInIntermediateLibExists()
|
||||||
|
{
|
||||||
|
QVERIFY(intermediate_lib::isResourceAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestAddResourcesBigResources::resourceInLeafLibExists()
|
||||||
|
{
|
||||||
|
QVERIFY(intermediate_lib::isLeafLibResourceAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
|
QTEST_MAIN(TestAddResourcesBigResources)
|
||||||
|
#include "main.moc"
|
||||||
|
|
@ -0,0 +1 @@
|
|||||||
|
Test resource1
|
@ -0,0 +1 @@
|
|||||||
|
Test resource2
|
@ -0,0 +1 @@
|
|||||||
|
Test resource3
|
Loading…
x
Reference in New Issue
Block a user