Simplify resource embedding for qml modules

* Add support for a QT_RESOURCE_PREFIX target property, that
      add_qt_resource respects. This makes it convenient to add files
      to the resource system for a project without the need to repeat
      prefixes. In qmake land with multiple resources they're repeated
      in the foo.prefix variables or in the prefix attribute in .qrc
      files.

    * Since /qt-project.org/imports is in the default QML import search path
       and the hierarchy under the import search paths is "regulated",
       we might as well make add_qml_module set QT_RESOURCE_PREFIX on
       the target. We can compute the correct value for that. This
       allows removing the redundant prefix from the add_qt_resource()
       calls for the qml files.

Change-Id: Ic15130dc9e432340fc3edf93e35f2a803b4b40eb
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Qt CMake Build Bot
This commit is contained in:
Simon Hausmann 2019-08-09 11:42:37 +02:00
parent f55c6a4cb0
commit 73ba2ba2de
3 changed files with 9 additions and 19 deletions

View File

@ -1905,8 +1905,6 @@ endfunction()
# to the module's URI where '.' is replaced with '/'. Use this to override the # to the module's URI where '.' is replaced with '/'. Use this to override the
# default substitution pattern. # default substitution pattern.
# VERSION: Version of the qml module # VERSION: Version of the qml module
# RESOURCE_PREFIX: Resource import prefix to be prepended to the module's
# target path.
# QML_PLUGINDUMP_DEPENDENCIES: Path to a dependencies.json file to be consumed # QML_PLUGINDUMP_DEPENDENCIES: Path to a dependencies.json file to be consumed
# with the ${target}_qmltypes target (optional) # with the ${target}_qmltypes target (optional)
# #
@ -1920,7 +1918,6 @@ function(add_qml_module target)
URI URI
TARGET_PATH TARGET_PATH
VERSION VERSION
RESOURCE_PREFIX
QML_PLUGINDUMP_DEPENDENCIES QML_PLUGINDUMP_DEPENDENCIES
) )
@ -1939,10 +1936,6 @@ function(add_qml_module target)
message(FATAL_ERROR "add_qml_module called without specifying the module's import version. Please specify one using the VERSION parameter.") message(FATAL_ERROR "add_qml_module called without specifying the module's import version. Please specify one using the VERSION parameter.")
endif() endif()
if (NOT arg_RESOURCE_PREFIX)
message(FATAL_ERROR "add_qml_module called without specifying the module's import prefix. Prease specify one using the RESOURCE_PREFIX parameter.")
endif()
if (NOT arg_TARGET_PATH) if (NOT arg_TARGET_PATH)
string(REPLACE "." "/" arg_TARGET_PATH ${arg_URI}) string(REPLACE "." "/" arg_TARGET_PATH ${arg_URI})
endif() endif()
@ -1983,7 +1976,7 @@ function(add_qml_module target)
PROPERTIES PROPERTIES
QT_QML_MODULE_TARGET_PATH ${arg_TARGET_PATH} QT_QML_MODULE_TARGET_PATH ${arg_TARGET_PATH}
QT_QML_MODULE_URI ${arg_URI} QT_QML_MODULE_URI ${arg_URI}
QT_QML_MODULE_RESOURCE_PREFIX ${arg_RESOURCE_PREFIX} QT_RESOURCE_PREFIX "/qt-project.org/imports/${arg_TARGET_PATH}"
QT_QML_MODULE_VERSION ${arg_VERSION} QT_QML_MODULE_VERSION ${arg_VERSION}
) )
@ -2017,7 +2010,6 @@ function(add_qml_module target)
set(qmldir_resource_name "${qmldir_resource_name}_qmldir") set(qmldir_resource_name "${qmldir_resource_name}_qmldir")
add_qt_resource(${target} ${uri_target} add_qt_resource(${target} ${uri_target}
FILES "${CMAKE_CURRENT_SOURCE_DIR}/qmldir" FILES "${CMAKE_CURRENT_SOURCE_DIR}/qmldir"
PREFIX "${arg_RESOURCE_PREFIX}/${arg_TARGET_PATH}"
) )
endif() endif()
@ -2547,6 +2539,9 @@ function(add_qt_resource target resourceName)
set(resource_files ${rcc_FILES}) set(resource_files ${rcc_FILES})
endif() endif()
if(NOT rcc_PREFIX)
get_target_property(rcc_PREFIX ${target} QT_RESOURCE_PREFIX)
endif()
# Apply quick compiler pass # Apply quick compiler pass
qt_quick_compiler_process_resources(${target} ${resourceName} qt_quick_compiler_process_resources(${target} ${resourceName}

View File

@ -79,11 +79,12 @@ define_property(TARGET
define_property(TARGET define_property(TARGET
PROPERTY PROPERTY
QT_QML_MODULE_RESOURCE_PREFIX QT_RESOURCE_PREFIX
BRIEF_DOCS BRIEF_DOCS
"Specifies the qml module's resource prefix." "Specifies the default Qt resource prefix."
FULL_DOCS FULL_DOCS
"Specifies the qml module's resource prefix." "When using add_qt_resource() without a PREFIX, then prefix of this target property
will be used."
) )
define_property(TARGET define_property(TARGET

View File

@ -2097,8 +2097,6 @@ def write_qml_plugin(cm_fh: typing.IO[str],
if plugindump_dep: if plugindump_dep:
extra_lines.append('QML_PLUGINDUMP_DEPENDENCIES "{}"'.format(plugindump_dep)) extra_lines.append('QML_PLUGINDUMP_DEPENDENCIES "{}"'.format(plugindump_dep))
# This is only required because of qmldir
extra_lines.append('RESOURCE_PREFIX "/qt-project.org/imports"')
def write_qml_plugin_qml_files(cm_fh: typing.IO[str], def write_qml_plugin_qml_files(cm_fh: typing.IO[str],
target: str, target: str,
@ -2116,15 +2114,11 @@ def write_qml_plugin_qml_files(cm_fh: typing.IO[str],
target_path_mangled = target_path.replace('/', '_') target_path_mangled = target_path.replace('/', '_')
target_path_mangled = target_path_mangled.replace('.', '_') target_path_mangled = target_path_mangled.replace('.', '_')
resource_name = 'qmake_' + target_path_mangled resource_name = 'qmake_' + target_path_mangled
prefix = '/qt-project.org/imports/' + target_path cm_fh.write('\n{}add_qt_resource({} {}\n{}FILES\n{}${{qml_files}}\n)\n'.format(
cm_fh.write('\n{}add_qt_resource({} {}\n{}PREFIX\n{}"{}"\n{}FILES\n{}${{qml_files}}\n)\n'.format(
spaces(indent), spaces(indent),
target, target,
resource_name, resource_name,
spaces(indent + 1), spaces(indent + 1),
spaces(indent + 2),
prefix,
spaces(indent + 1),
spaces(indent + 2))) spaces(indent + 2)))
cm_fh.write('\nqt_install_qml_files({}\n FILES ${{qml_files}}\n)\n\n'.format( cm_fh.write('\nqt_install_qml_files({}\n FILES ${{qml_files}}\n)\n\n'.format(