diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2019-01-18 16:02:43 +0100 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2019-02-12 09:12:39 +0000 |
commit | c4e60ed8283aa7a86e13c09113e7fec6bf41cc42 (patch) | |
tree | 6cefbf3ece17e255c3962e69573abc88bef060ef /share/qbs/module-providers/Qt/templates/qml.qbs | |
parent | 17058d1fc537e40e7dda9d6e48ccfb24ea1220f7 (diff) | |
download | qbs-c4e60ed8283aa7a86e13c09113e7fec6bf41cc42.tar.gz |
Detect Qt via a module provider
Creation of qbs modules for Qt is now done on demand during project
resolving. The qmake executable(s) are looked up via PATH or taken from
the Qt.qmakeFilePaths provider property. As a result, Qt projects can
now be built without a profile.
The qtprofilesetup library is gone; its code is now in the module
provider. I kept the C++ -> JavaScript conversion as straightforward as
possible and mostly resisted the temptation to "optimize".
The setup-qt tool still exists and mainly sets Qt.qmakeFilePaths.
[ChangeLog] It is no longer required to call setup-qt before building Qt
projects.
Change-Id: I5b7e4711ec47b996911c499f29d8129d90e4731e
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'share/qbs/module-providers/Qt/templates/qml.qbs')
-rw-r--r-- | share/qbs/module-providers/Qt/templates/qml.qbs | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/share/qbs/module-providers/Qt/templates/qml.qbs b/share/qbs/module-providers/Qt/templates/qml.qbs new file mode 100644 index 000000000..2b11abbd5 --- /dev/null +++ b/share/qbs/module-providers/Qt/templates/qml.qbs @@ -0,0 +1,132 @@ +import qbs.TextFile +import '../QtModule.qbs' as QtModule +import "qml.js" as Qml + +QtModule { + qtModuleName: "Qml" + Depends { name: "Qt"; submodules: @dependencies@} + + property string qmlImportScannerName: "qmlimportscanner" + property string qmlImportScannerFilePath: Qt.core.binPath + '/' + qmlImportScannerName + property string qmlPath: @qmlPath@ + + property bool generateCacheFiles: false + Depends { name: "Qt.qmlcache"; condition: generateCacheFiles; required: false } + readonly property bool cachingEnabled: generateCacheFiles && Qt.qmlcache.present + property string qmlCacheGenPath + Properties { + condition: cachingEnabled + Qt.qmlcache.qmlCacheGenPath: qmlCacheGenPath || original + Qt.qmlcache.installDir: cacheFilesInstallDir || original + } + + property string cacheFilesInstallDir + + readonly property string pluginListFilePathDebug: product.buildDirectory + "/plugins.list.d" + readonly property string pluginListFilePathRelease: product.buildDirectory + "/plugins.list" + + hasLibrary: @has_library@ + architectures: @archs@ + targetPlatform: @targetPlatform@ + staticLibsDebug: (isStaticLibrary ? ['@' + pluginListFilePathDebug] : []).concat(@staticLibsDebug@) + staticLibsRelease: (isStaticLibrary ? ['@' + pluginListFilePathRelease] : []).concat(@staticLibsRelease@) + dynamicLibsDebug: @dynamicLibsDebug@ + dynamicLibsRelease: @dynamicLibsRelease@ + linkerFlagsDebug: @linkerFlagsDebug@ + linkerFlagsRelease: @linkerFlagsRelease@ + frameworksDebug: @frameworksDebug@ + frameworksRelease: @frameworksRelease@ + frameworkPathsDebug: @frameworkPathsDebug@ + frameworkPathsRelease: @frameworkPathsRelease@ + libNameForLinkerDebug: @libNameForLinkerDebug@ + libNameForLinkerRelease: @libNameForLinkerRelease@ + libFilePathDebug: @libFilePathDebug@ + libFilePathRelease: @libFilePathRelease@ + pluginTypes: @pluginTypes@ + moduleConfig: @moduleConfig@ + cpp.defines: @defines@ + cpp.includePaths: @includes@ + cpp.libraryPaths: @libraryPaths@ + @additionalContent@ + + FileTagger { + patterns: ["*.qml"] + fileTags: ["qt.qml.qml"] + } + + FileTagger { + patterns: ["*.js"] + fileTags: ["qt.qml.js"] + } + + Rule { + condition: isStaticLibrary + multiplex: true + requiresInputs: false + inputs: ["qt.qml.qml"] + outputFileTags: ["cpp", "qt.qml.pluginlist"] + outputArtifacts: { + var list = []; + if (inputs["qt.qml.qml"]) + list.push({ filePath: "qml_plugin_import.cpp", fileTags: ["cpp"] }); + list.push({ + filePath: product.Qt.core.qtBuildVariant === "debug" + ? product.Qt.qml.pluginListFilePathDebug + : product.Qt.qml.pluginListFilePathRelease, + fileTags: ["qt.qml.pluginlist"] + }); + return list; + } + prepare: { + var cmd = new JavaScriptCommand(); + if (inputs["qt.qml.qml"]) + cmd.description = "Creating " + outputs["cpp"][0].fileName; + else + cmd.silent = true; + cmd.sourceCode = function() { + var qmlInputs = inputs["qt.qml.qml"]; + if (!qmlInputs) + qmlInputs = []; + var scannerData = Qml.scannerData(product.Qt.qml.qmlImportScannerFilePath, + qmlInputs.map(function(inp) { return inp.filePath; }), + product.Qt.qml.qmlPath); + var cppFile; + var listFile; + try { + if (qmlInputs.length > 0) + cppFile = new TextFile(outputs["cpp"][0].filePath, TextFile.WriteOnly); + listFile = new TextFile(outputs["qt.qml.pluginlist"][0].filePath, + TextFile.WriteOnly); + if (cppFile) + cppFile.writeLine("#include <QtPlugin>"); + var plugins = { }; + for (var p in scannerData) { + var plugin = scannerData[p].plugin; + if (!plugin || plugins[plugin]) + continue; + plugins[plugin] = true; + var className = scannerData[p].classname; + if (!className) { + throw "QML plugin '" + plugin + "' is missing a classname entry. " + + "Please add one to the qmldir file."; + } + if (cppFile) + cppFile.writeLine("Q_IMPORT_PLUGIN(" + className + ")"); + var libs = Qml.getLibsForPlugin(scannerData[p], + product.Qt.core.qtBuildVariant, + product.qbs.targetOS, + product.qbs.toolchain, + product.Qt.core.libPath); + listFile.write(libs + ' '); + } + } finally { + if (cppFile) + cppFile.close(); + if (listFile) + listFile.close(); + }; + }; + return [cmd]; + } + } +} |