diff options
author | Leander Beernaert <leander.beernaert@qt.io> | 2019-07-18 09:38:37 +0200 |
---|---|---|
committer | Leander Beernaert <leander.beernaert@qt.io> | 2019-07-22 14:28:19 +0000 |
commit | 31341ad63abbf67fc6a058284e5f48c33a6c4e8f (patch) | |
tree | b43292a826a276a22d9027a432f20caef777dfe6 /util/cmake/pro2cmake.py | |
parent | 9f40dddaaab969ab278aef9bb05bc077f8b1cee9 (diff) |
Simplify add_qml_module code
Reduce the amount of code required to add a qml plugin to cmake
by making add_qml_module wrap the add_qt_plugin code where required.
add_qml_module will also create a dummy target so that qml files
will appear as source files in an IDE when no cpp files are present.
CXX_MODULE qmake parameter has been dropped in favor of an
explicit IMPORT_VERSION parameter, since it was only used to
determine the version when the IMPORT_VERSION was not specified.
Change-Id: I4a4b626566720d04c62d246ca521db8c4a95b10f
Reviewed-by: Qt CMake Build Bot
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'util/cmake/pro2cmake.py')
-rwxr-xr-x | util/cmake/pro2cmake.py | 36 |
1 files changed, 11 insertions, 25 deletions
diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py index 35a0bba2cc..64eb070282 100755 --- a/util/cmake/pro2cmake.py +++ b/util/cmake/pro2cmake.py @@ -1795,28 +1795,20 @@ def write_plugin(cm_fh, scope, *, indent: int = 0): plugin_type = scope.get_string('PLUGIN_TYPE') is_qml_plugin = any('qml_plugin' == s for s in scope.get('_LOADED')) - target_path = scope.get_string('TARGETPATH') - + plugin_function_name = 'add_qt_plugin' if plugin_type: extra.append('TYPE {}'.format(plugin_type)) elif is_qml_plugin: - extra.append('TYPE {}'.format('qml_plugin')) - extra.append('QML_TARGET_PATH "{}"'.format(target_path)) + plugin_function_name = 'add_qml_module' + write_qml_plugin(cm_fh, plugin_name, scope, indent=indent, extra_lines=extra) plugin_class_name = scope.get_string('PLUGIN_CLASS_NAME') if plugin_class_name: extra.append('CLASS_NAME {}'.format(plugin_class_name)) - write_main_part(cm_fh, plugin_name, 'Plugin', 'add_qt_plugin', scope, + write_main_part(cm_fh, plugin_name, 'Plugin', plugin_function_name, scope, indent=indent, extra_lines=extra, known_libraries={}, extra_keys=[]) - if is_qml_plugin: - extra = [] - extra.append('TARGET_PATH "{}"'.format(target_path)) - - write_qml_plugin(cm_fh, plugin_name, scope, indent=indent, extra_lines=extra) - - def write_qml_plugin(cm_fh: typing.IO[str], target: str, scope: Scope, *, @@ -1824,9 +1816,10 @@ def write_qml_plugin(cm_fh: typing.IO[str], indent: int = 0, **kwargs: typing.Any): # Collect other args if available - cxx_module = scope.get_string('CXX_MODULE') - if cxx_module: - extra_lines.append('CXX_MODULE "{}"'.format(cxx_module)) + indent += 2 + target_path = scope.get_string('TARGETPATH') + if target_path: + 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}") @@ -1838,19 +1831,12 @@ def write_qml_plugin(cm_fh: typing.IO[str], if plugindump_dep: extra_lines.append('QML_PLUGINDUMP_DEPENDENCIES "{}"'.format(plugindump_dep)) - cm_fh.write('\n{}{}({}\n'.format(spaces(indent), 'add_qml_module', target)) - indent += 1 - for extra_line in extra_lines: - cm_fh.write('{}{}\n'.format(spaces(indent), extra_line)) - qml_files = scope.expand('QML_FILES') if qml_files: - cm_fh.write('{}{}\n'.format(spaces(indent), 'QML_FILES')) - write_list(cm_fh, qml_files, '', indent=indent + 1) + extra_lines.append('QML_FILES\n{}{}'.format( + spaces(indent), + '\n{}'.format(spaces(indent)).join(qml_files))) - # Footer: - indent -= 1 - cm_fh.write('{})\n'.format(spaces(indent))) def handle_app_or_lib(scope: Scope, cm_fh: typing.IO[str], *, |