Add EMBED_QML_FILES option to add_qml_module

Some projects in QtQuickControls force the qml files to embedded into
the binary. This change exposes an option to mimic that bevhavior.

Change-Id: I4cbf0c21c05ca03b8dd1189eb7d81e43279c7157
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Leander Beernaert 2019-07-25 11:22:52 +02:00
parent a92f029e2a
commit 88bf485f91
2 changed files with 25 additions and 11 deletions

View File

@ -1759,6 +1759,7 @@ endfunction()
# in an IDE. Finally, it will also create a custom ${target}_qmltypes which
# can be used to generate the respective plugin.qmltypes file.
#
# EMBED_QML_FILES: When present will embed qml files into the binary
# TARGET_PATH: Expected installation path for the Qml Module. Equivalent
# to the module's URI where '.' is replaced with '/'.
# IMPORT_VERSION: Import version for the qml module
@ -1769,6 +1770,10 @@ endfunction()
#
function(add_qml_module target)
set(qml_module_optional_args
EMBED_QML_FILES
)
set(qml_module_single_args
TARGET_PATH
IMPORT_VERSION
@ -1780,7 +1785,7 @@ function(add_qml_module target)
)
qt_parse_all_arguments(arg "add_qml_module"
"${__add_qt_plugin_optional_args}"
"${__add_qt_plugin_optional_args};${qml_module_optional_args}"
"${__add_qt_plugin_single_args};${qml_module_single_args}"
"${__add_qt_plugin_multi_args};${qml_module_multi_args}" ${ARGN})
@ -1861,19 +1866,26 @@ function(add_qml_module target)
)
endif()
if(NOT QT_BUILD_SHARED_LIBS)
if(NOT QT_BUILD_SHARED_LIBS OR arg_EMBED_QML_FILES)
string(REPLACE "/" "." uri ${arg_TARGET_PATH})
string(REPLACE "." "_" uri_target ${uri})
# only embed qmldir on static builds. Some qml modules may request
# their qml files to be embedded into their binary
if (NOT QT_BUILD_SHARED_LIBS)
list(APPEND resource_files "${CMAKE_CURRENT_SOURCE_DIR}/qmldir")
endif()
list(APPEND resource_files ${arg_QML_FILES})
add_qt_resource(${target} ${uri_target}
FILES ${arg_QML_FILES} "${CMAKE_CURRENT_SOURCE_DIR}/qmldir"
PREFIX "/qt-project.org/import/${target_path}")
else()
if(arg_QML_FILES)
FILES ${resource_files}
PREFIX "/qt-project.org/import/${target_path}"
)
endif()
if (NOT QT_BUILD_SHARED_LIBS AND arg_QML_FILES)
qt_copy_or_install(FILES ${arg_QML_FILES}
DESTINATION "${qml_module_install_dir}"
)
endif()
endif()
endfunction()

View File

@ -1829,6 +1829,8 @@ def write_qml_plugin(cm_fh: typing.IO[str],
**kwargs: typing.Any):
# Collect other args if available
indent += 2
if 'builtin_resources' in scope.get('CONFIG'):
extra_lines.append('EMBED_QML_FILES')
target_path = scope.get_string('TARGETPATH')
if target_path:
extra_lines.append('TARGET_PATH "{}"'.format(target_path))