diff options
author | Leander Beernaert <leander.beernaert@qt.io> | 2019-08-01 15:43:36 +0200 |
---|---|---|
committer | Leander Beernaert <leander.beernaert@qt.io> | 2019-08-01 14:07:01 +0000 |
commit | 97b76704ea3b3a062a912656809b17d434f31ffe (patch) | |
tree | ea6f8214815c1af605ce186f1861c67bbfec9eef /util/cmake/pro2cmake.py | |
parent | 9e96c384261ca1329d3143295d013701eb85b186 (diff) |
Refactor QML_FILES for add_qml_module
It has been decided, that going forward all qml files are to be added
to a module via the resource system. This patch does the ground work
to make sure all qml modules in the qt codebase follow these new
conventions.
New properties on targets have been added so that we can't track all the
qml related information for later use.
To make sure it is still possible to install qml files we added the
qt_install_qml_files() command.
Pro2cmake has been adjusted to handle the special cases of versioned
qml modules (e.g: QtQuick.2). It will now insert a TARGET_PATH
override to avoid the default conversion from the URI parameter.
Finally, this patch temporarliy disables the quick compiler by moving
all relevant code into a dummy function. This will be removed in a
follow up patch where the quick compiler will be enable for all
qml files present in resource files.
Change-Id: I09fe4517fad26ec96122d9c7c777dbfbd214905c
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'util/cmake/pro2cmake.py')
-rwxr-xr-x | util/cmake/pro2cmake.py | 67 |
1 files changed, 52 insertions, 15 deletions
diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py index 80c975cec1..a62b094ee9 100755 --- a/util/cmake/pro2cmake.py +++ b/util/cmake/pro2cmake.py @@ -651,8 +651,8 @@ class Scope(object): return self._evalOps(key, None, [], inherit=inherit) - def get_string(self, key: str, default: str = '') -> str: - v = self.get(key) + def get_string(self, key: str, default: str = '', inherit : bool = False) -> str: + v = self.get(key, inherit = inherit) if len(v) == 0: return default assert len(v) == 1 @@ -1646,6 +1646,8 @@ def write_main_part(cm_fh: typing.IO[str], name: str, typename: str, # Evaluate total condition of all scopes: recursive_evaluate_scope(scope) + is_qml_plugin = any('qml_plugin' == s for s in scope.get('_LOADED')) + if 'exceptions' in scope.get('CONFIG'): extra_lines.append('EXCEPTIONS') @@ -1706,6 +1708,9 @@ def write_main_part(cm_fh: typing.IO[str], name: str, typename: str, write_android_part(cm_fh, name, scopes[0], indent) + if is_qml_plugin: + write_qml_plugin_qml_files(cm_fh, name, scopes[0], indent) + ignored_keys_report = write_ignored_keys(scopes[0], spaces(indent)) if ignored_keys_report: cm_fh.write(ignored_keys_report) @@ -1898,6 +1903,7 @@ def write_plugin(cm_fh, scope, *, indent: int = 0): write_main_part(cm_fh, plugin_name, 'Plugin', plugin_function_name, scope, indent=indent, extra_lines=extra, known_libraries={}, extra_keys=[]) + def write_qml_plugin(cm_fh: typing.IO[str], target: str, scope: Scope, *, @@ -1908,36 +1914,67 @@ def write_qml_plugin(cm_fh: typing.IO[str], indent += 2 scope_config = scope.get('CONFIG') is_embedding_qml_files = False - if 'builtin_resources' in scope_config or 'qt_quick_compiler' in scope_config: - extra_lines.append('EMBED_QML_FILES') - is_embedding_qml_files = True - if not is_embedding_qml_files: - extra_lines.append('INSTALL_QML_FILES') - if 'install_qml_files' in scope_config and is_embedding_qml_files: - extra_lines.append('INSTALL_QML_FILES') + sources = scope.get_files('SOURCES') + if len(sources) != 0: + extra_lines.append('CPP_PLUGIN') target_path = scope.get_string('TARGETPATH') if target_path: - extra_lines.append('TARGET_PATH "{}"'.format(target_path)) + uri = target_path.replace('/','.') + extra_lines.append('URI "{}"'.format(uri)) + # Catch special cases such as foo.QtQuick.2.bar, which when converted + # into a target path via cmake will result in foo/QtQuick/2/bar, which is + # not what we want. So we supply the target path override. + target_path_from_uri = uri.replace('.', '/') + if target_path != target_path_from_uri: + extra_lines.append('TARGET_PATH "{}"'.format(target_path)) + import_version = scope.get_string('IMPORT_VERSION') if import_version: import_version = import_version.replace("$$QT_MINOR_VERSION","${CMAKE_PROJECT_VERSION_MINOR}") - extra_lines.append('IMPORT_VERSION "{}"'.format(import_version)) + extra_lines.append('VERSION "{}"'.format(import_version)) + import_name = scope.get_string('IMPORT_NAME') if import_name: - extra_lines.append('IMPORT_NAME "{}"'.format(import_name)) + extra_lines.append('NAME "{}"'.format(import_name)) plugindump_dep = scope.get_string('QML_PLUGINDUMP_DEPENDENCIES') + if 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], + target: str, + scope: Scope, + indent: int = 0): + qml_files = scope.get_files('QML_FILES', use_vpath=True) if qml_files: - extra_lines.append('QML_FILES\n{}{}'.format( + target_path = scope.get_string('TARGETPATH', inherit=True) + target_path_mangled = target_path.replace('/', '_') + target_path_mangled = target_path_mangled.replace('.', '_') + resource_name = 'qmake_' + target_path_mangled + prefix = '/qt-project.org/imports/' + target_path + cm_fh.write('\n# QML Files\n') + cm_fh.write('{}add_qt_resource({} {}\n{}PREFIX\n{}"{}"\n{}FILES\n{}{}\n)\n'.format( spaces(indent), - '\n{}'.format(spaces(indent)).join(qml_files))) - + target, + resource_name, + spaces(indent + 1), + spaces(indent + 2), + prefix, + spaces(indent + 1), + spaces(indent + 2), + '\n{}'.format(spaces(indent + 2)).join(qml_files))) + + if 'install_qml_files' in scope.get('CONFIG'): + cm_fh.write('\nqt_install_qml_files({}\n FILES\n {}\n)\n\n'.format( + target, + '\n '.join(qml_files))) def handle_app_or_lib(scope: Scope, cm_fh: typing.IO[str], *, |