diff options
Diffstat (limited to 'share')
61 files changed, 3144 insertions, 1843 deletions
diff --git a/share/CMakeLists.txt b/share/CMakeLists.txt index 976111f71..e47bd74f0 100644 --- a/share/CMakeLists.txt +++ b/share/CMakeLists.txt @@ -8,22 +8,8 @@ endif() # below we copy some files that are required to run qbs from the build directory # emulating the same layout we will have after the installation -# copy & install dmgbuild -install( - PROGRAMS ../src/3rdparty/python/bin/dmgbuild - DESTINATION "${QBS_LIBEXEC_INSTALL_DIR}" - ) -set(_DMGBUILD_INSTALL_PATH ${CMAKE_BINARY_DIR}/${QBS_OUTPUT_PREFIX}${QBS_LIBEXEC_INSTALL_DIR}/dmgbuild) -add_custom_command( - OUTPUT ${_DMGBUILD_INSTALL_PATH} - COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_CURRENT_SOURCE_DIR}/../src/3rdparty/python/bin/dmgbuild - ${CMAKE_BINARY_DIR}/${QBS_OUTPUT_PREFIX}${QBS_LIBEXEC_INSTALL_DIR} - COMMENT "Copying dmgbuild script" - ) - # copy & install python packages -set(_SITE_PACKAGES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../src/3rdparty/python/lib/python2.7/site-packages/) +set(_SITE_PACKAGES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../src/3rdparty/python/lib/python3.9/site-packages/) file(GLOB_RECURSE _SITE_PACKAGES_RELATIVE RELATIVE "${_SITE_PACKAGES_DIR}" "${_SITE_PACKAGES_DIR}/*.py") set(_SITE_PACKAGES_SRC ${_SITE_PACKAGES_RELATIVE}) @@ -102,7 +88,6 @@ add_custom_command( add_custom_target( BuildQbsResources ALL DEPENDS - "${_DMGBUILD_INSTALL_PATH}" ${_SITE_PACKAGES_DST} ${_QBS_RESOURCES_DST} "${_QMLTYPES_INSTALL_PATH}" diff --git a/share/qbs/imports/qbs/PathTools/path-tools.js b/share/qbs/imports/qbs/PathTools/path-tools.js index a857a7139..c928c33e4 100644 --- a/share/qbs/imports/qbs/PathTools/path-tools.js +++ b/share/qbs/imports/qbs/PathTools/path-tools.js @@ -232,3 +232,25 @@ function prependOrSetPath(path, pathList, separator) { return path; return path + separator + pathList; } + +function librarySuffixes(targetOS, types, forImport) { + if (targetOS.includes("windows")) { + if (forImport) + return [".lib"]; + return [].concat(types.includes("shared") ? [".dll"] : []); + } + if (targetOS.includes("darwin")) { + return [] + .concat(types.includes("shared") ? [".dylib"] : []) + .concat(types.includes("static") ? [".a"] : []); + } + return [] + .concat(types.includes("shared") ? [".so"] : []) + .concat(types.includes("static") ? [".a"] : []); +} + +function libraryNameFilter(targetOS) { + if (targetOS.contains("unix")) + return function(name) { return "lib" + name; } + return function(name) { return name; } +} diff --git a/share/qbs/imports/qbs/Probes/LibraryProbe.qbs b/share/qbs/imports/qbs/Probes/LibraryProbe.qbs index 7631eb441..d67a81372 100644 --- a/share/qbs/imports/qbs/Probes/LibraryProbe.qbs +++ b/share/qbs/imports/qbs/Probes/LibraryProbe.qbs @@ -28,15 +28,11 @@ ** ****************************************************************************/ +import qbs.PathTools + PathProbe { property string endianness - nameSuffixes: { - if (qbs.targetOS.contains("windows")) - return [".lib"]; - if (qbs.targetOS.contains("macos")) - return [".dylib", ".a"]; - return [".so", ".a"]; - } + nameSuffixes: PathTools.librarySuffixes(qbs.targetOS, ["shared", "static"], true) platformSearchPaths: { var result = []; if (qbs.targetOS.contains("unix")) { @@ -65,17 +61,7 @@ PathProbe { return result; } - nameFilter: { - if (qbs.targetOS.contains("unix")) { - return function(name) { - return "lib" + name; - } - } else { - return function(name) { - return name; - } - } - } + nameFilter: PathTools.libraryNameFilter(qbs.targetOS) platformEnvironmentPaths: { if (qbs.targetOS.contains("windows")) return [ "PATH" ]; diff --git a/share/qbs/imports/qbs/Probes/PkgConfigProbe.qbs b/share/qbs/imports/qbs/Probes/PkgConfigProbe.qbs index 61a9c0b74..0fe81c3cc 100644 --- a/share/qbs/imports/qbs/Probes/PkgConfigProbe.qbs +++ b/share/qbs/imports/qbs/Probes/PkgConfigProbe.qbs @@ -85,6 +85,12 @@ Probe { && p.exec(executable, versionArgs.concat(packageNames)) !== 0) { return; } + + // protobuf is reserved as qbs module name, which depends on the protobuflib module + packageNames = packageNames.map(function(name) { + return name === "protobuflib" ? "protobuf" : name; + }); + var args = packageNames; if (p.exec(executable, args.concat([ '--cflags' ])) === 0) { stdout = p.readStdOut().trim(); diff --git a/share/qbs/imports/qbs/Probes/QbsPkgConfigProbe.qbs b/share/qbs/imports/qbs/Probes/QbsPkgConfigProbe.qbs new file mode 100644 index 000000000..5acec6bc0 --- /dev/null +++ b/share/qbs/imports/qbs/Probes/QbsPkgConfigProbe.qbs @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2021 Ivan Komissarov (abbapoh@gmail.com) +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +import "qbs-pkg-config-probe.js" as PkgConfigProbeConfigure + +Probe { + // Inputs + + property string _executableFilePath + property stringList _extraPaths + property stringList _libDirs + property bool _staticMode: false + property bool _definePrefix: false + + property path _sysroot + + // Output + property var packages + property var packagesByModuleName + property var brokenPackages + property stringList qmakePaths + + configure: { + var result = PkgConfigProbeConfigure.configure( + _executableFilePath, + _extraPaths, + _libDirs, + _staticMode, + _definePrefix, + _sysroot); + packages = result.packages; + packagesByModuleName = result.packagesByModuleName; + brokenPackages = result.brokenPackages; + qmakePaths = result.qmakePaths; + found = true; + } +} diff --git a/share/qbs/imports/qbs/Probes/QmakeProbe.qbs b/share/qbs/imports/qbs/Probes/QmakeProbe.qbs new file mode 100644 index 000000000..c50c6c851 --- /dev/null +++ b/share/qbs/imports/qbs/Probes/QmakeProbe.qbs @@ -0,0 +1,41 @@ + +/**************************************************************************** +** +** Copyright (C) 2023 Ivan Komissarov (abbapoh@gmail.com) +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +import "qmake-probe.js" as QmakeProbeConfigure + +Probe { + property stringList qmakePaths + property varList qtInfos + + configure: { + qtInfos = QmakeProbeConfigure.configure(qmakePaths); + } +} diff --git a/share/qbs/imports/qbs/Probes/qbs-pkg-config-probe.js b/share/qbs/imports/qbs/Probes/qbs-pkg-config-probe.js new file mode 100644 index 000000000..d382dfb02 --- /dev/null +++ b/share/qbs/imports/qbs/Probes/qbs-pkg-config-probe.js @@ -0,0 +1,118 @@ +/**************************************************************************** +** +** Copyright (C) 2023 Ivan Komissarov (abbapoh@gmail.com) +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +var Environment = require("qbs.Environment"); +var File = require("qbs.File"); +var FileInfo = require("qbs.FileInfo"); +var PkgConfig = require("qbs.PkgConfig"); +var ProviderUtils = require("qbs.ProviderUtils"); +var Process = require("qbs.Process"); + +function getQmakePaths(pkg) { + var packageName = pkg.baseFileName; + if (packageName === "QtCore" + || packageName === "Qt5Core" + || packageName === "Qt6Core") { + var binDir = pkg.variables["bindir"] || pkg.variables["host_bins"]; + if (!binDir) { + if (packageName === "QtCore") { // Qt4 does not have host_bins + var mocLocation = pkg.variables["moc_location"]; + if (!mocLocation) { + console.warn("No moc_location variable in " + packageName); + return; + } + binDir = FileInfo.path(mocLocation); + } else { + console.warn("No 'bindir' or 'host_bins' variable in " + packageName); + return; + } + } + var suffix = FileInfo.executableSuffix(); + return [FileInfo.joinPaths(binDir, "qmake" + suffix)]; + } +} + +function configure( + executableFilePath, extraPaths, libDirs, staticMode, definePrefix, sysroot) { + + var result = {}; + result.packages = []; + result.packagesByModuleName = {}; + result.brokenPackages = []; + result.qtInfos = []; + + var options = {}; + options.libDirs = libDirs; + options.sysroot = sysroot; + options.definePrefix = definePrefix; + if (options.sysroot) + options.allowSystemLibraryPaths = true; + options.staticMode = staticMode; + options.extraPaths = extraPaths; + if (options.sysroot && !options.libDirs) { + options.libDirs = [ + options.sysroot + "/usr/lib/pkgconfig", + options.sysroot + "/usr/share/pkgconfig" + ]; + } + if (!options.libDirs) { + // if we have pkg-config/pkgconf installed, let's ask it for its search paths (since + // built-in search paths can differ between platforms) + if (executableFilePath) { + var p = new Process() + if (p.exec(executableFilePath, ['pkg-config', '--variable=pc_path']) === 0) { + var stdout = p.readStdOut().trim(); + options.libDirs = stdout ? stdout.split(FileInfo.pathListSeparator()): []; + var installDir = FileInfo.path(executableFilePath); + options.libDirs = options.libDirs.map(function(path){ + if (FileInfo.isAbsolutePath(path)) + return path; + return FileInfo.cleanPath(FileInfo.joinPaths(installDir, path)); + }); + } + } + } + var pkgConfig = new PkgConfig(options); + result.packages = pkgConfig.packages(); + for (var packageName in result.packages) { + var pkg = result.packages[packageName]; + var moduleName = ProviderUtils.pkgConfigToModuleName(packageName); + result.packagesByModuleName[moduleName] = pkg; + + if (packageName.startsWith("Qt")) { + if (!sysroot) { + var qmakePaths = getQmakePaths(pkg); + if (qmakePaths !== undefined) + result.qmakePaths = qmakePaths; + } + } + } + return result; +} diff --git a/share/qbs/imports/qbs/Probes/qmake-probe.js b/share/qbs/imports/qbs/Probes/qmake-probe.js new file mode 100644 index 000000000..746914e20 --- /dev/null +++ b/share/qbs/imports/qbs/Probes/qmake-probe.js @@ -0,0 +1,1256 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qbs. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +var Environment = require("qbs.Environment"); +var File = require("qbs.File"); +var FileInfo = require("qbs.FileInfo"); +var Host = require("qbs.Host"); +var Process = require("qbs.Process"); +var ProviderUtils = require("qbs.ProviderUtils"); +var TextFile = require("qbs.TextFile"); +var Utilities = require("qbs.Utilities"); + +function splitNonEmpty(s, c) { return s.split(c).filter(function(e) { return e; }); } + +function getQmakeFilePaths(qmakeFilePaths) { + if (qmakeFilePaths && qmakeFilePaths.length > 0) + return qmakeFilePaths; + console.info("Detecting Qt installations..."); + var filePaths = []; + var pathValue = Environment.getEnv("PATH"); + if (pathValue) { + var dirs = splitNonEmpty(pathValue, FileInfo.pathListSeparator()); + for (var i = 0; i < dirs.length; ++i) { + var candidate = FileInfo.joinPaths(dirs[i], "qmake" + FileInfo.executableSuffix()); + var canonicalCandidate = FileInfo.canonicalPath(candidate); + if (!canonicalCandidate || !File.exists(canonicalCandidate)) + continue; + if (FileInfo.completeBaseName(canonicalCandidate) !== "qtchooser") + candidate = canonicalCandidate; + if (!filePaths.contains(candidate)) { + console.info("Found Qt at '" + FileInfo.toNativeSeparators(candidate) + "'."); + filePaths.push(candidate); + } + } + } + if (filePaths.length === 0) { + console.warn("Could not find any qmake executables in PATH. Either make sure a qmake " + + "executable is present in PATH or set the moduleProviders.Qt.qmakeFilePaths property " + + "to point to a qmake executable."); + } + return filePaths; +} + +function queryQmake(qmakeFilePath) { + var qmakeProcess = new Process; + qmakeProcess.exec(qmakeFilePath, ["-query"]); + if (qmakeProcess.exitCode() !== 0) { + throw "The qmake executable '" + FileInfo.toNativeSeparators(qmakeFilePath) + + "' failed with exit code " + qmakeProcess.exitCode() + "."; + } + var queryResult = {}; + while (!qmakeProcess.atEnd()) { + var line = qmakeProcess.readLine(); + var index = (line || "").indexOf(":"); + if (index !== -1) + queryResult[line.slice(0, index)] = line.slice(index + 1).trim(); + } + return queryResult; +} + +function pathQueryValue(queryResult, key) { + var p = queryResult[key]; + if (p) + return FileInfo.fromNativeSeparators(p); +} + +function readFileContent(filePath) { + var f = new TextFile(filePath, TextFile.ReadOnly); + var content = f.readAll(); + f.close(); + return content; +} + +// TODO: Don't do the split every time... +function configVariable(configContent, key) { + var configContentLines = configContent.split('\n'); + var regexp = new RegExp("^\\s*" + key + "\\s*\\+{0,1}=(.*)"); + for (var i = 0; i < configContentLines.length; ++i) { + var line = configContentLines[i]; + var match = regexp.exec(line); + if (match) + return match[1].trim(); + } +} + +function configVariableItems(configContent, key) { + return splitNonEmpty(configVariable(configContent, key), ' '); +} + +function msvcCompilerVersionForYear(year) { + var mapping = { + "2005": "14", "2008": "15", "2010": "16", "2012": "17", "2013": "18", "2015": "19", + "2017": "19.1", "2019": "19.2" + }; + return mapping[year]; +} + +function msvcCompilerVersionFromMkspecName(mkspecName) { + return msvcCompilerVersionForYear(mkspecName.slice(msvcPrefix().length)); +} + +function addQtBuildVariant(qtProps, buildVariantName) { + if (qtProps.qtConfigItems.contains(buildVariantName)) + qtProps.buildVariant.push(buildVariantName); +} + +function checkForStaticBuild(qtProps) { + if (qtProps.qtMajorVersion >= 5) + return qtProps.qtConfigItems.contains("static"); + if (qtProps.frameworkBuild) + return false; // there are no Qt4 static frameworks + var isWin = qtProps.mkspecName.startsWith("win"); + var libDir = isWin ? qtProps.binaryPath : qtProps.libraryPath; + var coreLibFiles = File.directoryEntries(libDir, File.Files) + .filter(function(fp) { return fp.contains("Core"); }); + if (coreLibFiles.length === 0) + throw "Could not determine whether Qt is a static build."; + for (var i = 0; i < coreLibFiles.length; ++i) { + if (Utilities.isSharedLibrary(coreLibFiles[i])) + return false; + } + return true; +} + +function guessMinimumWindowsVersion(qtProps) { + if (qtProps.mkspecName.startsWith("winrt-")) + return "10.0"; + if (!ProviderUtils.isDesktopWindowsQt(qtProps)) + return ""; + if (qtProps.qtMajorVersion >= 6) + return "10.0"; + if (qtProps.architecture === "x86_64" || qtProps.architecture === "ia64") + return "5.2" + var match = qtProps.mkspecName.match(/^win32-msvc(\d+)$/); + if (match) { + var msvcVersion = match[1]; + if (msvcVersion < 2012) + return "5.0"; + return "5.1"; + } + return qtProps.qtMajorVersion < 5 ? "5.0" : "5.1"; +} + +function fillEntryPointLibs(qtProps, debug) { + result = []; + var isMinGW = ProviderUtils.isMinGwQt(qtProps); + + // Some Linux distributions rename the qtmain library. + var qtMainCandidates = ["qtmain"]; + if (isMinGW && qtProps.qtMajorVersion === 5) + qtMainCandidates.push("qt5main"); + if (qtProps.qtMajorVersion === 6) + qtMainCandidates.push("Qt6EntryPoint"); + + for (var i = 0; i < qtMainCandidates.length; ++i) { + var baseNameCandidate = qtMainCandidates[i]; + var qtmain = qtProps.libraryPath + '/'; + if (isMinGW) + qtmain += "lib"; + qtmain += baseNameCandidate + qtProps.qtLibInfix; + if (debug && ProviderUtils.qtNeedsDSuffix(qtProps)) + qtmain += 'd'; + if (isMinGW) { + qtmain += ".a"; + } else { + qtmain += ".lib"; + if (Utilities.versionCompare(qtProps.qtVersion, "5.4.0") >= 0) + result.push("Shell32.lib"); + } + if (File.exists(qtmain)) { + result.push(qtmain); + break; + } + } + if (result.length === 0) { + console.warn("Could not find the qtmain library at '" + + FileInfo.toNativeSeparators(qtProps.libraryPath) + + "'. You will not be able to link Qt applications."); + } + return result; +} + +function getQtProperties(qmakeFilePath) { + var queryResult = queryQmake(qmakeFilePath); + var qtProps = {}; + qtProps.installPrefixPath = pathQueryValue(queryResult, "QT_INSTALL_PREFIX"); + qtProps.documentationPath = pathQueryValue(queryResult, "QT_INSTALL_DOCS"); + qtProps.includePath = pathQueryValue(queryResult, "QT_INSTALL_HEADERS"); + qtProps.libraryPath = pathQueryValue(queryResult, "QT_INSTALL_LIBS"); + qtProps.hostLibraryPath = pathQueryValue(queryResult, "QT_HOST_LIBS"); + qtProps.binaryPath = pathQueryValue(queryResult, "QT_HOST_BINS") + || pathQueryValue(queryResult, "QT_INSTALL_BINS"); + qtProps.installPath = pathQueryValue(queryResult, "QT_INSTALL_BINS"); + qtProps.documentationPath = pathQueryValue(queryResult, "QT_INSTALL_DOCS"); + qtProps.pluginPath = pathQueryValue(queryResult, "QT_INSTALL_PLUGINS"); + qtProps.qmlPath = pathQueryValue(queryResult, "QT_INSTALL_QML"); + qtProps.qmlImportPath = pathQueryValue(queryResult, "QT_INSTALL_IMPORTS"); + qtProps.qtVersion = queryResult.QT_VERSION; + + var mkspecsBaseSrcPath; + if (Utilities.versionCompare(qtProps.qtVersion, "5") >= 0) { + qtProps.mkspecBasePath = FileInfo.joinPaths(pathQueryValue(queryResult, "QT_HOST_DATA"), + "mkspecs"); + mkspecsBaseSrcPath = FileInfo.joinPaths(pathQueryValue(queryResult, "QT_HOST_DATA/src"), + "mkspecs"); + } else { + qtProps.mkspecBasePath = FileInfo.joinPaths + (pathQueryValue(queryResult, "QT_INSTALL_DATA"), "mkspecs"); + } + + if (Utilities.versionCompare(qtProps.qtVersion, "6") >= 0) { + qtProps.libExecPath = pathQueryValue(queryResult, "QT_HOST_LIBEXECS") + || pathQueryValue(queryResult, "QT_INSTALL_LIBEXECS"); + } + + // QML tools were only moved in Qt 6.2. + qtProps.qmlLibExecPath = Utilities.versionCompare(qtProps.qtVersion, "6.2") >= 0 + ? qtProps.libExecPath : qtProps.binaryPath; + + // qhelpgenerator was only moved in Qt 6.3. + qtProps.helpGeneratorLibExecPath = Utilities.versionCompare(qtProps.qtVersion, "6.3") >= 0 + ? qtProps.libExecPath : qtProps.binaryPath; + + if (!File.exists(qtProps.mkspecBasePath)) + throw "Cannot extract the mkspecs directory."; + + var qconfigContent = readFileContent(FileInfo.joinPaths(qtProps.mkspecBasePath, + "qconfig.pri")); + qtProps.qtMajorVersion = parseInt(configVariable(qconfigContent, "QT_MAJOR_VERSION")); + qtProps.qtMinorVersion = parseInt(configVariable(qconfigContent, "QT_MINOR_VERSION")); + qtProps.qtPatchVersion = parseInt(configVariable(qconfigContent, "QT_PATCH_VERSION")); + qtProps.qtNameSpace = configVariable(qconfigContent, "QT_NAMESPACE"); + qtProps.qtLibInfix = configVariable(qconfigContent, "QT_LIBINFIX") || ""; + qtProps.architecture = configVariable(qconfigContent, "QT_TARGET_ARCH") + || configVariable(qconfigContent, "QT_ARCH") || "x86"; + qtProps.configItems = configVariableItems(qconfigContent, "CONFIG"); + qtProps.qtConfigItems = configVariableItems(qconfigContent, "QT_CONFIG"); + + // retrieve the mkspec + if (qtProps.qtMajorVersion >= 5) { + qtProps.mkspecName = queryResult.QMAKE_XSPEC; + qtProps.mkspecPath = FileInfo.joinPaths(qtProps.mkspecBasePath, qtProps.mkspecName); + if (mkspecsBaseSrcPath && !File.exists(qtProps.mkspecPath)) + qtProps.mkspecPath = FileInfo.joinPaths(mkspecsBaseSrcPath, qtProps.mkspecName); + } else { + if (Host.os().contains("windows")) { + var baseDirPath = FileInfo.joinPaths(qtProps.mkspecBasePath, "default"); + var fileContent = readFileContent(FileInfo.joinPaths(baseDirPath, "qmake.conf")); + qtProps.mkspecPath = configVariable(fileContent, "QMAKESPEC_ORIGINAL"); + if (!File.exists(qtProps.mkspecPath)) { + // Work around QTBUG-28792. + // The value of QMAKESPEC_ORIGINAL is wrong for MinGW packages. Y u h8 me? + var match = fileContent.exec(/\binclude\(([^)]+)\/qmake\.conf\)/m); + if (match) { + qtProps.mkspecPath = FileInfo.cleanPath(FileInfo.joinPaths( + baseDirPath, match[1])); + } + } + } else { + qtProps.mkspecPath = FileInfo.canonicalPath( + FileInfo.joinPaths(qtProps.mkspecBasePath, "default")); + } + + // E.g. in qmake.conf for Qt 4.8/mingw we find this gem: + // QMAKESPEC_ORIGINAL=C:\\Qt\\Qt\\4.8\\mingw482\\mkspecs\\win32-g++ + qtProps.mkspecPath = FileInfo.cleanPath(qtProps.mkspecPath); + + qtProps.mkspecName = qtProps.mkspecPath; + var idx = qtProps.mkspecName.lastIndexOf('/'); + if (idx !== -1) + qtProps.mkspecName = qtProps.mkspecName.slice(idx + 1); + } + if (!File.exists(qtProps.mkspecPath)) + throw "mkspec '" + FileInfo.toNativeSeparators(qtProps.mkspecPath) + "' does not exist"; + + // Starting with qt 5.14, android sdk provides multi-abi + if (Utilities.versionCompare(qtProps.qtVersion, "5.14.0") >= 0 + && qtProps.mkspecPath.contains("android")) { + var qdeviceContent = readFileContent(FileInfo.joinPaths(qtProps.mkspecBasePath, + "qdevice.pri")); + qtProps.androidAbis = configVariable(qdeviceContent, "DEFAULT_ANDROID_ABIS").split(' '); + } + + // determine MSVC version + if (ProviderUtils.isMsvcQt(qtProps)) { + var msvcMajor = configVariable(qconfigContent, "QT_MSVC_MAJOR_VERSION"); + var msvcMinor = configVariable(qconfigContent, "QT_MSVC_MINOR_VERSION"); + var msvcPatch = configVariable(qconfigContent, "QT_MSVC_PATCH_VERSION"); + if (msvcMajor && msvcMinor && msvcPatch) + qtProps.msvcVersion = msvcMajor + "." + msvcMinor + "." + msvcPatch; + else + qtProps.msvcVersion = msvcCompilerVersionFromMkspecName(qtProps.mkspecName); + } + + // determine whether we have a framework build + qtProps.frameworkBuild = qtProps.mkspecPath.contains("macx") + && qtProps.configItems.contains("qt_framework"); + + // determine whether Qt is built with debug, release or both + qtProps.buildVariant = []; + addQtBuildVariant(qtProps, "debug"); + addQtBuildVariant(qtProps, "release"); + + qtProps.staticBuild = checkForStaticBuild(qtProps); + + // determine whether user apps require C++11 + if (qtProps.qtConfigItems.contains("c++11") && qtProps.staticBuild) + qtProps.configItems.push("c++11"); + + // Set the minimum operating system versions appropriate for this Qt version + qtProps.windowsVersion = guessMinimumWindowsVersion(qtProps); + if (qtProps.windowsVersion) { // Is target OS Windows? + if (qtProps.buildVariant.contains("debug")) + qtProps.entryPointLibsDebug = fillEntryPointLibs(qtProps, true); + if (qtProps.buildVariant.contains("release")) + qtProps.entryPointLibsRelease = fillEntryPointLibs(qtProps, false); + } else if (qtProps.mkspecPath.contains("macx")) { + if (qtProps.qtMajorVersion >= 5) { + // Since Qt 6.7.1, QMAKE_MACOSX|IOS_DEPLOYMENT_TARGET is no longer present in + // qmake.conf. But it is also present in qconfig.pri, so first try to read it from there + qtProps.macosVersion = configVariable(qconfigContent, "QMAKE_MACOSX_DEPLOYMENT_TARGET"); + qtProps.iosVersion = configVariable(qconfigContent, "QMAKE_IOS_DEPLOYMENT_TARGET"); + + // Next, we override the value from qmake.conf, if present there + // Note, that TVOS/WATCHOS variables are only present in qmake.conf (as of Qt 6.7.1) + var lines = getFileContentsRecursively(FileInfo.joinPaths(qtProps.mkspecPath, + "qmake.conf")); + for (var i = 0; i < lines.length; ++i) { + var line = lines[i].trim(); + match = line.match + (/^QMAKE_(MACOSX|IOS|TVOS|WATCHOS)_DEPLOYMENT_TARGET\s*=\s*(.*)\s*$/); + if (match) { + var platform = match[1]; + var version = match[2]; + if (platform === "MACOSX") + qtProps.macosVersion = version; + else if (platform === "IOS") + qtProps.iosVersion = version; + else if (platform === "TVOS") + qtProps.tvosVersion = version; + else if (platform === "WATCHOS") + qtProps.watchosVersion = version; + } + } + var isMac = qtProps.mkspecName !== "macx-ios-clang" + && qtProps.mkspecName !== "macx-tvos-clang" + && qtProps.mkspecName !== "macx-watchos-clang"; + if (isMac) { + // Qt 5.0.x placed the minimum version in a different file + if (!qtProps.macosVersion) + qtProps.macosVersion = "10.6"; + + // If we're using C++11 with libc++, make sure the deployment target is >= 10.7 + if (Utilities.versionCompare(qtProps.macosVersion, "10, 7") < 0 + && qtProps.qtConfigItems.contains("c++11")) { + qtProps.macosVersion = "10.7"; + } + } + } else if (qtProps.qtMajorVersion === 4 && qtProps.qtMinorVersion >= 6) { + var qconfigDir = qtProps.frameworkBuild + ? FileInfo.joinPaths(qtProps.libraryPath, "QtCore.framework", "Headers") + : FileInfo.joinPaths(qtProps.includePath, "Qt"); + try { + var qconfig = new TextFile(FileInfo.joinPaths(qconfigDir, "qconfig.h"), + TextFile.ReadOnly); + var qtCocoaBuild = false; + var ok = true; + do { + line = qconfig.readLine(); + if (line.match(/\s*#define\s+QT_MAC_USE_COCOA\s+1\s*/)) { + qtCocoaBuild = true; + break; + } + } while (!qconfig.atEof()); + qtProps.macosVersion = qtCocoaBuild ? "10.5" : "10.4"; + } + catch (e) {} + finally { + if (qconfig) + qconfig.close(); + } + if (!qtProps.macosVersion) { + throw "Could not determine whether Qt is using Cocoa or Carbon from '" + + FileInfo.toNativeSeparators(qconfig.filePath()) + "'."; + } + } + } else if (qtProps.mkspecPath.contains("android")) { + if (qtProps.qtMajorVersion >= 5) + qtProps.androidVersion = "2.3"; + else if (qtProps.qtMajorVersion === 4 && qtProps.qtMinorVersion >= 8) + qtProps.androidVersion = "1.6"; // Necessitas + } + return qtProps; +} + +function makePluginData() { + var pluginData = {}; + pluginData.type = undefined; + pluginData.className = undefined; + pluginData.autoLoad = true; + pluginData["extends"] = []; + return pluginData; +} + +function makeQtModuleInfo(name, qbsName, deps) { + var moduleInfo = {}; + moduleInfo.name = name; // As in the path to the headers and ".name" in the pri files. + if (moduleInfo.name === undefined) + moduleInfo.name = ""; + moduleInfo.qbsName = qbsName; // Lower-case version without "qt" prefix. + moduleInfo.dependencies = deps || []; // qbs names. + if (moduleInfo.qbsName && moduleInfo.qbsName !== "core" + && !moduleInfo.dependencies.contains("core")) { + moduleInfo.dependencies.unshift("core"); + } + moduleInfo.isPrivate = qbsName && qbsName.endsWith("-private"); + moduleInfo.hasLibrary = !moduleInfo.isPrivate; + moduleInfo.isStaticLibrary = false; + moduleInfo.isPlugin = false; + moduleInfo.mustExist = true; + moduleInfo.modulePrefix = ""; // empty value means "Qt". + moduleInfo.version = undefined; + moduleInfo.includePaths = []; + moduleInfo.compilerDefines = []; + moduleInfo.staticLibrariesDebug = []; + moduleInfo.staticLibrariesRelease = []; + moduleInfo.dynamicLibrariesDebug = []; + moduleInfo.dynamicLibrariesRelease = []; + moduleInfo.linkerFlagsDebug = []; + moduleInfo.linkerFlagsRelease = []; + moduleInfo.libFilePathDebug = undefined; + moduleInfo.libFilePathRelease = undefined; + moduleInfo.frameworksDebug = []; + moduleInfo.frameworksRelease = []; + moduleInfo.frameworkPathsDebug = []; + moduleInfo.frameworkPathsRelease = []; + moduleInfo.libraryPaths = []; + moduleInfo.libDir = ""; + moduleInfo.config = []; + moduleInfo.supportedPluginTypes = []; + moduleInfo.pluginData = makePluginData(); + return moduleInfo; +} + +function frameworkHeadersPath(qtModuleInfo, qtProps) { + return FileInfo.joinPaths(qtProps.libraryPath, qtModuleInfo.name + ".framework", "Headers"); +} + +function qt4ModuleIncludePaths(qtModuleInfo, qtProps) { + var paths = []; + if (ProviderUtils.qtIsFramework(qtModuleInfo, qtProps)) + paths.push(frameworkHeadersPath(qtModuleInfo, qtProps)); + else + paths.push(qtProps.includePath, FileInfo.joinPaths(qtProps.includePath, qtModuleInfo.name)); + return paths; +} + +// We erroneously called the "testlib" module "test" for quite a while. Let's not punish users +// for that. +function addTestModule(modules) { + var testModule = makeQtModuleInfo("QtTest", "test", ["testlib"]); + testModule.hasLibrary = false; + modules.push(testModule); +} + +// See above. +function addDesignerComponentsModule(modules) { + var module = makeQtModuleInfo("QtDesignerComponents", "designercomponents", + ["designercomponents-private"]); + module.hasLibrary = false; + modules.push(module); +} + +function guessLibraryFilePath(prlFilePath, libDir, qtProps) { + var baseName = FileInfo.baseName(prlFilePath); + var prefixCandidates = ["", "lib"]; + var suffixCandidates = ["so." + qtProps.qtVersion, "so", "a", "lib", "dll.a"]; + for (var i = 0; i < prefixCandidates.length; ++i) { + var prefix = prefixCandidates[i]; + for (var j = 0; j < suffixCandidates.length; ++j) { + var suffix = suffixCandidates[j]; + var candidate = FileInfo.joinPaths(libDir, prefix + baseName + '.' + suffix); + if (File.exists(candidate)) + return candidate; + } + } +} + +function doReplaceQtLibNamesWithFilePath(namePathMap, libList) { + for (var i = 0; i < libList.length; ++i) { + var lib = libList[i]; + var path = namePathMap[lib]; + if (path) + libList[i] = path; + } +} + +function replaceQtLibNamesWithFilePath(modules, qtProps) { + // We don't want to add the libraries for Qt modules via "-l", because of the + // danger that a wrong one will be picked up, e.g. from /usr/lib. Instead, + // we pull them in using the full file path. + var linkerNamesToFilePathsDebug = {}; + var linkerNamesToFilePathsRelease = {}; + for (var i = 0; i < modules.length; ++i) { + var m = modules[i]; + linkerNamesToFilePathsDebug[ + ProviderUtils.qtLibNameForLinker(m, qtProps, true)] = m.libFilePathDebug; + linkerNamesToFilePathsRelease[ + ProviderUtils.qtLibNameForLinker(m, qtProps, false)] = m.libFilePathRelease; + } + for (i = 0; i < modules.length; ++i) { + var module = modules[i]; + doReplaceQtLibNamesWithFilePath(linkerNamesToFilePathsDebug, module.dynamicLibrariesDebug); + doReplaceQtLibNamesWithFilePath(linkerNamesToFilePathsDebug, module.staticLibrariesDebug); + doReplaceQtLibNamesWithFilePath(linkerNamesToFilePathsRelease, + module.dynamicLibrariesRelease); + doReplaceQtLibNamesWithFilePath(linkerNamesToFilePathsRelease, + module.staticLibrariesRelease); + } +} + +function doSetupLibraries(modInfo, qtProps, debugBuild, nonExistingPrlFiles, androidAbi) { + if (!modInfo.hasLibrary) + return; // Can happen for Qt4 convenience modules, like "widgets". + + if (debugBuild) { + if (!qtProps.buildVariant.contains("debug")) + return; + var modulesNeverBuiltAsDebug = ["bootstrap", "qmldevtools"]; + for (var i = 0; i < modulesNeverBuiltAsDebug.length; ++i) { + var m = modulesNeverBuiltAsDebug[i]; + if (modInfo.qbsName === m || modInfo.qbsName === m + "-private") + return; + } + } else if (!qtProps.buildVariant.contains("release")) { + return; + } + + var libs = modInfo.isStaticLibrary + ? (debugBuild ? modInfo.staticLibrariesDebug : modInfo.staticLibrariesRelease) + : (debugBuild ? modInfo.dynamicLibrariesDebug : modInfo.dynamicLibrariesRelease); + var frameworks = debugBuild ? modInfo.frameworksDebug : modInfo.frameworksRelease; + var frameworkPaths = debugBuild ? modInfo.frameworkPathsDebug : modInfo.frameworkPathsRelease; + var flags = debugBuild ? modInfo.linkerFlagsDebug : modInfo.linkerFlagsRelease; + var libFilePath; + + if (qtProps.mkspecName.contains("ios") && modInfo.isStaticLibrary) { + libs.push("z", "m"); + if (qtProps.qtMajorVersion === 5 && qtProps.qtMinorVersion < 8) { + var platformSupportModule = makeQtModuleInfo("QtPlatformSupport", "platformsupport"); + libs.push(ProviderUtils.qtLibNameForLinker(platformSupportModule, qtProps, debugBuild)); + } + if (modInfo.name === "qios") { + flags.push("-force_load", FileInfo.joinPaths( + qtProps.pluginPath, "platforms", + ProviderUtils.qtLibBaseName( + modInfo, "libqios", debugBuild, qtProps) + ".a")); + } + } + var prlFilePath = modInfo.isPlugin + ? FileInfo.joinPaths(qtProps.pluginPath, modInfo.pluginData.type) + : (modInfo.libDir ? modInfo.libDir : qtProps.libraryPath); + var libDir = prlFilePath; + if (ProviderUtils.qtIsFramework(modInfo, qtProps)) { + prlFilePath = FileInfo.joinPaths( + prlFilePath, + ProviderUtils.qtLibraryBaseName(modInfo, qtProps, false) + ".framework"); + libDir = prlFilePath; + if (Utilities.versionCompare(qtProps.qtVersion, "5.14") >= 0) + prlFilePath = FileInfo.joinPaths(prlFilePath, "Resources"); + } + var baseName = ProviderUtils.qtLibraryBaseName(modInfo, qtProps, debugBuild); + if (!qtProps.mkspecName.startsWith("win") && !ProviderUtils.qtIsFramework(modInfo, qtProps)) + baseName = "lib" + baseName; + prlFilePath = FileInfo.joinPaths(prlFilePath, baseName); + var isNonStaticQt4OnWindows = qtProps.mkspecName.startsWith("win") + && !modInfo.isStaticLibrary && qtProps.qtMajorVersion < 5; + if (isNonStaticQt4OnWindows) + prlFilePath = prlFilePath.slice(0, prlFilePath.length - 1); // The prl file base name does *not* contain the version number... + // qt for android versions 6.0 and 6.1 don't have the architecture suffix in the prl file + if (androidAbi.length > 0 + && modInfo.name !== "QtBootstrap" + && (modInfo.name !== "QtQmlDevTools" || modInfo.name === "QtQmlDevTools" + && Utilities.versionCompare(qtProps.qtVersion, "6.2") >= 0) + && (Utilities.versionCompare(qtProps.qtVersion, "6.0") < 0 + || Utilities.versionCompare(qtProps.qtVersion, "6.2") >= 0)) { + prlFilePath += "_"; + prlFilePath += androidAbi; + } + + prlFilePath += ".prl"; + + try { + var prlFile = new TextFile(prlFilePath, TextFile.ReadOnly); + while (!prlFile.atEof()) { + var line = prlFile.readLine().trim(); + var equalsOffset = line.indexOf('='); + if (equalsOffset === -1) + continue; + if (line.startsWith("QMAKE_PRL_TARGET")) { + var isMingw = qtProps.mkspecName.startsWith("win") + && qtProps.mkspecName.contains("g++"); + var isQtVersionBefore56 = qtProps.qtMajorVersion < 5 + || (qtProps.qtMajorVersion === 5 && qtProps.qtMinorVersion < 6); + + // QMAKE_PRL_TARGET has a "lib" prefix, except for mingw. + // Of course, the exception has an exception too: For static libs, mingw *does* + // have the "lib" prefix. + var libFileName = ""; + if (isQtVersionBefore56 && qtProps.qtMajorVersion === 5 && isMingw + && !modInfo.isStaticLibrary) { + libFileName += "lib"; + } + + libFileName += line.slice(equalsOffset + 1).trim(); + if (isNonStaticQt4OnWindows) + libFileName += 4; // This is *not* part of QMAKE_PRL_TARGET... + if (isQtVersionBefore56) { + if (qtProps.mkspecName.contains("msvc")) { + libFileName += ".lib"; + } else if (isMingw) { + libFileName += ".a"; + if (!File.exists(FileInfo.joinPaths(libDir, libFileName))) + libFileName = libFileName.slice(0, -2) + ".dll"; + } + } + libFilePath = FileInfo.joinPaths(libDir, libFileName); + continue; + } + if (line.startsWith("QMAKE_PRL_CONFIG")) { + modInfo.config = splitNonEmpty(line.slice(equalsOffset + 1).trim(), ' '); + continue; + } + if (!line.startsWith("QMAKE_PRL_LIBS =")) + continue; + + var parts = extractPaths(line.slice(equalsOffset + 1).trim(), prlFilePath); + for (i = 0; i < parts.length; ++i) { + var part = parts[i]; + part = part.replace("$$[QT_INSTALL_LIBS]", qtProps.libraryPath); + part = part.replace("$$[QT_INSTALL_PLUGINS]", qtProps.pluginPath); + part = part.replace("$$[QT_INSTALL_PREFIX]", qtProps.installPrefixPath); + if (part.startsWith("-l")) { + libs.push(part.slice(2)); + } else if (part.startsWith("-L")) { + modInfo.libraryPaths.push(part.slice(2)); + } else if (part.startsWith("-F")) { + frameworkPaths.push(part.slice(2)); + } else if (part === "-framework") { + if (++i < parts.length) + frameworks.push(parts[i]); + } else if (part === "-pthread") { + // prl files for android have QMAKE_PRL_LIBS = -llog -pthread but the pthread + // functionality is included in libc. + if (androidAbi.length === 0) + libs.push("pthread"); + } else if (part.startsWith('-')) { // Some other option + console.debug("QMAKE_PRL_LIBS contains non-library option '" + part + + "' in file '" + prlFilePath + "'"); + flags.push(part); + } else if (part.startsWith("/LIBPATH:")) { + libraryPaths.push(part.slice(9).replace(/\\/g, '/')); + } else { // Assume it's a file path/name. + libs.push(part.replace(/\\/g, '/')); + } + } + } + } catch (e) { + // qt_ext_lib_extX.pri (usually) don't have a corresponding prl file. + // So the pri file variable QMAKE_LIBS_LIBX points to the library + if (modInfo.isExternal) { + libFilePath = debugBuild ? modInfo.staticLibrariesDebug[0] : + modInfo.staticLibrariesRelease[0]; + } + if (!libFilePath || !File.exists(libFilePath)) + libFilePath = guessLibraryFilePath(prlFilePath, libDir, qtProps); + if (nonExistingPrlFiles.contains(prlFilePath)) + return; + nonExistingPrlFiles.push(prlFilePath); + if (modInfo.mustExist) { + console.warn("Could not open prl file '" + + FileInfo.toNativeSeparators(prlFilePath) + "' for module '" + + modInfo.name + + "' (" + e + "), and failed to deduce the library file path. " + + " This module will likely not be usable by qbs."); + } + } + finally { + if (prlFile) + prlFile.close(); + } + + if (debugBuild) + modInfo.libFilePathDebug = libFilePath; + else + modInfo.libFilePathRelease = libFilePath; +} + +function setupLibraries(qtModuleInfo, qtProps, nonExistingPrlFiles, androidAbi) { + doSetupLibraries(qtModuleInfo, qtProps, true, nonExistingPrlFiles, androidAbi); + doSetupLibraries(qtModuleInfo, qtProps, false, nonExistingPrlFiles, androidAbi); +} + +function allQt4Modules(qtProps) { + // as per http://doc.qt.io/qt-4.8/modules.html + private stuff. + var modules = []; + + var core = makeQtModuleInfo("QtCore", "core"); + core.compilerDefines.push("QT_CORE_LIB"); + if (qtProps.qtNameSpace) + core.compilerDefines.push("QT_NAMESPACE=" + qtProps.qtNameSpace); + modules.push(core, + makeQtModuleInfo("QtCore", "core-private", ["core"]), + makeQtModuleInfo("QtGui", "gui"), + makeQtModuleInfo("QtGui", "gui-private", ["gui"]), + makeQtModuleInfo("QtMultimedia", "multimedia", ["gui", "network"]), + makeQtModuleInfo("QtMultimedia", "multimedia-private", ["multimedia"]), + makeQtModuleInfo("QtNetwork", "network"), + makeQtModuleInfo("QtNetwork", "network-private", ["network"]), + makeQtModuleInfo("QtOpenGL", "opengl", ["gui"]), + makeQtModuleInfo("QtOpenGL", "opengl-private", ["opengl"]), + makeQtModuleInfo("QtOpenVG", "openvg", ["gui"]), + makeQtModuleInfo("QtScript", "script"), + makeQtModuleInfo("QtScript", "script-private", ["script"]), + makeQtModuleInfo("QtScriptTools", "scripttools", ["script", "gui"]), + makeQtModuleInfo("QtScriptTools", "scripttools-private", ["scripttools"]), + makeQtModuleInfo("QtSql", "sql"), + makeQtModuleInfo("QtSql", "sql-private", ["sql"]), + makeQtModuleInfo("QtSvg", "svg", ["gui"]), + makeQtModuleInfo("QtSvg", "svg-private", ["svg"]), + makeQtModuleInfo("QtWebKit", "webkit", ["gui", "network"]), + makeQtModuleInfo("QtWebKit", "webkit-private", ["webkit"]), + makeQtModuleInfo("QtXml", "xml"), + makeQtModuleInfo("QtXml", "xml-private", ["xml"]), + makeQtModuleInfo("QtXmlPatterns", "xmlpatterns", ["network"]), + makeQtModuleInfo("QtXmlPatterns", "xmlpatterns-private", ["xmlpatterns"]), + makeQtModuleInfo("QtDeclarative", "declarative", ["gui", "script"]), + makeQtModuleInfo("QtDeclarative", "declarative-private", ["declarative"]), + makeQtModuleInfo("QtDesigner", "designer", ["gui", "xml"]), + makeQtModuleInfo("QtDesigner", "designer-private", ["designer"]), + makeQtModuleInfo("QtUiTools", "uitools"), + makeQtModuleInfo("QtUiTools", "uitools-private", ["uitools"]), + makeQtModuleInfo("QtHelp", "help", ["network", "sql"]), + makeQtModuleInfo("QtHelp", "help-private", ["help"]), + makeQtModuleInfo("QtTest", "testlib"), + makeQtModuleInfo("QtTest", "testlib-private", ["testlib"])); + if (qtProps.mkspecName.startsWith("win")) { + var axcontainer = makeQtModuleInfo("QAxContainer", "axcontainer"); + axcontainer.modulePrefix = "Q"; + axcontainer.isStaticLibrary = true; + axcontainer.includePaths.push(FileInfo.joinPaths(qtProps.includePath, "ActiveQt")); + modules.push(axcontainer); + + var axserver = makeQtModuleInfo("QAxServer", "axserver"); + axserver.modulePrefix = "Q"; + axserver.isStaticLibrary = true; + axserver.compilerDefines.push("QAXSERVER"); + axserver.includePaths.push(FileInfo.joinPaths(qtProps.includePath, "ActiveQt")); + modules.push(axserver); + } else { + modules.push(makeQtModuleInfo("QtDBus", "dbus")); + modules.push(makeQtModuleInfo("QtDBus", "dbus-private", ["dbus"])); + } + + var designerComponentsPrivate = makeQtModuleInfo( + "QtDesignerComponents", "designercomponents-private", + ["gui-private", "designer-private"]); + designerComponentsPrivate.hasLibrary = true; + modules.push(designerComponentsPrivate); + + var phonon = makeQtModuleInfo("Phonon", "phonon"); + phonon.includePaths = qt4ModuleIncludePaths(phonon, qtProps); + modules.push(phonon); + + // Set up include paths that haven't been set up before this point. + for (i = 0; i < modules.length; ++i) { + var module = modules[i]; + if (module.includePaths.length > 0) + continue; + module.includePaths = qt4ModuleIncludePaths(module, qtProps); + } + + // Set up compiler defines haven't been set up before this point. + for (i = 0; i < modules.length; ++i) { + module = modules[i]; + if (module.compilerDefines.length > 0) + continue; + module.compilerDefines.push("QT_" + module.qbsName.toUpperCase() + "_LIB"); + } + + // These are for the convenience of project file authors. It allows them + // to add a dependency to e.g. "Qt.widgets" without a version check. + var virtualModule = makeQtModuleInfo(undefined, "widgets", ["core", "gui"]); + virtualModule.hasLibrary = false; + modules.push(virtualModule); + virtualModule = makeQtModuleInfo(undefined, "quick", ["declarative"]); + virtualModule.hasLibrary = false; + modules.push(virtualModule); + virtualModule = makeQtModuleInfo(undefined, "concurrent"); + virtualModule.hasLibrary = false; + modules.push(virtualModule); + virtualModule = makeQtModuleInfo(undefined, "printsupport", ["core", "gui"]); + virtualModule.hasLibrary = false; + modules.push(virtualModule); + + addTestModule(modules); + addDesignerComponentsModule(modules); + + var modulesThatCanBeDisabled = [ + "xmlpatterns", "multimedia", "phonon", "svg", "webkit", "script", "scripttools", + "declarative", "gui", "dbus", "opengl", "openvg"]; + var nonExistingPrlFiles = []; + for (i = 0; i < modules.length; ++i) { + module = modules[i]; + var name = module.qbsName; + var privateIndex = name.indexOf("-private"); + if (privateIndex !== -1) + name = name.slice(0, privateIndex); + if (modulesThatCanBeDisabled.contains(name)) + module.mustExist = false; + if (qtProps.staticBuild) + module.isStaticLibrary = true; + setupLibraries(module, qtProps, nonExistingPrlFiles, ""); + } + replaceQtLibNamesWithFilePath(modules, qtProps); + + return modules; +} + +function getFileContentsRecursively(filePath) { + var file = new TextFile(filePath, TextFile.ReadOnly); + var lines = splitNonEmpty(file.readAll(), '\n'); + for (var i = 0; i < lines.length; ++i) { + var includeString = "include("; + var line = lines[i].trim(); + if (!line.startsWith(includeString)) + continue; + var offset = includeString.length; + var closingParenPos = line.indexOf(')', offset); + if (closingParenPos === -1) { + console.warn("Invalid include statement in '" + + FileInfo.toNativeSeparators(filePath) + "'"); + continue; + } + var includedFilePath = line.slice(offset, closingParenPos); + if (!FileInfo.isAbsolutePath(includedFilePath)) + includedFilePath = FileInfo.joinPaths(FileInfo.path(filePath), includedFilePath); + var includedContents = getFileContentsRecursively(includedFilePath); + var j = i; + for (var k = 0; k < includedContents.length; ++k) + lines.splice(++j, 0, includedContents[k]); + lines.splice(i--, 1); + } + file.close(); + return lines; +} + +function extractPaths(rhs, filePath) { + var paths = []; + var startIndex = 0; + for (;;) { + while (startIndex < rhs.length && rhs.charAt(startIndex) === ' ') + ++startIndex; + if (startIndex >= rhs.length) + break; + var endIndex; + if (rhs.charAt(startIndex) === '"') { + ++startIndex; + endIndex = rhs.indexOf('"', startIndex); + if (endIndex === -1) { + console.warn("Unmatched quote in file '" + + FileInfo.toNativeSeparators(filePath) + "'"); + break; + } + } else { + endIndex = rhs.indexOf(' ', startIndex + 1); + if (endIndex === -1) + endIndex = rhs.length; + } + paths.push(FileInfo.cleanPath(rhs.slice(startIndex, endIndex) + .replace("$$PWD", FileInfo.path(filePath)))); + startIndex = endIndex + 1; + } + return paths; +} + +function removeDuplicatedDependencyLibs(modules) { + var revDeps = {}; + var currentPath = []; + var getLibraries; + var getLibFilePath; + + function setupReverseDependencies(modules) { + var moduleByName = {}; + for (var i = 0; i < modules.length; ++i) + moduleByName[modules[i].qbsName] = modules[i]; + for (i = 0; i < modules.length; ++i) { + var module = modules[i]; + for (var j = 0; j < module.dependencies.length; ++j) { + var depmod = moduleByName[module.dependencies[j]]; + if (!depmod) + continue; + if (!revDeps[depmod.qbsName]) + revDeps[depmod.qbsName] = []; + revDeps[depmod.qbsName].push(module); + } + } + } + + function roots(modules) { + var result = []; + for (i = 0; i < modules.length; ++i) { + var module = modules[i] + if (module.dependencies.length === 0) + result.push(module); + } + return result; + } + + function traverse(module, libs) { + if (currentPath.contains(module)) + return; + currentPath.push(module); + var moduleLibraryLists = getLibraries(module); + for (var i = 0; i < moduleLibraryLists.length; ++i) { + var modLibList = moduleLibraryLists[i]; + for (j = modLibList.length - 1; j >= 0; --j) { + if (libs.contains(modLibList[j])) + modLibList.splice(j, 1); + } + } + + var libFilePath = getLibFilePath(module); + if (libFilePath) + libs.push(libFilePath); + for (i = 0; i < moduleLibraryLists.length; ++i) + libs = libs.concat(moduleLibraryLists[i]); + libs.sort(); + + var deps = revDeps[module.qbsName]; + for (i = 0; i < (deps || []).length; ++i) + traverse(deps[i], libs); + + currentPath.pop(); + } + + setupReverseDependencies(modules); + + // Traverse the debug variants of modules. + getLibraries = function(module) { + return [module.dynamicLibrariesDebug, module.staticLibrariesDebug]; + }; + getLibFilePath = function(module) { return module.libFilePathDebug; }; + var rootModules = roots(modules); + for (var i = 0; i < rootModules.length; ++i) + traverse(rootModules[i], []); + + // Traverse the release variants of modules. + getLibraries = function(module) { + return [module.dynamicLibrariesRelease, module.staticLibrariesRelease]; + }; + getLibFilePath = function(module) { return module.libFilePathRelease; }; + for (i = 0; i < rootModules.length; ++i) + traverse(rootModules[i], []); +} + +function allQt5Modules(qtProps, androidAbi) { + var nonExistingPrlFiles = []; + var modules = []; + var modulesDir = FileInfo.joinPaths(qtProps.mkspecBasePath, "modules"); + var modulePriFiles = File.directoryEntries(modulesDir, File.Files); + for (var i = 0; i < modulePriFiles.length; ++i) { + var priFileName = modulePriFiles[i]; + var priFilePath = FileInfo.joinPaths(modulesDir, priFileName); + var externalFileNamePrefix = "qt_ext_"; + var moduleFileNamePrefix = "qt_lib_"; + var pluginFileNamePrefix = "qt_plugin_"; + var moduleFileNameSuffix = ".pri"; + var fileHasExternalPrefix = priFileName.startsWith(externalFileNamePrefix); + var fileHasModulePrefix = priFileName.startsWith(moduleFileNamePrefix); + var fileHasPluginPrefix = priFileName.startsWith(pluginFileNamePrefix); + if (!fileHasPluginPrefix && !fileHasModulePrefix && !fileHasExternalPrefix + || !priFileName.endsWith(moduleFileNameSuffix)) { + continue; + } + var moduleInfo = makeQtModuleInfo(); + moduleInfo.isPlugin = fileHasPluginPrefix; + moduleInfo.isExternal = !moduleInfo.isPlugin && !fileHasModulePrefix; + var fileNamePrefix = moduleInfo.isPlugin ? pluginFileNamePrefix : moduleInfo.isExternal + ? externalFileNamePrefix : moduleFileNamePrefix; + moduleInfo.qbsName = priFileName.slice(fileNamePrefix.length, -moduleFileNameSuffix.length); + if (moduleInfo.isPlugin) { + moduleInfo.name = moduleInfo.qbsName; + moduleInfo.isStaticLibrary = true; + } + var moduleKeyPrefix = (moduleInfo.isPlugin ? "QT_PLUGIN" : "QT") + + '.' + moduleInfo.qbsName + '.'; + moduleInfo.qbsName = moduleInfo.qbsName.replace("_private", "-private"); + var hasV2 = false; + var hasModuleEntry = false; + var lines = getFileContentsRecursively(priFilePath); + if (moduleInfo.isExternal) { + moduleInfo.name = "qt" + moduleInfo.qbsName; + moduleInfo.isStaticLibrary = true; + for (var k = 0; k < lines.length; ++k) { + var extLine = lines[k].trim(); + var extFirstEqualsOffset = extLine.indexOf('='); + if (extFirstEqualsOffset === -1) + continue; + var extKey = extLine.slice(0, extFirstEqualsOffset).trim(); + var extValue = extLine.slice(extFirstEqualsOffset + 1).trim(); + if (!extKey.startsWith("QMAKE_") || !extValue) + continue; + + var elements = extKey.split('_'); + if (elements.length >= 3) { + if (elements[1] === "LIBS") { + extValue = extValue.replace("/home/qt/work/qt/qtbase/lib", + qtProps.libraryPath); + extValue = extValue.replace("$$[QT_INSTALL_LIBS]", qtProps.libraryPath); + extValue = extValue.replace("$$[QT_INSTALL_LIBS/get]", qtProps.libraryPath); + if (elements.length === 4 ) { + if (elements[3] === androidAbi) { + moduleInfo.staticLibrariesRelease.push(extValue); + moduleInfo.staticLibrariesDebug.push(extValue); + } + } else if (elements.length === 5 ) { + // That's for "x86_64" + var abi = elements[3] + '_' + elements[4]; + if (abi === androidAbi) { + moduleInfo.staticLibrariesRelease.push(extValue); + moduleInfo.staticLibrariesDebug.push(extValue); + } + } else { + moduleInfo.staticLibrariesRelease.push(extValue); + moduleInfo.staticLibrariesDebug.push(extValue); + } + } else if (elements[1] === "INCDIR") { + moduleInfo.includePaths.push(extValue.replace("$$[QT_INSTALL_HEADERS]", + qtProps.includePath)); + } + } + } + moduleInfo.compilerDefines.push("QT_" + moduleInfo.qbsName.toUpperCase() + "_LIB"); + moduleInfo.mustExist = false; + } else { + for (var j = 0; j < lines.length; ++j) { + var line = lines[j].trim(); + var firstEqualsOffset = line.indexOf('='); + if (firstEqualsOffset === -1) + continue; + var key = line.slice(0, firstEqualsOffset).trim(); + var value = line.slice(firstEqualsOffset + 1).trim(); + if (!key.startsWith(moduleKeyPrefix) || !value) + continue; + if (key.endsWith(".name")) { + moduleInfo.name = value; + } else if (key.endsWith(".module")) { + hasModuleEntry = true; + } else if (key.endsWith(".depends")) { + moduleInfo.dependencies = splitNonEmpty(value, ' '); + for (var k = 0; k < moduleInfo.dependencies.length; ++k) { + moduleInfo.dependencies[k] + = moduleInfo.dependencies[k].replace("_private", "-private"); + } + } else if (key.endsWith(".module_config")) { + var elems = splitNonEmpty(value, ' '); + for (k = 0; k < elems.length; ++k) { + var elem = elems[k]; + if (elem === "no_link") + moduleInfo.hasLibrary = false; + else if (elem === "staticlib") + moduleInfo.isStaticLibrary = true; + else if (elem === "internal_module") + moduleInfo.isPrivate = true; + else if (elem === "v2") + hasV2 = true; + } + } else if (key.endsWith(".includes")) { + moduleInfo.includePaths = extractPaths(value, priFilePath); + for (k = 0; k < moduleInfo.includePaths.length; ++k) { + moduleInfo.includePaths[k] = moduleInfo.includePaths[k] + .replace("$$QT_MODULE_INCLUDE_BASE", qtProps.includePath) + .replace("$$QT_MODULE_HOST_LIB_BASE", qtProps.hostLibraryPath) + .replace("$$QT_MODULE_LIB_BASE", qtProps.libraryPath); + } + } else if (key.endsWith(".libs")) { + var libDirs = extractPaths(value, priFilePath); + if (libDirs.length === 1) { + moduleInfo.libDir = libDirs[0] + .replace("$$QT_MODULE_HOST_LIB_BASE", qtProps.hostLibraryPath) + .replace("$$QT_MODULE_LIB_BASE", qtProps.libraryPath); + } else { + moduleInfo.libDir = qtProps.libraryPath; + } + } else if (key.endsWith(".DEFINES")) { + moduleInfo.compilerDefines = splitNonEmpty(value, ' '); + } else if (key.endsWith(".VERSION")) { + moduleInfo.version = value; + } else if (key.endsWith(".plugin_types")) { + moduleInfo.supportedPluginTypes = splitNonEmpty(value, ' '); + } else if (key.endsWith(".TYPE")) { + moduleInfo.pluginData.type = value; + } else if (key.endsWith(".EXTENDS")) { + moduleInfo.pluginData["extends"] = splitNonEmpty(value, ' '); + for (k = 0; k < moduleInfo.pluginData["extends"].length; ++k) { + if (moduleInfo.pluginData["extends"][k] === "-") { + moduleInfo.pluginData["extends"].splice(k, 1); + moduleInfo.pluginData.autoLoad = false; + break; + } + } + } else if (key.endsWith(".CLASS_NAME")) { + moduleInfo.pluginData.className = value; + } + } + } + if (hasV2 && !hasModuleEntry && !moduleInfo.isStaticLibrary) + moduleInfo.hasLibrary = false; + + // Fix include paths for Apple frameworks. + // The qt_lib_XXX.pri files contain wrong values for versions < 5.6. + if (!hasV2 && ProviderUtils.qtIsFramework(moduleInfo, qtProps)) { + moduleInfo.includePaths = []; + var baseIncDir = frameworkHeadersPath(moduleInfo, qtProps); + if (moduleInfo.isPrivate) { + baseIncDir = FileInfo.joinPaths(baseIncDir, moduleInfo.version); + moduleInfo.includePaths.push(baseIncDir, + FileInfo.joinPaths(baseIncDir, moduleInfo.name)); + } else { + moduleInfo.includePaths.push(baseIncDir); + } + } + + setupLibraries(moduleInfo, qtProps, nonExistingPrlFiles, androidAbi); + + modules.push(moduleInfo); + if (moduleInfo.qbsName === "testlib") + addTestModule(modules); + if (moduleInfo.qbsName === "designercomponents-private") + addDesignerComponentsModule(modules); + } + + replaceQtLibNamesWithFilePath(modules, qtProps); + removeDuplicatedDependencyLibs(modules); + + return modules; +} + +function getQtInfo(qmakeFilePath) { + if (!File.exists(qmakeFilePath)) { + throw "The specified qmake file path '" + + FileInfo.toNativeSeparators(qmakeFilePath) + "' does not exist."; + } + var qtProps = getQtProperties(qmakeFilePath); + var androidAbis = []; + if (qtProps.androidAbis !== undefined) { + // Multiple androidAbis detected: Qt >= 5.14 + androidAbis = qtProps.androidAbis; + } else { + // Single abi detected: Qt < 5.14 + androidAbis.push(''); + } + if (androidAbis.length > 1) + console.info("Qt with multiple abi detected: '" + androidAbis + "'"); + + var result = {}; + result.qtProps = qtProps; + result.abiInfos = []; + result.qmakeFilePath = qmakeFilePath; + for (a = 0; a < androidAbis.length; ++a) { + var abiInfo = {}; + if (androidAbis.length > 1) + console.info("Found abi '" + androidAbis[a] + "'..."); + abiInfo.androidAbi = androidAbis[a]; + var allModules = qtProps.qtMajorVersion < 5 + ? allQt4Modules(qtProps) : allQt5Modules(qtProps, androidAbis[a]);; + abiInfo.modules = {}; + for (var i = 0; i < allModules.length; ++i) { + var module = allModules[i]; + abiInfo.modules[module.qbsName] = module; + } + abiInfo.pluginsByType = {}; + abiInfo.nonEssentialPlugins = []; + for (var moduleName in abiInfo.modules) { + var m = abiInfo.modules[moduleName]; + if (m.isPlugin) { + if (!abiInfo.pluginsByType[m.pluginData.type]) + abiInfo.pluginsByType[m.pluginData.type] = []; + abiInfo.pluginsByType[m.pluginData.type].push(m.name); + if (!m.pluginData.autoLoad) + abiInfo.nonEssentialPlugins.push(m.name); + } + } + + result.abiInfos.push(abiInfo); + } + return result; +} + +function configure(qmakeFilePaths) { + var result = []; + qmakeFilePaths = getQmakeFilePaths(qmakeFilePaths); + if (!qmakeFilePaths || qmakeFilePaths.length === 0) + return result; + for (var i = 0; i < qmakeFilePaths.length; ++i) { + var qtInfo = {}; + try { + console.info("Getting info about Qt at '" + + FileInfo.toNativeSeparators(qmakeFilePaths[i]) + "'..."); + qtInfo = getQtInfo(qmakeFilePaths[i]); + result.push(qtInfo); + } catch (e) { + console.warn("Error getting info about Qt for '" + + FileInfo.toNativeSeparators(qmakeFilePaths[i]) + "': " + e); + throw e; + } + } + return result; +} diff --git a/share/qbs/imports/qbs/ProviderUtils/provider-utils.js b/share/qbs/imports/qbs/ProviderUtils/provider-utils.js new file mode 100644 index 000000000..06e703a7a --- /dev/null +++ b/share/qbs/imports/qbs/ProviderUtils/provider-utils.js @@ -0,0 +1,128 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Copyright (C) 2023 Ivan Komissarov (abbapoh@gmail.com) +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +var Utilities = require("qbs.Utilities"); + +function pkgConfigToModuleName(packageName) { + return packageName.replace(/\./g, '-'); +} + +function msvcPrefix() { return "win32-msvc"; } + +function isMsvcQt(qtProps) { return qtProps.mkspecName.startsWith(msvcPrefix()); } + +function isMinGwQt(qtProps) { + return qtProps.mkspecName.startsWith("win32-g++") || qtProps.mkspecName.startsWith("mingw"); +} + +function isDesktopWindowsQt(qtProps) { + return qtProps.mkspecName.startsWith("win32-") || isMinGwQt(qtProps); +} + +function qtNeedsDSuffix(qtProps) { + return !isMinGwQt(qtProps) + || Utilities.versionCompare(qtProps.qtVersion, "5.14.0") < 0 + || qtProps.configItems.contains("debug_and_release"); +} + +function qtIsFramework(modInfo, qtProps) { + if (!qtProps.frameworkBuild || modInfo.isStaticLibrary) + return false; + var modulesNeverBuiltAsFrameworks = [ + "bootstrap", "openglextensions", "platformsupport", "qmldevtools", "harfbuzzng" + ]; + + if (qtProps.qtMajorVersion <= 5) { + modulesNeverBuiltAsFrameworks.push("uitools"); // is framework since qt6 + } + + return !modulesNeverBuiltAsFrameworks.contains(modInfo.qbsName); +} + +function qtLibBaseName(modInfo, libName, debugBuild, qtProps) { + var name = libName; + if (qtProps.mkspecName.startsWith("win")) { + if (debugBuild && qtNeedsDSuffix(qtProps)) + name += 'd'; + if (!modInfo.isStaticLibrary && qtProps.qtMajorVersion < 5) + name += qtProps.qtMajorVersion; + } + if (qtProps.mkspecName.contains("macx") + || qtProps.mkspecName.contains("ios") + || qtProps.mkspecName.contains("darwin")) { + if (!qtIsFramework(modInfo, qtProps) + && qtProps.buildVariant.contains("debug") + && (!qtProps.buildVariant.contains("release") || debugBuild)) { + name += "_debug"; + } + } + return name; +} + +function qtModuleNameWithoutPrefix(modInfo) { + if (modInfo.name === "Phonon") + return "phonon"; + if (!modInfo.modulePrefix && modInfo.name.startsWith("Qt")) + return modInfo.name.slice(2); // Strip off "Qt". + if (modInfo.name.startsWith(modInfo.modulePrefix)) + return modInfo.name.slice(modInfo.modulePrefix.length); + return modInfo.name; +} + +function qtLibraryBaseName(modInfo, qtProps, debugBuild) { + if (modInfo.isPlugin) + return qtLibBaseName(modInfo, modInfo.name, debugBuild, qtProps); + + // Some modules use a different naming scheme, so it doesn't get boring. + var libNameBroken = modInfo.name === "Enginio" + || modInfo.name === "DataVisualization" + || modInfo.name === "Phonon"; + + var libName = ""; + if (!modInfo.isExternal) { + libName += !modInfo.modulePrefix && !libNameBroken ? "Qt" : modInfo.modulePrefix; + if (qtProps.qtMajorVersion >= 5 && !qtIsFramework(modInfo, qtProps) && !libNameBroken) + libName += qtProps.qtMajorVersion; + } + libName += qtModuleNameWithoutPrefix(modInfo); + if (!modInfo.isExternal) + libName += qtProps.qtLibInfix; + return qtLibBaseName(modInfo, libName, debugBuild, qtProps); +} + +function qtLibNameForLinker(modInfo, qtProps, debugBuild) { + if (!modInfo.hasLibrary) + return undefined; + var libName = qtLibraryBaseName(modInfo, qtProps, debugBuild); + if (qtProps.mkspecName.contains("msvc")) + libName += ".lib"; + return libName; +} diff --git a/share/qbs/imports/qbs/base/AppleApplicationDiskImage.qbs b/share/qbs/imports/qbs/base/AppleApplicationDiskImage.qbs index 6491bf14a..462b96b7c 100644 --- a/share/qbs/imports/qbs/base/AppleApplicationDiskImage.qbs +++ b/share/qbs/imports/qbs/base/AppleApplicationDiskImage.qbs @@ -34,7 +34,8 @@ import qbs.ModUtils AppleDiskImage { property string sourceBase: "/Applications" - readonly property string absoluteSourceBase: FileInfo.joinPaths(qbs.installRoot, sourceBase) + readonly property string absoluteSourceBase: + FileInfo.joinPaths(qbs.installRoot, qbs.installPrefix, sourceBase) property stringList symlinks: ["/Applications:Applications"] readonly property string stageDirectory: FileInfo.joinPaths(destinationDirectory, "Volumes", dmg.volumeName) diff --git a/share/qbs/imports/qbs/base/ApplicationExtension.qbs b/share/qbs/imports/qbs/base/ApplicationExtension.qbs index eae5145ce..3d25d5f73 100644 --- a/share/qbs/imports/qbs/base/ApplicationExtension.qbs +++ b/share/qbs/imports/qbs/base/ApplicationExtension.qbs @@ -34,8 +34,12 @@ XPCService { type: base.concat(["applicationextension"]) property bool _useLegacyExtensionLibraries: - qbs.targetOS.contains("macos") && parseInt(xcode.sdkVersion.split(".")[1], 10) < 11 || - qbs.targetOS.contains("ios") && parseInt(xcode.sdkVersion.split(".")[0], 10) < 9 + qbs.targetOS.contains("macos") + && xcode.present + && parseInt(xcode.sdkVersion.split(".")[1], 10) < 11 + || qbs.targetOS.contains("ios") + && xcode.present + && parseInt(xcode.sdkVersion.split(".")[0], 10) < 9 cpp.entryPoint: "_NSExtensionMain" cpp.frameworkPaths: base.concat(_useLegacyExtensionLibraries diff --git a/share/qbs/module-providers/Qt/templates/QtModule.qbs b/share/qbs/imports/qbs/base/QtModule.qbs index 62e05327b..35421436f 100644 --- a/share/qbs/module-providers/Qt/templates/QtModule.qbs +++ b/share/qbs/imports/qbs/base/QtModule.qbs @@ -23,6 +23,7 @@ Module { // We have to pull in all plugins here, because dependency resolving happens // before module merging, and we don't know yet if someone set // Qt.pluginSupport.pluginsByType in the product. + // TODO: We might be able to use Qt.pluginSupport.pluginsByType now. // The real filtering is done later by the plugin module files themselves. var list = []; var allPlugins = Qt.plugin_support.allPluginsByType; diff --git a/share/qbs/module-providers/Qt/templates/QtPlugin.qbs b/share/qbs/imports/qbs/base/QtPlugin.qbs index 883e34465..883e34465 100644 --- a/share/qbs/module-providers/Qt/templates/QtPlugin.qbs +++ b/share/qbs/imports/qbs/base/QtPlugin.qbs diff --git a/share/qbs/module-providers/Qt/provider.qbs b/share/qbs/module-providers/Qt/provider.qbs index 33083c51d..0d036c04d 100644 --- a/share/qbs/module-providers/Qt/provider.qbs +++ b/share/qbs/module-providers/Qt/provider.qbs @@ -1,6 +1,14 @@ import "setup-qt.js" as SetupQt +import qbs.Probes ModuleProvider { + Probes.QmakeProbe { + id: probe + qmakePaths: qmakeFilePaths + } property stringList qmakeFilePaths - relativeSearchPaths: SetupQt.doSetup(qmakeFilePaths, outputBaseDir, path, qbs) + readonly property varList _qtInfos: probe.qtInfos + condition: moduleName.startsWith("Qt.") + isEager: false + relativeSearchPaths: SetupQt.doSetup(moduleName, _qtInfos, outputBaseDir, path) } diff --git a/share/qbs/module-providers/Qt/setup-qt.js b/share/qbs/module-providers/Qt/setup-qt.js index 08fc8b999..9a314822b 100644 --- a/share/qbs/module-providers/Qt/setup-qt.js +++ b/share/qbs/module-providers/Qt/setup-qt.js @@ -37,1243 +37,13 @@ ** ****************************************************************************/ -var Environment = require("qbs.Environment"); var File = require("qbs.File"); var FileInfo = require("qbs.FileInfo"); -var Host = require("qbs.Host"); var ModUtils = require("qbs.ModUtils"); -var Process = require("qbs.Process"); +var ProviderUtils = require("qbs.ProviderUtils"); var TextFile = require("qbs.TextFile"); var Utilities = require("qbs.Utilities"); -function splitNonEmpty(s, c) { return s.split(c).filter(function(e) { return e; }); } -function toNative(p) { return FileInfo.toNativeSeparators(p); } -function exeSuffix(qbs) { return FileInfo.executableSuffix(); } - -function getQmakeFilePaths(qmakeFilePaths, qbs) { - if (qmakeFilePaths && qmakeFilePaths.length > 0) - return qmakeFilePaths; - console.info("Detecting Qt installations..."); - var filePaths = []; - var pathValue = Environment.getEnv("PATH"); - if (pathValue) { - var dirs = splitNonEmpty(pathValue, FileInfo.pathListSeparator()); - var suffix = exeSuffix(qbs); - for (var i = 0; i < dirs.length; ++i) { - var candidate = FileInfo.joinPaths(dirs[i], "qmake" + suffix); - var canonicalCandidate = FileInfo.canonicalPath(candidate); - if (!canonicalCandidate || !File.exists(canonicalCandidate)) - continue; - if (FileInfo.completeBaseName(canonicalCandidate) !== "qtchooser") - candidate = canonicalCandidate; - if (!filePaths.contains(candidate)) { - console.info("Found Qt at '" + toNative(candidate) + "'."); - filePaths.push(candidate); - } - } - } - if (filePaths.length === 0) { - console.warn("Could not find any qmake executables in PATH. Either make sure a qmake " - + "executable is present in PATH or set the moduleProviders.Qt.qmakeFilePaths property " - + "to point a qmake executable."); - } - return filePaths; -} - -function queryQmake(qmakeFilePath) { - var qmakeProcess = new Process; - qmakeProcess.exec(qmakeFilePath, ["-query"]); - if (qmakeProcess.exitCode() !== 0) { - throw "The qmake executable '" + toNative(qmakeFilePath) + "' failed with exit code " - + qmakeProcess.exitCode() + "."; - } - var queryResult = {}; - while (!qmakeProcess.atEnd()) { - var line = qmakeProcess.readLine(); - var index = (line || "").indexOf(":"); - if (index !== -1) - queryResult[line.slice(0, index)] = line.slice(index + 1).trim(); - } - return queryResult; -} - -function pathQueryValue(queryResult, key) { - var p = queryResult[key]; - if (p) - return FileInfo.fromNativeSeparators(p); -} - -function readFileContent(filePath) { - var f = new TextFile(filePath, TextFile.ReadOnly); - var content = f.readAll(); - f.close(); - return content; -} - -// TODO: Don't do the split every time... -function configVariable(configContent, key) { - var configContentLines = configContent.split('\n'); - var regexp = new RegExp("^\\s*" + key + "\\s*\\+{0,1}=(.*)"); - for (var i = 0; i < configContentLines.length; ++i) { - var line = configContentLines[i]; - var match = regexp.exec(line); - if (match) - return match[1].trim(); - } -} - -function configVariableItems(configContent, key) { - return splitNonEmpty(configVariable(configContent, key), ' '); -} - -function msvcPrefix() { return "win32-msvc"; } - -function isMsvcQt(qtProps) { return qtProps.mkspecName.startsWith(msvcPrefix()); } - -function msvcCompilerVersionForYear(year) { - var mapping = { - "2005": "14", "2008": "15", "2010": "16", "2012": "17", "2013": "18", "2015": "19", - "2017": "19.1", "2019": "19.2" - }; - return mapping[year]; -} - -function msvcCompilerVersionFromMkspecName(mkspecName) { - return msvcCompilerVersionForYear(mkspecName.slice(msvcPrefix().length)); -} - -function addQtBuildVariant(qtProps, buildVariantName) { - if (qtProps.qtConfigItems.contains(buildVariantName)) - qtProps.buildVariant.push(buildVariantName); -} - -function checkForStaticBuild(qtProps) { - if (qtProps.qtMajorVersion >= 5) - return qtProps.qtConfigItems.contains("static"); - if (qtProps.frameworkBuild) - return false; // there are no Qt4 static frameworks - var isWin = qtProps.mkspecName.startsWith("win"); - var libDir = isWin ? qtProps.binaryPath : qtProps.libraryPath; - var coreLibFiles = File.directoryEntries(libDir, File.Files) - .filter(function(fp) { return fp.contains("Core"); }); - if (coreLibFiles.length === 0) - throw "Could not determine whether Qt is a static build."; - for (var i = 0; i < coreLibFiles.length; ++i) { - if (Utilities.isSharedLibrary(coreLibFiles[i])) - return false; - } - return true; -} - -function isForMinGw(qtProps) { - return qtProps.mkspecName.startsWith("win32-g++") || qtProps.mkspecName.startsWith("mingw"); -} - -function targetsDesktopWindows(qtProps) { - return qtProps.mkspecName.startsWith("win32-") || isForMinGw(qtProps); -} - -function guessMinimumWindowsVersion(qtProps) { - if (qtProps.mkspecName.startsWith("winrt-")) - return "10.0"; - if (!targetsDesktopWindows(qtProps)) - return ""; - if (qtProps.qtMajorVersion >= 6) - return "10.0"; - if (qtProps.architecture === "x86_64" || qtProps.architecture === "ia64") - return "5.2" - var match = qtProps.mkspecName.match(/^win32-msvc(\d+)$/); - if (match) { - var msvcVersion = match[1]; - if (msvcVersion < 2012) - return "5.0"; - return "5.1"; - } - return qtProps.qtMajorVersion < 5 ? "5.0" : "5.1"; -} - -function needsDSuffix(qtProps) { - return !isForMinGw(qtProps) || Utilities.versionCompare(qtProps.qtVersion, "5.14.0") < 0 - || qtProps.configItems.contains("debug_and_release"); -} - -function fillEntryPointLibs(qtProps, debug) { - result = []; - var isMinGW = isForMinGw(qtProps); - - // Some Linux distributions rename the qtmain library. - var qtMainCandidates = ["qtmain"]; - if (isMinGW && qtProps.qtMajorVersion === 5) - qtMainCandidates.push("qt5main"); - if (qtProps.qtMajorVersion === 6) - qtMainCandidates.push("Qt6EntryPoint"); - - for (var i = 0; i < qtMainCandidates.length; ++i) { - var baseNameCandidate = qtMainCandidates[i]; - var qtmain = qtProps.libraryPath + '/'; - if (isMinGW) - qtmain += "lib"; - qtmain += baseNameCandidate + qtProps.qtLibInfix; - if (debug && needsDSuffix(qtProps)) - qtmain += 'd'; - if (isMinGW) { - qtmain += ".a"; - } else { - qtmain += ".lib"; - if (Utilities.versionCompare(qtProps.qtVersion, "5.4.0") >= 0) - result.push("Shell32.lib"); - } - if (File.exists(qtmain)) { - result.push(qtmain); - break; - } - } - if (result.length === 0) { - console.warn("Could not find the qtmain library at '" + toNative(qtProps.libraryPath) - + "'. You will not be able to link Qt applications."); - } - return result; -} - -function abiToArchitecture(abi) { - switch (abi) { - case "armeabi-v7a": - return "armv7a"; - case "arm64-v8a": - return "arm64"; - case "x86": - case "x86_64": - default: - return abi; - } -} - -function getQtProperties(qmakeFilePath, qbs) { - var queryResult = queryQmake(qmakeFilePath); - var qtProps = {}; - qtProps.installPrefixPath = pathQueryValue(queryResult, "QT_INSTALL_PREFIX"); - qtProps.documentationPath = pathQueryValue(queryResult, "QT_INSTALL_DOCS"); - qtProps.includePath = pathQueryValue(queryResult, "QT_INSTALL_HEADERS"); - qtProps.libraryPath = pathQueryValue(queryResult, "QT_INSTALL_LIBS"); - qtProps.hostLibraryPath = pathQueryValue(queryResult, "QT_HOST_LIBS"); - qtProps.binaryPath = pathQueryValue(queryResult, "QT_HOST_BINS") - || pathQueryValue(queryResult, "QT_INSTALL_BINS"); - qtProps.installPath = pathQueryValue(queryResult, "QT_INSTALL_BINS"); - qtProps.documentationPath = pathQueryValue(queryResult, "QT_INSTALL_DOCS"); - qtProps.pluginPath = pathQueryValue(queryResult, "QT_INSTALL_PLUGINS"); - qtProps.qmlPath = pathQueryValue(queryResult, "QT_INSTALL_QML"); - qtProps.qmlImportPath = pathQueryValue(queryResult, "QT_INSTALL_IMPORTS"); - qtProps.qtVersion = queryResult.QT_VERSION; - - var mkspecsBaseSrcPath; - if (Utilities.versionCompare(qtProps.qtVersion, "5") >= 0) { - qtProps.mkspecBasePath = FileInfo.joinPaths(pathQueryValue(queryResult, "QT_HOST_DATA"), - "mkspecs"); - mkspecsBaseSrcPath = FileInfo.joinPaths(pathQueryValue(queryResult, "QT_HOST_DATA/src"), - "mkspecs"); - } else { - qtProps.mkspecBasePath = FileInfo.joinPaths - (pathQueryValue(queryResult, "QT_INSTALL_DATA"), "mkspecs"); - } - - if (Utilities.versionCompare(qtProps.qtVersion, "6") >= 0) { - qtProps.libExecPath = pathQueryValue(queryResult, "QT_HOST_LIBEXECS") - || pathQueryValue(queryResult, "QT_INSTALL_LIBEXECS"); - } - - // QML tools were only moved in Qt 6.2. - qtProps.qmlLibExecPath = Utilities.versionCompare(qtProps.qtVersion, "6.2") >= 0 - ? qtProps.libExecPath : qtProps.binaryPath; - - // qhelpgenerator was only moved in Qt 6.3. - qtProps.helpGeneratorLibExecPath = Utilities.versionCompare(qtProps.qtVersion, "6.3") >= 0 - ? qtProps.libExecPath : qtProps.binaryPath; - - if (!File.exists(qtProps.mkspecBasePath)) - throw "Cannot extract the mkspecs directory."; - - var qconfigContent = readFileContent(FileInfo.joinPaths(qtProps.mkspecBasePath, - "qconfig.pri")); - qtProps.qtMajorVersion = parseInt(configVariable(qconfigContent, "QT_MAJOR_VERSION")); - qtProps.qtMinorVersion = parseInt(configVariable(qconfigContent, "QT_MINOR_VERSION")); - qtProps.qtPatchVersion = parseInt(configVariable(qconfigContent, "QT_PATCH_VERSION")); - qtProps.qtNameSpace = configVariable(qconfigContent, "QT_NAMESPACE"); - qtProps.qtLibInfix = configVariable(qconfigContent, "QT_LIBINFIX") || ""; - qtProps.architecture = configVariable(qconfigContent, "QT_TARGET_ARCH") - || configVariable(qconfigContent, "QT_ARCH") || "x86"; - qtProps.configItems = configVariableItems(qconfigContent, "CONFIG"); - qtProps.qtConfigItems = configVariableItems(qconfigContent, "QT_CONFIG"); - - // retrieve the mkspec - if (qtProps.qtMajorVersion >= 5) { - qtProps.mkspecName = queryResult.QMAKE_XSPEC; - qtProps.mkspecPath = FileInfo.joinPaths(qtProps.mkspecBasePath, qtProps.mkspecName); - if (mkspecsBaseSrcPath && !File.exists(qtProps.mkspecPath)) - qtProps.mkspecPath = FileInfo.joinPaths(mkspecsBaseSrcPath, qtProps.mkspecName); - } else { - if (Host.os().contains("windows")) { - var baseDirPath = FileInfo.joinPaths(qtProps.mkspecBasePath, "default"); - var fileContent = readFileContent(FileInfo.joinPaths(baseDirPath, "qmake.conf")); - qtProps.mkspecPath = configVariable(fileContent, "QMAKESPEC_ORIGINAL"); - if (!File.exists(qtProps.mkspecPath)) { - // Work around QTBUG-28792. - // The value of QMAKESPEC_ORIGINAL is wrong for MinGW packages. Y u h8 me? - var match = fileContent.exec(/\binclude\(([^)]+)\/qmake\.conf\)/m); - if (match) { - qtProps.mkspecPath = FileInfo.cleanPath(FileInfo.joinPaths( - baseDirPath, match[1])); - } - } - } else { - qtProps.mkspecPath = FileInfo.canonicalPath( - FileInfo.joinPaths(qtProps.mkspecBasePath, "default")); - } - - // E.g. in qmake.conf for Qt 4.8/mingw we find this gem: - // QMAKESPEC_ORIGINAL=C:\\Qt\\Qt\\4.8\\mingw482\\mkspecs\\win32-g++ - qtProps.mkspecPath = FileInfo.cleanPath(qtProps.mkspecPath); - - qtProps.mkspecName = qtProps.mkspecPath; - var idx = qtProps.mkspecName.lastIndexOf('/'); - if (idx !== -1) - qtProps.mkspecName = qtProps.mkspecName.slice(idx + 1); - } - if (!File.exists(qtProps.mkspecPath)) - throw "mkspec '" + toNative(qtProps.mkspecPath) + "' does not exist"; - - // Starting with qt 5.14, android sdk provides multi-abi - if (Utilities.versionCompare(qtProps.qtVersion, "5.14.0") >= 0 - && qtProps.mkspecPath.contains("android")) { - var qdeviceContent = readFileContent(FileInfo.joinPaths(qtProps.mkspecBasePath, - "qdevice.pri")); - qtProps.androidAbis = configVariable(qdeviceContent, "DEFAULT_ANDROID_ABIS").split(' '); - } - - // determine MSVC version - if (isMsvcQt(qtProps)) { - var msvcMajor = configVariable(qconfigContent, "QT_MSVC_MAJOR_VERSION"); - var msvcMinor = configVariable(qconfigContent, "QT_MSVC_MINOR_VERSION"); - var msvcPatch = configVariable(qconfigContent, "QT_MSVC_PATCH_VERSION"); - if (msvcMajor && msvcMinor && msvcPatch) - qtProps.msvcVersion = msvcMajor + "." + msvcMinor + "." + msvcPatch; - else - qtProps.msvcVersion = msvcCompilerVersionFromMkspecName(qtProps.mkspecName); - } - - // determine whether we have a framework build - qtProps.frameworkBuild = qtProps.mkspecPath.contains("macx") - && qtProps.configItems.contains("qt_framework"); - - // determine whether Qt is built with debug, release or both - qtProps.buildVariant = []; - addQtBuildVariant(qtProps, "debug"); - addQtBuildVariant(qtProps, "release"); - - qtProps.staticBuild = checkForStaticBuild(qtProps); - - // determine whether user apps require C++11 - if (qtProps.qtConfigItems.contains("c++11") && qtProps.staticBuild) - qtProps.configItems.push("c++11"); - - // Set the minimum operating system versions appropriate for this Qt version - qtProps.windowsVersion = guessMinimumWindowsVersion(qtProps); - if (qtProps.windowsVersion) { // Is target OS Windows? - if (qtProps.buildVariant.contains("debug")) - qtProps.entryPointLibsDebug = fillEntryPointLibs(qtProps, true); - if (qtProps.buildVariant.contains("release")) - qtProps.entryPointLibsRelease = fillEntryPointLibs(qtProps, false); - } else if (qtProps.mkspecPath.contains("macx")) { - if (qtProps.qtMajorVersion >= 5) { - var lines = getFileContentsRecursively(FileInfo.joinPaths(qtProps.mkspecPath, - "qmake.conf")); - for (var i = 0; i < lines.length; ++i) { - var line = lines[i].trim(); - match = line.match - (/^QMAKE_(MACOSX|IOS|TVOS|WATCHOS)_DEPLOYMENT_TARGET\s*=\s*(.*)\s*$/); - if (match) { - var platform = match[1]; - var version = match[2]; - if (platform === "MACOSX") - qtProps.macosVersion = version; - else if (platform === "IOS") - qtProps.iosVersion = version; - else if (platform === "TVOS") - qtProps.tvosVersion = version; - else if (platform === "WATCHOS") - qtProps.watchosVersion = version; - } - } - var isMac = qtProps.mkspecName !== "macx-ios-clang" - && qtProps.mkspecName !== "macx-tvos-clang" - && qtProps.mkspecName !== "macx-watchos-clang"; - if (isMac) { - // Qt 5.0.x placed the minimum version in a different file - if (!qtProps.macosVersion) - qtProps.macosVersion = "10.6"; - - // If we're using C++11 with libc++, make sure the deployment target is >= 10.7 - if (Utilities.versionCompare(qtProps.macosVersion, "10, 7") < 0 - && qtProps.qtConfigItems.contains("c++11")) { - qtProps.macosVersion = "10.7"; - } - } - } else if (qtProps.qtMajorVersion === 4 && qtProps.qtMinorVersion >= 6) { - var qconfigDir = qtProps.frameworkBuild - ? FileInfo.joinPaths(qtProps.libraryPath, "QtCore.framework", "Headers") - : FileInfo.joinPaths(qtProps.includePath, "Qt"); - try { - var qconfig = new TextFile(FileInfo.joinPaths(qconfigDir, "qconfig.h"), - TextFile.ReadOnly); - var qtCocoaBuild = false; - var ok = true; - do { - line = qconfig.readLine(); - if (line.match(/\s*#define\s+QT_MAC_USE_COCOA\s+1\s*/)) { - qtCocoaBuild = true; - break; - } - } while (!qconfig.atEof()); - qtProps.macosVersion = qtCocoaBuild ? "10.5" : "10.4"; - } - catch (e) {} - finally { - if (qconfig) - qconfig.close(); - } - if (!qtProps.macosVersion) { - throw "Could not determine whether Qt is using Cocoa or Carbon from '" - + toNative(qconfig.filePath()) + "'."; - } - } - } else if (qtProps.mkspecPath.contains("android")) { - if (qtProps.qtMajorVersion >= 5) - qtProps.androidVersion = "2.3"; - else if (qtProps.qtMajorVersion === 4 && qtProps.qtMinorVersion >= 8) - qtProps.androidVersion = "1.6"; // Necessitas - } - return qtProps; -} - -function makePluginData() { - var pluginData = {}; - pluginData.type = undefined; - pluginData.className = undefined; - pluginData.autoLoad = true; - pluginData["extends"] = []; - return pluginData; -} - -function makeQtModuleInfo(name, qbsName, deps) { - var moduleInfo = {}; - moduleInfo.name = name; // As in the path to the headers and ".name" in the pri files. - if (moduleInfo.name === undefined) - moduleInfo.name = ""; - moduleInfo.qbsName = qbsName; // Lower-case version without "qt" prefix. - moduleInfo.dependencies = deps || []; // qbs names. - if (moduleInfo.qbsName && moduleInfo.qbsName !== "core" - && !moduleInfo.dependencies.contains("core")) { - moduleInfo.dependencies.unshift("core"); - } - moduleInfo.isPrivate = qbsName && qbsName.endsWith("-private"); - moduleInfo.hasLibrary = !moduleInfo.isPrivate; - moduleInfo.isStaticLibrary = false; - moduleInfo.isPlugin = false; - moduleInfo.mustExist = true; - moduleInfo.modulePrefix = ""; // empty value means "Qt". - moduleInfo.version = undefined; - moduleInfo.includePaths = []; - moduleInfo.compilerDefines = []; - moduleInfo.staticLibrariesDebug = []; - moduleInfo.staticLibrariesRelease = []; - moduleInfo.dynamicLibrariesDebug = []; - moduleInfo.dynamicLibrariesRelease = []; - moduleInfo.linkerFlagsDebug = []; - moduleInfo.linkerFlagsRelease = []; - moduleInfo.libFilePathDebug = undefined; - moduleInfo.libFilePathRelease = undefined; - moduleInfo.frameworksDebug = []; - moduleInfo.frameworksRelease = []; - moduleInfo.frameworkPathsDebug = []; - moduleInfo.frameworkPathsRelease = []; - moduleInfo.libraryPaths = []; - moduleInfo.libDir = ""; - moduleInfo.config = []; - moduleInfo.supportedPluginTypes = []; - moduleInfo.pluginData = makePluginData(); - return moduleInfo; -} - -function frameworkHeadersPath(qtModuleInfo, qtProps) { - return FileInfo.joinPaths(qtProps.libraryPath, qtModuleInfo.name + ".framework", "Headers"); -} - -function qt4ModuleIncludePaths(qtModuleInfo, qtProps) { - var paths = []; - if (isFramework(qtModuleInfo, qtProps)) - paths.push(frameworkHeadersPath(qtModuleInfo, qtProps)); - else - paths.push(qtProps.includePath, FileInfo.joinPaths(qtProps.includePath, qtModuleInfo.name)); - return paths; -} - -// We erroneously called the "testlib" module "test" for quite a while. Let's not punish users -// for that. -function addTestModule(modules) { - var testModule = makeQtModuleInfo("QtTest", "test", ["testlib"]); - testModule.hasLibrary = false; - modules.push(testModule); -} - -// See above. -function addDesignerComponentsModule(modules) { - var module = makeQtModuleInfo("QtDesignerComponents", "designercomponents", - ["designercomponents-private"]); - module.hasLibrary = false; - modules.push(module); -} - -function isFramework(modInfo, qtProps) { - if (!qtProps.frameworkBuild || modInfo.isStaticLibrary) - return false; - var modulesNeverBuiltAsFrameworks = [ - "bootstrap", "openglextensions", "platformsupport", "qmldevtools", "harfbuzzng" - ]; - - if (qtProps.qtMajorVersion <= 5) { - modulesNeverBuiltAsFrameworks.push("uitools"); // is framework since qt6 - } - - return !modulesNeverBuiltAsFrameworks.contains(modInfo.qbsName); -} - -function libBaseName(modInfo, libName, debugBuild, qtProps) { - var name = libName; - if (qtProps.mkspecName.startsWith("win")) { - if (debugBuild && needsDSuffix(qtProps)) - name += 'd'; - if (!modInfo.isStaticLibrary && qtProps.qtMajorVersion < 5) - name += qtProps.qtMajorVersion; - } - if (qtProps.mkspecName.contains("macx") - || qtProps.mkspecName.contains("ios") - || qtProps.mkspecName.contains("darwin")) { - if (!isFramework(modInfo, qtProps) - && qtProps.buildVariant.contains("debug") - && (!qtProps.buildVariant.contains("release") || debugBuild)) { - name += "_debug"; - } - } - return name; -} - -function moduleNameWithoutPrefix(modInfo) { - if (modInfo.name === "Phonon") - return "phonon"; - if (!modInfo.modulePrefix && modInfo.name.startsWith("Qt")) - return modInfo.name.slice(2); // Strip off "Qt". - if (modInfo.name.startsWith(modInfo.modulePrefix)) - return modInfo.name.slice(modInfo.modulePrefix.length); - return modInfo.name; -} - -function libraryBaseName(modInfo, qtProps, debugBuild) { - if (modInfo.isPlugin) - return libBaseName(modInfo, modInfo.name, debugBuild, qtProps); - - // Some modules use a different naming scheme, so it doesn't get boring. - var libNameBroken = modInfo.name === "Enginio" - || modInfo.name === "DataVisualization" - || modInfo.name === "Phonon"; - - var libName = ""; - if (!modInfo.isExternal) { - libName += !modInfo.modulePrefix && !libNameBroken ? "Qt" : modInfo.modulePrefix; - if (qtProps.qtMajorVersion >= 5 && !isFramework(modInfo, qtProps) && !libNameBroken) - libName += qtProps.qtMajorVersion; - } - libName += moduleNameWithoutPrefix(modInfo); - if (!modInfo.isExternal) - libName += qtProps.qtLibInfix; - return libBaseName(modInfo, libName, debugBuild, qtProps); -} - -function libNameForLinker(modInfo, qtProps, debugBuild) { - if (!modInfo.hasLibrary) - return undefined; - var libName = libraryBaseName(modInfo, qtProps, debugBuild); - if (qtProps.mkspecName.contains("msvc")) - libName += ".lib"; - return libName; -} - -function guessLibraryFilePath(prlFilePath, libDir, qtProps) { - var baseName = FileInfo.baseName(prlFilePath); - var prefixCandidates = ["", "lib"]; - var suffixCandidates = ["so." + qtProps.qtVersion, "so", "a", "lib", "dll.a"]; - for (var i = 0; i < prefixCandidates.length; ++i) { - var prefix = prefixCandidates[i]; - for (var j = 0; j < suffixCandidates.length; ++j) { - var suffix = suffixCandidates[j]; - var candidate = FileInfo.joinPaths(libDir, prefix + baseName + '.' + suffix); - if (File.exists(candidate)) - return candidate; - } - } -} - -function doReplaceQtLibNamesWithFilePath(namePathMap, libList) { - for (var i = 0; i < libList.length; ++i) { - var lib = libList[i]; - var path = namePathMap[lib]; - if (path) - libList[i] = path; - } -} - -function replaceQtLibNamesWithFilePath(modules, qtProps) { - // We don't want to add the libraries for Qt modules via "-l", because of the - // danger that a wrong one will be picked up, e.g. from /usr/lib. Instead, - // we pull them in using the full file path. - var linkerNamesToFilePathsDebug = {}; - var linkerNamesToFilePathsRelease = {}; - for (var i = 0; i < modules.length; ++i) { - var m = modules[i]; - linkerNamesToFilePathsDebug[libNameForLinker(m, qtProps, true)] = m.libFilePathDebug; - linkerNamesToFilePathsRelease[libNameForLinker(m, qtProps, false)] = m.libFilePathRelease; - } - for (i = 0; i < modules.length; ++i) { - var module = modules[i]; - doReplaceQtLibNamesWithFilePath(linkerNamesToFilePathsDebug, module.dynamicLibrariesDebug); - doReplaceQtLibNamesWithFilePath(linkerNamesToFilePathsDebug, module.staticLibrariesDebug); - doReplaceQtLibNamesWithFilePath(linkerNamesToFilePathsRelease, - module.dynamicLibrariesRelease); - doReplaceQtLibNamesWithFilePath(linkerNamesToFilePathsRelease, - module.staticLibrariesRelease); - } -} - -function doSetupLibraries(modInfo, qtProps, debugBuild, nonExistingPrlFiles, androidAbi) { - if (!modInfo.hasLibrary) - return; // Can happen for Qt4 convenience modules, like "widgets". - - if (debugBuild) { - if (!qtProps.buildVariant.contains("debug")) - return; - var modulesNeverBuiltAsDebug = ["bootstrap", "qmldevtools"]; - for (var i = 0; i < modulesNeverBuiltAsDebug.length; ++i) { - var m = modulesNeverBuiltAsDebug[i]; - if (modInfo.qbsName === m || modInfo.qbsName === m + "-private") - return; - } - } else if (!qtProps.buildVariant.contains("release")) { - return; - } - - var libs = modInfo.isStaticLibrary - ? (debugBuild ? modInfo.staticLibrariesDebug : modInfo.staticLibrariesRelease) - : (debugBuild ? modInfo.dynamicLibrariesDebug : modInfo.dynamicLibrariesRelease); - var frameworks = debugBuild ? modInfo.frameworksDebug : modInfo.frameworksRelease; - var frameworkPaths = debugBuild ? modInfo.frameworkPathsDebug : modInfo.frameworkPathsRelease; - var flags = debugBuild ? modInfo.linkerFlagsDebug : modInfo.linkerFlagsRelease; - var libFilePath; - - if (qtProps.mkspecName.contains("ios") && modInfo.isStaticLibrary) { - libs.push("z", "m"); - if (qtProps.qtMajorVersion === 5 && qtProps.qtMinorVersion < 8) { - var platformSupportModule = makeQtModuleInfo("QtPlatformSupport", "platformsupport"); - libs.push(libNameForLinker(platformSupportModule, qtProps, debugBuild)); - } - if (modInfo.name === "qios") { - flags.push("-force_load", FileInfo.joinPaths( - qtProps.pluginPath, "platforms", - libBaseName(modInfo, "libqios", debugBuild, qtProps) + ".a")); - } - } - var prlFilePath = modInfo.isPlugin - ? FileInfo.joinPaths(qtProps.pluginPath, modInfo.pluginData.type) - : (modInfo.libDir ? modInfo.libDir : qtProps.libraryPath); - var libDir = prlFilePath; - if (isFramework(modInfo, qtProps)) { - prlFilePath = FileInfo.joinPaths(prlFilePath, - libraryBaseName(modInfo, qtProps, false) + ".framework"); - libDir = prlFilePath; - if (Utilities.versionCompare(qtProps.qtVersion, "5.14") >= 0) - prlFilePath = FileInfo.joinPaths(prlFilePath, "Resources"); - } - var baseName = libraryBaseName(modInfo, qtProps, debugBuild); - if (!qtProps.mkspecName.startsWith("win") && !isFramework(modInfo, qtProps)) - baseName = "lib" + baseName; - prlFilePath = FileInfo.joinPaths(prlFilePath, baseName); - var isNonStaticQt4OnWindows = qtProps.mkspecName.startsWith("win") - && !modInfo.isStaticLibrary && qtProps.qtMajorVersion < 5; - if (isNonStaticQt4OnWindows) - prlFilePath = prlFilePath.slice(0, prlFilePath.length - 1); // The prl file base name does *not* contain the version number... - // qt for android versions 6.0 and 6.1 don't have the architecture suffix in the prl file - if (androidAbi.length > 0 - && modInfo.name !== "QtBootstrap" - && (modInfo.name !== "QtQmlDevTools" || modInfo.name === "QtQmlDevTools" - && Utilities.versionCompare(qtProps.qtVersion, "6.2") >= 0) - && (Utilities.versionCompare(qtProps.qtVersion, "6.0") < 0 - || Utilities.versionCompare(qtProps.qtVersion, "6.2") >= 0)) { - prlFilePath += "_"; - prlFilePath += androidAbi; - } - - prlFilePath += ".prl"; - - try { - var prlFile = new TextFile(prlFilePath, TextFile.ReadOnly); - while (!prlFile.atEof()) { - var line = prlFile.readLine().trim(); - var equalsOffset = line.indexOf('='); - if (equalsOffset === -1) - continue; - if (line.startsWith("QMAKE_PRL_TARGET")) { - var isMingw = qtProps.mkspecName.startsWith("win") - && qtProps.mkspecName.contains("g++"); - var isQtVersionBefore56 = qtProps.qtMajorVersion < 5 - || (qtProps.qtMajorVersion === 5 && qtProps.qtMinorVersion < 6); - - // QMAKE_PRL_TARGET has a "lib" prefix, except for mingw. - // Of course, the exception has an exception too: For static libs, mingw *does* - // have the "lib" prefix. - var libFileName = ""; - if (isQtVersionBefore56 && qtProps.qtMajorVersion === 5 && isMingw - && !modInfo.isStaticLibrary) { - libFileName += "lib"; - } - - libFileName += line.slice(equalsOffset + 1).trim(); - if (isNonStaticQt4OnWindows) - libFileName += 4; // This is *not* part of QMAKE_PRL_TARGET... - if (isQtVersionBefore56) { - if (qtProps.mkspecName.contains("msvc")) { - libFileName += ".lib"; - } else if (isMingw) { - libFileName += ".a"; - if (!File.exists(FileInfo.joinPaths(libDir, libFileName))) - libFileName = libFileName.slice(0, -2) + ".dll"; - } - } - libFilePath = FileInfo.joinPaths(libDir, libFileName); - continue; - } - if (line.startsWith("QMAKE_PRL_CONFIG")) { - modInfo.config = splitNonEmpty(line.slice(equalsOffset + 1).trim(), ' '); - continue; - } - if (!line.startsWith("QMAKE_PRL_LIBS =")) - continue; - - var parts = extractPaths(line.slice(equalsOffset + 1).trim(), prlFilePath); - for (i = 0; i < parts.length; ++i) { - var part = parts[i]; - part = part.replace("$$[QT_INSTALL_LIBS]", qtProps.libraryPath); - part = part.replace("$$[QT_INSTALL_PLUGINS]", qtProps.pluginPath); - part = part.replace("$$[QT_INSTALL_PREFIX]", qtProps.installPrefixPath); - if (part.startsWith("-l")) { - libs.push(part.slice(2)); - } else if (part.startsWith("-L")) { - modInfo.libraryPaths.push(part.slice(2)); - } else if (part.startsWith("-F")) { - frameworkPaths.push(part.slice(2)); - } else if (part === "-framework") { - if (++i < parts.length) - frameworks.push(parts[i]); - } else if (part === "-pthread") { - // prl files for android have QMAKE_PRL_LIBS = -llog -pthread but the pthread - // functionality is included in libc. - if (androidAbi.length === 0) - libs.push("pthread"); - } else if (part.startsWith('-')) { // Some other option - console.debug("QMAKE_PRL_LIBS contains non-library option '" + part - + "' in file '" + prlFilePath + "'"); - flags.push(part); - } else if (part.startsWith("/LIBPATH:")) { - libraryPaths.push(part.slice(9).replace(/\\/g, '/')); - } else { // Assume it's a file path/name. - libs.push(part.replace(/\\/g, '/')); - } - } - } - } catch (e) { - // qt_ext_lib_extX.pri (usually) don't have a corresponding prl file. - // So the pri file variable QMAKE_LIBS_LIBX points to the library - if (modInfo.isExternal) { - libFilePath = debugBuild ? modInfo.staticLibrariesDebug[0] : - modInfo.staticLibrariesRelease[0]; - } - if (!libFilePath || !File.exists(libFilePath)) - libFilePath = guessLibraryFilePath(prlFilePath, libDir, qtProps); - if (nonExistingPrlFiles.contains(prlFilePath)) - return; - nonExistingPrlFiles.push(prlFilePath); - if (modInfo.mustExist) { - console.warn("Could not open prl file '" + toNative(prlFilePath) + "' for module '" - + modInfo.name - + "' (" + e + "), and failed to deduce the library file path. " - + " This module will likely not be usable by qbs."); - } - } - finally { - if (prlFile) - prlFile.close(); - } - - if (debugBuild) - modInfo.libFilePathDebug = libFilePath; - else - modInfo.libFilePathRelease = libFilePath; -} - -function setupLibraries(qtModuleInfo, qtProps, nonExistingPrlFiles, androidAbi) { - doSetupLibraries(qtModuleInfo, qtProps, true, nonExistingPrlFiles, androidAbi); - doSetupLibraries(qtModuleInfo, qtProps, false, nonExistingPrlFiles, androidAbi); -} - -function allQt4Modules(qtProps) { - // as per http://doc.qt.io/qt-4.8/modules.html + private stuff. - var modules = []; - - var core = makeQtModuleInfo("QtCore", "core"); - core.compilerDefines.push("QT_CORE_LIB"); - if (qtProps.qtNameSpace) - core.compilerDefines.push("QT_NAMESPACE=" + qtProps.qtNameSpace); - modules.push(core, - makeQtModuleInfo("QtCore", "core-private", ["core"]), - makeQtModuleInfo("QtGui", "gui"), - makeQtModuleInfo("QtGui", "gui-private", ["gui"]), - makeQtModuleInfo("QtMultimedia", "multimedia", ["gui", "network"]), - makeQtModuleInfo("QtMultimedia", "multimedia-private", ["multimedia"]), - makeQtModuleInfo("QtNetwork", "network"), - makeQtModuleInfo("QtNetwork", "network-private", ["network"]), - makeQtModuleInfo("QtOpenGL", "opengl", ["gui"]), - makeQtModuleInfo("QtOpenGL", "opengl-private", ["opengl"]), - makeQtModuleInfo("QtOpenVG", "openvg", ["gui"]), - makeQtModuleInfo("QtScript", "script"), - makeQtModuleInfo("QtScript", "script-private", ["script"]), - makeQtModuleInfo("QtScriptTools", "scripttools", ["script", "gui"]), - makeQtModuleInfo("QtScriptTools", "scripttools-private", ["scripttools"]), - makeQtModuleInfo("QtSql", "sql"), - makeQtModuleInfo("QtSql", "sql-private", ["sql"]), - makeQtModuleInfo("QtSvg", "svg", ["gui"]), - makeQtModuleInfo("QtSvg", "svg-private", ["svg"]), - makeQtModuleInfo("QtWebKit", "webkit", ["gui", "network"]), - makeQtModuleInfo("QtWebKit", "webkit-private", ["webkit"]), - makeQtModuleInfo("QtXml", "xml"), - makeQtModuleInfo("QtXml", "xml-private", ["xml"]), - makeQtModuleInfo("QtXmlPatterns", "xmlpatterns", ["network"]), - makeQtModuleInfo("QtXmlPatterns", "xmlpatterns-private", ["xmlpatterns"]), - makeQtModuleInfo("QtDeclarative", "declarative", ["gui", "script"]), - makeQtModuleInfo("QtDeclarative", "declarative-private", ["declarative"]), - makeQtModuleInfo("QtDesigner", "designer", ["gui", "xml"]), - makeQtModuleInfo("QtDesigner", "designer-private", ["designer"]), - makeQtModuleInfo("QtUiTools", "uitools"), - makeQtModuleInfo("QtUiTools", "uitools-private", ["uitools"]), - makeQtModuleInfo("QtHelp", "help", ["network", "sql"]), - makeQtModuleInfo("QtHelp", "help-private", ["help"]), - makeQtModuleInfo("QtTest", "testlib"), - makeQtModuleInfo("QtTest", "testlib-private", ["testlib"])); - if (qtProps.mkspecName.startsWith("win")) { - var axcontainer = makeQtModuleInfo("QAxContainer", "axcontainer"); - axcontainer.modulePrefix = "Q"; - axcontainer.isStaticLibrary = true; - axcontainer.includePaths.push(FileInfo.joinPaths(qtProps.includePath, "ActiveQt")); - modules.push(axcontainer); - - var axserver = makeQtModuleInfo("QAxServer", "axserver"); - axserver.modulePrefix = "Q"; - axserver.isStaticLibrary = true; - axserver.compilerDefines.push("QAXSERVER"); - axserver.includePaths.push(FileInfo.joinPaths(qtProps.includePath, "ActiveQt")); - modules.push(axserver); - } else { - modules.push(makeQtModuleInfo("QtDBus", "dbus")); - modules.push(makeQtModuleInfo("QtDBus", "dbus-private", ["dbus"])); - } - - var designerComponentsPrivate = makeQtModuleInfo( - "QtDesignerComponents", "designercomponents-private", - ["gui-private", "designer-private"]); - designerComponentsPrivate.hasLibrary = true; - modules.push(designerComponentsPrivate); - - var phonon = makeQtModuleInfo("Phonon", "phonon"); - phonon.includePaths = qt4ModuleIncludePaths(phonon, qtProps); - modules.push(phonon); - - // Set up include paths that haven't been set up before this point. - for (i = 0; i < modules.length; ++i) { - var module = modules[i]; - if (module.includePaths.length > 0) - continue; - module.includePaths = qt4ModuleIncludePaths(module, qtProps); - } - - // Set up compiler defines haven't been set up before this point. - for (i = 0; i < modules.length; ++i) { - module = modules[i]; - if (module.compilerDefines.length > 0) - continue; - module.compilerDefines.push("QT_" + module.qbsName.toUpperCase() + "_LIB"); - } - - // These are for the convenience of project file authors. It allows them - // to add a dependency to e.g. "Qt.widgets" without a version check. - var virtualModule = makeQtModuleInfo(undefined, "widgets", ["core", "gui"]); - virtualModule.hasLibrary = false; - modules.push(virtualModule); - virtualModule = makeQtModuleInfo(undefined, "quick", ["declarative"]); - virtualModule.hasLibrary = false; - modules.push(virtualModule); - virtualModule = makeQtModuleInfo(undefined, "concurrent"); - virtualModule.hasLibrary = false; - modules.push(virtualModule); - virtualModule = makeQtModuleInfo(undefined, "printsupport", ["core", "gui"]); - virtualModule.hasLibrary = false; - modules.push(virtualModule); - - addTestModule(modules); - addDesignerComponentsModule(modules); - - var modulesThatCanBeDisabled = [ - "xmlpatterns", "multimedia", "phonon", "svg", "webkit", "script", "scripttools", - "declarative", "gui", "dbus", "opengl", "openvg"]; - var nonExistingPrlFiles = []; - for (i = 0; i < modules.length; ++i) { - module = modules[i]; - var name = module.qbsName; - var privateIndex = name.indexOf("-private"); - if (privateIndex !== -1) - name = name.slice(0, privateIndex); - if (modulesThatCanBeDisabled.contains(name)) - module.mustExist = false; - if (qtProps.staticBuild) - module.isStaticLibrary = true; - setupLibraries(module, qtProps, nonExistingPrlFiles, ""); - } - replaceQtLibNamesWithFilePath(modules, qtProps); - - return modules; -} - -function getFileContentsRecursively(filePath) { - var file = new TextFile(filePath, TextFile.ReadOnly); - var lines = splitNonEmpty(file.readAll(), '\n'); - for (var i = 0; i < lines.length; ++i) { - var includeString = "include("; - var line = lines[i].trim(); - if (!line.startsWith(includeString)) - continue; - var offset = includeString.length; - var closingParenPos = line.indexOf(')', offset); - if (closingParenPos === -1) { - console.warn("Invalid include statement in '" + toNative(filePath) + "'"); - continue; - } - var includedFilePath = line.slice(offset, closingParenPos); - if (!FileInfo.isAbsolutePath(includedFilePath)) - includedFilePath = FileInfo.joinPaths(FileInfo.path(filePath), includedFilePath); - var includedContents = getFileContentsRecursively(includedFilePath); - var j = i; - for (var k = 0; k < includedContents.length; ++k) - lines.splice(++j, 0, includedContents[k]); - lines.splice(i--, 1); - } - file.close(); - return lines; -} - -function extractPaths(rhs, filePath) { - var paths = []; - var startIndex = 0; - for (;;) { - while (startIndex < rhs.length && rhs.charAt(startIndex) === ' ') - ++startIndex; - if (startIndex >= rhs.length) - break; - var endIndex; - if (rhs.charAt(startIndex) === '"') { - ++startIndex; - endIndex = rhs.indexOf('"', startIndex); - if (endIndex === -1) { - console.warn("Unmatched quote in file '" + toNative(filePath) + "'"); - break; - } - } else { - endIndex = rhs.indexOf(' ', startIndex + 1); - if (endIndex === -1) - endIndex = rhs.length; - } - paths.push(FileInfo.cleanPath(rhs.slice(startIndex, endIndex) - .replace("$$PWD", FileInfo.path(filePath)))); - startIndex = endIndex + 1; - } - return paths; -} - -function removeDuplicatedDependencyLibs(modules) { - var revDeps = {}; - var currentPath = []; - var getLibraries; - var getLibFilePath; - - function setupReverseDependencies(modules) { - var moduleByName = {}; - for (var i = 0; i < modules.length; ++i) - moduleByName[modules[i].qbsName] = modules[i]; - for (i = 0; i < modules.length; ++i) { - var module = modules[i]; - for (var j = 0; j < module.dependencies.length; ++j) { - var depmod = moduleByName[module.dependencies[j]]; - if (!depmod) - continue; - if (!revDeps[depmod.qbsName]) - revDeps[depmod.qbsName] = []; - revDeps[depmod.qbsName].push(module); - } - } - } - - function roots(modules) { - var result = []; - for (i = 0; i < modules.length; ++i) { - var module = modules[i] - if (module.dependencies.length === 0) - result.push(module); - } - return result; - } - - function traverse(module, libs) { - if (currentPath.contains(module)) - return; - currentPath.push(module); - var moduleLibraryLists = getLibraries(module); - for (var i = 0; i < moduleLibraryLists.length; ++i) { - var modLibList = moduleLibraryLists[i]; - for (j = modLibList.length - 1; j >= 0; --j) { - if (libs.contains(modLibList[j])) - modLibList.splice(j, 1); - } - } - - var libFilePath = getLibFilePath(module); - if (libFilePath) - libs.push(libFilePath); - for (i = 0; i < moduleLibraryLists.length; ++i) - libs = libs.concat(moduleLibraryLists[i]); - libs.sort(); - - var deps = revDeps[module.qbsName]; - for (i = 0; i < (deps || []).length; ++i) - traverse(deps[i], libs); - - currentPath.pop(); - } - - setupReverseDependencies(modules); - - // Traverse the debug variants of modules. - getLibraries = function(module) { - return [module.dynamicLibrariesDebug, module.staticLibrariesDebug]; - }; - getLibFilePath = function(module) { return module.libFilePathDebug; }; - var rootModules = roots(modules); - for (var i = 0; i < rootModules.length; ++i) - traverse(rootModules[i], []); - - // Traverse the release variants of modules. - getLibraries = function(module) { - return [module.dynamicLibrariesRelease, module.staticLibrariesRelease]; - }; - getLibFilePath = function(module) { return module.libFilePathRelease; }; - for (i = 0; i < rootModules.length; ++i) - traverse(rootModules[i], []); -} - -function allQt5Modules(qtProps, androidAbi) { - var nonExistingPrlFiles = []; - var modules = []; - var modulesDir = FileInfo.joinPaths(qtProps.mkspecBasePath, "modules"); - var modulePriFiles = File.directoryEntries(modulesDir, File.Files); - for (var i = 0; i < modulePriFiles.length; ++i) { - var priFileName = modulePriFiles[i]; - var priFilePath = FileInfo.joinPaths(modulesDir, priFileName); - var externalFileNamePrefix = "qt_ext_"; - var moduleFileNamePrefix = "qt_lib_"; - var pluginFileNamePrefix = "qt_plugin_"; - var moduleFileNameSuffix = ".pri"; - var fileHasExternalPrefix = priFileName.startsWith(externalFileNamePrefix); - var fileHasModulePrefix = priFileName.startsWith(moduleFileNamePrefix); - var fileHasPluginPrefix = priFileName.startsWith(pluginFileNamePrefix); - if (!fileHasPluginPrefix && !fileHasModulePrefix && !fileHasExternalPrefix - || !priFileName.endsWith(moduleFileNameSuffix)) { - continue; - } - var moduleInfo = makeQtModuleInfo(); - moduleInfo.isPlugin = fileHasPluginPrefix; - moduleInfo.isExternal = !moduleInfo.isPlugin && !fileHasModulePrefix; - var fileNamePrefix = moduleInfo.isPlugin ? pluginFileNamePrefix : moduleInfo.isExternal - ? externalFileNamePrefix : moduleFileNamePrefix; - moduleInfo.qbsName = priFileName.slice(fileNamePrefix.length, -moduleFileNameSuffix.length); - if (moduleInfo.isPlugin) { - moduleInfo.name = moduleInfo.qbsName; - moduleInfo.isStaticLibrary = true; - } - var moduleKeyPrefix = (moduleInfo.isPlugin ? "QT_PLUGIN" : "QT") - + '.' + moduleInfo.qbsName + '.'; - moduleInfo.qbsName = moduleInfo.qbsName.replace("_private", "-private"); - var hasV2 = false; - var hasModuleEntry = false; - var lines = getFileContentsRecursively(priFilePath); - if (moduleInfo.isExternal) { - moduleInfo.name = "qt" + moduleInfo.qbsName; - moduleInfo.isStaticLibrary = true; - for (var k = 0; k < lines.length; ++k) { - var extLine = lines[k].trim(); - var extFirstEqualsOffset = extLine.indexOf('='); - if (extFirstEqualsOffset === -1) - continue; - var extKey = extLine.slice(0, extFirstEqualsOffset).trim(); - var extValue = extLine.slice(extFirstEqualsOffset + 1).trim(); - if (!extKey.startsWith("QMAKE_") || !extValue) - continue; - - var elements = extKey.split('_'); - if (elements.length >= 3) { - if (elements[1] === "LIBS") { - extValue = extValue.replace("/home/qt/work/qt/qtbase/lib", - qtProps.libraryPath); - extValue = extValue.replace("$$[QT_INSTALL_LIBS]", qtProps.libraryPath); - extValue = extValue.replace("$$[QT_INSTALL_LIBS/get]", qtProps.libraryPath); - if (elements.length === 4 ) { - if (elements[3] === androidAbi) { - moduleInfo.staticLibrariesRelease.push(extValue); - moduleInfo.staticLibrariesDebug.push(extValue); - } - } else if (elements.length === 5 ) { - // That's for "x86_64" - var abi = elements[3] + '_' + elements[4]; - if (abi === androidAbi) { - moduleInfo.staticLibrariesRelease.push(extValue); - moduleInfo.staticLibrariesDebug.push(extValue); - } - } else { - moduleInfo.staticLibrariesRelease.push(extValue); - moduleInfo.staticLibrariesDebug.push(extValue); - } - } else if (elements[1] === "INCDIR") { - moduleInfo.includePaths.push(extValue.replace("$$[QT_INSTALL_HEADERS]", - qtProps.includePath)); - } - } - } - moduleInfo.compilerDefines.push("QT_" + moduleInfo.qbsName.toUpperCase() + "_LIB"); - moduleInfo.mustExist = false; - } else { - for (var j = 0; j < lines.length; ++j) { - var line = lines[j].trim(); - var firstEqualsOffset = line.indexOf('='); - if (firstEqualsOffset === -1) - continue; - var key = line.slice(0, firstEqualsOffset).trim(); - var value = line.slice(firstEqualsOffset + 1).trim(); - if (!key.startsWith(moduleKeyPrefix) || !value) - continue; - if (key.endsWith(".name")) { - moduleInfo.name = value; - } else if (key.endsWith(".module")) { - hasModuleEntry = true; - } else if (key.endsWith(".depends")) { - moduleInfo.dependencies = splitNonEmpty(value, ' '); - for (var k = 0; k < moduleInfo.dependencies.length; ++k) { - moduleInfo.dependencies[k] - = moduleInfo.dependencies[k].replace("_private", "-private"); - } - } else if (key.endsWith(".module_config")) { - var elems = splitNonEmpty(value, ' '); - for (k = 0; k < elems.length; ++k) { - var elem = elems[k]; - if (elem === "no_link") - moduleInfo.hasLibrary = false; - else if (elem === "staticlib") - moduleInfo.isStaticLibrary = true; - else if (elem === "internal_module") - moduleInfo.isPrivate = true; - else if (elem === "v2") - hasV2 = true; - } - } else if (key.endsWith(".includes")) { - moduleInfo.includePaths = extractPaths(value, priFilePath); - for (k = 0; k < moduleInfo.includePaths.length; ++k) { - moduleInfo.includePaths[k] = moduleInfo.includePaths[k] - .replace("$$QT_MODULE_INCLUDE_BASE", qtProps.includePath) - .replace("$$QT_MODULE_HOST_LIB_BASE", qtProps.hostLibraryPath) - .replace("$$QT_MODULE_LIB_BASE", qtProps.libraryPath); - } - } else if (key.endsWith(".libs")) { - var libDirs = extractPaths(value, priFilePath); - if (libDirs.length === 1) { - moduleInfo.libDir = libDirs[0] - .replace("$$QT_MODULE_HOST_LIB_BASE", qtProps.hostLibraryPath) - .replace("$$QT_MODULE_LIB_BASE", qtProps.libraryPath); - } else { - moduleInfo.libDir = qtProps.libraryPath; - } - } else if (key.endsWith(".DEFINES")) { - moduleInfo.compilerDefines = splitNonEmpty(value, ' '); - } else if (key.endsWith(".VERSION")) { - moduleInfo.version = value; - } else if (key.endsWith(".plugin_types")) { - moduleInfo.supportedPluginTypes = splitNonEmpty(value, ' '); - } else if (key.endsWith(".TYPE")) { - moduleInfo.pluginData.type = value; - } else if (key.endsWith(".EXTENDS")) { - moduleInfo.pluginData["extends"] = splitNonEmpty(value, ' '); - for (k = 0; k < moduleInfo.pluginData["extends"].length; ++k) { - if (moduleInfo.pluginData["extends"][k] === "-") { - moduleInfo.pluginData["extends"].splice(k, 1); - moduleInfo.pluginData.autoLoad = false; - break; - } - } - } else if (key.endsWith(".CLASS_NAME")) { - moduleInfo.pluginData.className = value; - } - } - } - if (hasV2 && !hasModuleEntry) - moduleInfo.hasLibrary = false; - - // Fix include paths for Apple frameworks. - // The qt_lib_XXX.pri files contain wrong values for versions < 5.6. - if (!hasV2 && isFramework(moduleInfo, qtProps)) { - moduleInfo.includePaths = []; - var baseIncDir = frameworkHeadersPath(moduleInfo, qtProps); - if (moduleInfo.isPrivate) { - baseIncDir = FileInfo.joinPaths(baseIncDir, moduleInfo.version); - moduleInfo.includePaths.push(baseIncDir, - FileInfo.joinPaths(baseIncDir, moduleInfo.name)); - } else { - moduleInfo.includePaths.push(baseIncDir); - } - } - - setupLibraries(moduleInfo, qtProps, nonExistingPrlFiles, androidAbi); - - modules.push(moduleInfo); - if (moduleInfo.qbsName === "testlib") - addTestModule(modules); - if (moduleInfo.qbsName === "designercomponents-private") - addDesignerComponentsModule(modules); - } - - replaceQtLibNamesWithFilePath(modules, qtProps); - removeDuplicatedDependencyLibs(modules); - return modules; -} - function extractQbsArchs(module, qtProps) { if (qtProps.mkspecName.startsWith("macx-")) { var archs = []; @@ -1335,7 +105,7 @@ function qbsTargetPlatformFromQtMkspec(qtProps) { return "solaris"; if (mkspec.startsWith("vxworks-")) return "vxworks"; - if (targetsDesktopWindows(qtProps) || mkspec.startsWith("winrt-")) + if (ProviderUtils.isDesktopWindowsQt(qtProps) || mkspec.startsWith("winrt-")) return "windows"; } @@ -1391,7 +161,7 @@ function defaultQpaPlugin(module, qtProps) { function libraryFileTag(module, qtProps) { if (module.isStaticLibrary) return "staticlibrary"; - return isMsvcQt(qtProps) || qtProps.mkspecName.startsWith("win32-g++") + return ProviderUtils.isMsvcQt(qtProps) || qtProps.mkspecName.startsWith("win32-g++") ? "dynamiclibrary_import" : "dynamiclibrary"; } @@ -1416,7 +186,20 @@ function findVariable(content, start) { } function minVersionJsString(minVersion) { - return !minVersion ? "original" : ModUtils.toJSLiteral(minVersion); + return !minVersion ? "" : ModUtils.toJSLiteral(minVersion); +} + +function abiToArchitecture(abi) { + switch (abi) { + case "armeabi-v7a": + return "armv7a"; + case "arm64-v8a": + return "arm64"; + case "x86": + case "x86_64": + default: + return abi; + } } function replaceSpecialValues(content, module, qtProps, abi) { @@ -1447,7 +230,7 @@ function replaceSpecialValues(content, module, qtProps, abi) { availableBuildVariants: ModUtils.toJSLiteral(qtProps.buildVariant), staticBuild: ModUtils.toJSLiteral(qtProps.staticBuild), frameworkBuild: ModUtils.toJSLiteral(qtProps.frameworkBuild), - name: ModUtils.toJSLiteral(moduleNameWithoutPrefix(module)), + name: ModUtils.toJSLiteral(ProviderUtils.qtModuleNameWithoutPrefix(module)), has_library: ModUtils.toJSLiteral(module.hasLibrary), dependencies: ModUtils.toJSLiteral(module.dependencies), includes: ModUtils.toJSLiteral(module.includePaths), @@ -1464,18 +247,20 @@ function replaceSpecialValues(content, module, qtProps, abi) { frameworksRelease: ModUtils.toJSLiteral(module.frameworksRelease), libFilePathDebug: ModUtils.toJSLiteral(module.libFilePathDebug), libFilePathRelease: ModUtils.toJSLiteral(module.libFilePathRelease), - libNameForLinkerDebug: ModUtils.toJSLiteral(libNameForLinker(module, qtProps, true)), + libNameForLinkerDebug: + ModUtils.toJSLiteral(ProviderUtils.qtLibNameForLinker(module, qtProps, true)), pluginTypes: ModUtils.toJSLiteral(module.supportedPluginTypes), moduleConfig: ModUtils.toJSLiteral(module.config), - libNameForLinkerRelease: ModUtils.toJSLiteral(libNameForLinker(module, qtProps, false)), + libNameForLinkerRelease: + ModUtils.toJSLiteral(ProviderUtils.qtLibNameForLinker(module, qtProps, false)), entryPointLibsDebug: ModUtils.toJSLiteral(qtProps.entryPointLibsDebug), entryPointLibsRelease: ModUtils.toJSLiteral(qtProps.entryPointLibsRelease), - minWinVersion: minVersionJsString(qtProps.windowsVersion), - minMacVersion: minVersionJsString(qtProps.macosVersion), - minIosVersion: minVersionJsString(qtProps.iosVersion), - minTvosVersion: minVersionJsString(qtProps.tvosVersion), - minWatchosVersion: minVersionJsString(qtProps.watchosVersion), - minAndroidVersion: minVersionJsString(qtProps.androidVersion), + minWinVersion_optional: minVersionJsString(qtProps.windowsVersion), + minMacVersion_optional: minVersionJsString(qtProps.macosVersion), + minIosVersion_optional: minVersionJsString(qtProps.iosVersion), + minTvosVersion_optional: minVersionJsString(qtProps.tvosVersion), + minWatchosVersion_optional: minVersionJsString(qtProps.watchosVersion), + minAndroidVersion_optional: minVersionJsString(qtProps.androidVersion), }; var additionalContent = ""; @@ -1527,16 +312,15 @@ function replaceSpecialValues(content, module, qtProps, abi) { + indent + indent + "fileTags: [\"qt.core.metatypes\"]\n" + indent + "}"; } - if (module.hasLibrary && !isFramework(module, qtProps)) { + if (module.hasLibrary && !ProviderUtils.qtIsFramework(module, qtProps)) { if (additionalContent) additionalContent += "\n" + indent; additionalContent += "Group {\n"; if (module.isPlugin) { additionalContent += indent + indent - + "condition: Qt[\"" + module.qbsName + "\"].enableLinking\n"; + + "condition: enableLinking\n"; } - additionalContent += indent + indent + "files: [Qt[\"" + module.qbsName + "\"]" - + ".libFilePath]\n" + additionalContent += indent + indent + "files: libFilePath\n" + indent + indent + "filesAreTargets: true\n" + indent + indent + "fileTags: [\"" + libraryFileTag(module, qtProps) + "\"]\n" @@ -1546,9 +330,21 @@ function replaceSpecialValues(content, module, qtProps, abi) { for (var pos = findVariable(content, 0); pos[0] !== -1; pos = findVariable(content, pos[0])) { - var replacement = dict[content.slice(pos[0] + 1, pos[1])] || ""; - content = content.slice(0, pos[0]) + replacement + content.slice(pos[1] + 1); - pos[0] += replacement.length; + var varName = content.slice(pos[0] + 1, pos[1]); + var replacement = dict[varName] || ""; + if (!replacement && varName.endsWith("_optional")) { + var prevNewline = content.lastIndexOf('\n', pos[0]); + if (prevNewline === -1) + prevNewline = 0; + var nextNewline = content.indexOf('\n', pos[0]); + if (nextNewline === -1) + prevNewline = content.length; + content = content.slice(0, prevNewline) + content.slice(nextNewline); + pos[0] = prevNewline; + } else { + content = content.slice(0, pos[0]) + replacement + content.slice(pos[1] + 1); + pos[0] += replacement.length; + } } return content; } @@ -1557,7 +353,7 @@ function copyTemplateFile(fileName, targetDirectory, qtProps, abi, location, all pluginMap, nonEssentialPlugins) { if (!File.makePath(targetDirectory)) { - throw "Cannot create directory '" + toNative(targetDirectory) + "'."; + throw "Cannot create directory '" + FileInfo.toNativeSeparators(targetDirectory) + "'."; } var sourceFile = new TextFile(FileInfo.joinPaths(location, "templates", fileName), TextFile.ReadOnly); @@ -1579,67 +375,64 @@ function copyTemplateFile(fileName, targetDirectory, qtProps, abi, location, all targetFile.close(); } -function setupOneQt(qmakeFilePath, outputBaseDir, uniquify, location, qbs) { - if (!File.exists(qmakeFilePath)) - throw "The specified qmake file path '" + toNative(qmakeFilePath) + "' does not exist."; - var qtProps = getQtProperties(qmakeFilePath, qbs); - var androidAbis = []; - if (qtProps.androidAbis !== undefined) - // Multiple androidAbis detected: Qt >= 5.14 - androidAbis = qtProps.androidAbis; - else - // Single abi detected: Qt < 5.14 - androidAbis.push(''); - if (androidAbis.length > 1) - console.info("Qt with multiple abi detected: '" + androidAbis + "'"); +function setupOneQt(moduleName, qtInfo, outputBaseDir, uniquify, location) { + var qtProps = qtInfo.qtProps; var relativeSearchPaths = []; - for (a = 0; a < androidAbis.length; ++a) { - if (androidAbis.length > 1) - console.info("Configuring abi '" + androidAbis[a] + "'..."); - var modules = qtProps.qtMajorVersion < 5 ? allQt4Modules(qtProps) : - allQt5Modules(qtProps,androidAbis[a]); - var pluginsByType = {}; - var nonEssentialPlugins = []; - for (var i = 0; i < modules.length; ++i) { - var m = modules[i]; - if (m.isPlugin) { - if (!pluginsByType[m.pluginData.type]) - pluginsByType[m.pluginData.type] = []; - pluginsByType[m.pluginData.type].push(m.name); - if (!m.pluginData.autoLoad) - nonEssentialPlugins.push(m.name); - } - } - - var relativeSearchPath = uniquify ? Utilities.getHash(qmakeFilePath) : ""; - relativeSearchPath = FileInfo.joinPaths(relativeSearchPath, androidAbis[a]); + for (a = 0; a < qtInfo.abiInfos.length; ++a) { + var abiInfo = qtInfo.abiInfos[a]; + var androidAbi = abiInfo.androidAbi; + if (qtInfo.abiInfos.length > 1) + console.info("Configuring abi '" + androidAbi + "'..."); + + var relativeSearchPath = uniquify ? Utilities.getHash(qtInfo.qmakeFilePath) : ""; + relativeSearchPath = FileInfo.joinPaths(relativeSearchPath, androidAbi); var qbsQtModuleBaseDir = FileInfo.joinPaths(outputBaseDir, relativeSearchPath, "modules", "Qt"); - if (File.exists(qbsQtModuleBaseDir)) - File.remove(qbsQtModuleBaseDir); + // TODO: + // if (File.exists(qbsQtModuleBaseDir)) + // File.remove(qbsQtModuleBaseDir); var allFiles = []; - copyTemplateFile("QtModule.qbs", qbsQtModuleBaseDir, qtProps, androidAbis[a], location, - allFiles); - copyTemplateFile("QtPlugin.qbs", qbsQtModuleBaseDir, qtProps, androidAbis[a], location, - allFiles); - copyTemplateFile("plugin_support.qbs", - FileInfo.joinPaths(qbsQtModuleBaseDir, "plugin_support"), qtProps, - androidAbis[a], location, allFiles, undefined, pluginsByType, - nonEssentialPlugins); + if (moduleName === "plugin_support") { + copyTemplateFile("plugin_support.qbs", + FileInfo.joinPaths(qbsQtModuleBaseDir, "plugin_support"), qtProps, + androidAbi, location, allFiles, undefined, abiInfo.pluginsByType, + abiInfo.nonEssentialPlugins); + relativeSearchPaths.push(relativeSearchPath); + return relativeSearchPaths; + } else if (moduleName === "android_support") { + // Note that it's not strictly necessary to copy this one, as it has no variable content. + // But we do it anyway for consistency. + copyTemplateFile("android_support.qbs", + FileInfo.joinPaths(qbsQtModuleBaseDir, "android_support"), + qtProps, androidAbi, location, allFiles); + relativeSearchPaths.push(relativeSearchPath); + return relativeSearchPaths; + } else if (moduleName === "qmlcache") { + var qmlcacheStr = "qmlcache"; + if (File.exists(FileInfo.joinPaths(qtProps.qmlLibExecPath, + "qmlcachegen" + FileInfo.executableSuffix()))) { + copyTemplateFile(qmlcacheStr + ".qbs", + FileInfo.joinPaths(qbsQtModuleBaseDir, qmlcacheStr), qtProps, + androidAbi, location, allFiles); + } + relativeSearchPaths.push(relativeSearchPath); + return relativeSearchPaths; + } - for (i = 0; i < modules.length; ++i) { - var module = modules[i]; + if (abiInfo.modules[moduleName] !== undefined) { + var module = abiInfo.modules[moduleName]; var qbsQtModuleDir = FileInfo.joinPaths(qbsQtModuleBaseDir, module.qbsName); var moduleTemplateFileName; + if (module.qbsName === "core") { moduleTemplateFileName = "core.qbs"; - copyTemplateFile("moc.js", qbsQtModuleDir, qtProps, androidAbis[a], location, + copyTemplateFile("moc.js", qbsQtModuleDir, qtProps, androidAbi, location, allFiles); - copyTemplateFile("qdoc.js", qbsQtModuleDir, qtProps, androidAbis[a], location, + copyTemplateFile("qdoc.js", qbsQtModuleDir, qtProps, androidAbi, location, allFiles); - copyTemplateFile("rcc.js", qbsQtModuleDir, qtProps, androidAbis[a], location, + copyTemplateFile("rcc.js", qbsQtModuleDir, qtProps, androidAbi, location, allFiles); } else if (module.qbsName === "gui") { moduleTemplateFileName = "gui.qbs"; @@ -1647,62 +440,51 @@ function setupOneQt(qmakeFilePath, outputBaseDir, uniquify, location, qbs) { moduleTemplateFileName = "scxml.qbs"; } else if (module.qbsName === "dbus") { moduleTemplateFileName = "dbus.qbs"; - copyTemplateFile("dbus.js", qbsQtModuleDir, qtProps, androidAbis[a], location, + copyTemplateFile("dbus.js", qbsQtModuleDir, qtProps, androidAbi, location, allFiles); } else if (module.qbsName === "qml") { moduleTemplateFileName = "qml.qbs"; - copyTemplateFile("qml.js", qbsQtModuleDir, qtProps, androidAbis[a], location, + copyTemplateFile("qml.js", qbsQtModuleDir, qtProps, androidAbi, location, allFiles); - var qmlcacheStr = "qmlcache"; - if (File.exists(FileInfo.joinPaths(qtProps.qmlLibExecPath, - "qmlcachegen" + exeSuffix(qbs)))) { - copyTemplateFile(qmlcacheStr + ".qbs", - FileInfo.joinPaths(qbsQtModuleBaseDir, qmlcacheStr), qtProps, - androidAbis[a], location, allFiles); - } } else if (module.qbsName === "quick") { moduleTemplateFileName = "quick.qbs"; - copyTemplateFile("quick.js", qbsQtModuleDir, qtProps, androidAbis[a], location, + copyTemplateFile("quick.js", qbsQtModuleDir, qtProps, androidAbi, location, allFiles); - copyTemplateFile("rcc.js", qbsQtModuleDir, qtProps, androidAbis[a], location, + copyTemplateFile("rcc.js", qbsQtModuleDir, qtProps, androidAbi, location, allFiles); } else if (module.isPlugin) { moduleTemplateFileName = "plugin.qbs"; } else { moduleTemplateFileName = "module.qbs"; } - copyTemplateFile(moduleTemplateFileName, qbsQtModuleDir, qtProps, androidAbis[a], + copyTemplateFile(moduleTemplateFileName, qbsQtModuleDir, qtProps, androidAbi, location, allFiles, module); + relativeSearchPaths.push(relativeSearchPath); } - - // Note that it's not strictly necessary to copy this one, as it has no variable content. - // But we do it anyway for consistency. - copyTemplateFile("android_support.qbs", - FileInfo.joinPaths(qbsQtModuleBaseDir, "android_support"), - qtProps, androidAbis[a], location, allFiles); - relativeSearchPaths.push(relativeSearchPath) } return relativeSearchPaths; } -function doSetup(qmakeFilePaths, outputBaseDir, location, qbs) { - qmakeFilePaths = getQmakeFilePaths(qmakeFilePaths, qbs); - if (!qmakeFilePaths || qmakeFilePaths.length === 0) +function doSetup(moduleName, qtInfos, outputBaseDir, location) { + if (!qtInfos || qtInfos.length === 0) return []; - var uniquifySearchPath = qmakeFilePaths.length > 1; + var uniquifySearchPath = qtInfos.length > 1; var allSearchPaths = []; - for (var i = 0; i < qmakeFilePaths.length; ++i) { + moduleName = moduleName.substring(3); + for (var i = 0; i < qtInfos.length; ++i) { try { - console.info("Setting up Qt at '" + toNative(qmakeFilePaths[i]) + "'..."); - var searchPaths = setupOneQt(qmakeFilePaths[i], outputBaseDir, uniquifySearchPath, - location, qbs); + console.info("Setting up Qt module '" + moduleName + "' for Qt located at '" + + FileInfo.toNativeSeparators(qtInfos[i].qmakeFilePath) + "'."); + var searchPaths = setupOneQt(moduleName, qtInfos[i], outputBaseDir, uniquifySearchPath, + location); if (searchPaths.length > 0) { for (var j = 0; j < searchPaths.length; ++j ) allSearchPaths.push(searchPaths[j]); - console.info("Qt was set up successfully."); } } catch (e) { - console.warn("Error setting up Qt for '" + toNative(qmakeFilePaths[i]) + "': " + e); + console.warn("Error setting up Qt module '" + moduleName + "' for '" + + FileInfo.toNativeSeparators(qtInfos[i].qmakeFilePath) + "': " + e); + throw e; } } return allSearchPaths; diff --git a/share/qbs/module-providers/Qt/templates/android_support.qbs b/share/qbs/module-providers/Qt/templates/android_support.qbs index 66914d11b..6d548f194 100644 --- a/share/qbs/module-providers/Qt/templates/android_support.qbs +++ b/share/qbs/module-providers/Qt/templates/android_support.qbs @@ -21,7 +21,7 @@ Module { property string _qtBinaryDir property string _qtInstallDir property bool _enableSdkSupport: product.type && product.type.contains("android.package") - && !consoleApplication + && !product.consoleApplication property bool _enableNdkSupport: !product.aggregate || product.multiplexConfigurationId property string _templatesBaseDir: FileInfo.joinPaths(_qtInstallDir, "src", "android") property string _deployQtOutDir: FileInfo.joinPaths(product.buildDirectory, "deployqt_out") diff --git a/share/qbs/module-providers/Qt/templates/core.qbs b/share/qbs/module-providers/Qt/templates/core.qbs index b980588ff..485402716 100644 --- a/share/qbs/module-providers/Qt/templates/core.qbs +++ b/share/qbs/module-providers/Qt/templates/core.qbs @@ -76,6 +76,8 @@ Module { property string qtBuildVariant: { if (availableBuildVariants.contains(qbs.buildVariant)) return qbs.buildVariant; + if (qbs.buildVariant === "profiling" && availableBuildVariants.contains("release")) + return "release"; return availableBuildVariants.length > 0 ? availableBuildVariants[0] : ""; } @@ -107,6 +109,7 @@ Module { property string libFilePathRelease: @libFilePathRelease@ property string libFilePath: qtBuildVariant === "debug" ? libFilePathDebug : libFilePathRelease + property bool useRPaths: qbs.targetOS.contains("linux") && !qbs.targetOS.contains("android") property stringList coreLibPaths: @libraryPaths@ property bool hasLibrary: true @@ -196,8 +199,7 @@ Module { return undefined; return frameworks; } - cpp.rpaths: qbs.targetOS.contains('linux') && !qbs.targetOS.contains("android") ? [libPath] : - undefined + cpp.rpaths: useRPaths ? libPath : undefined cpp.runtimeLibrary: qbs.toolchain.contains("msvc") ? config.contains("static_runtime") ? "static" : "dynamic" : original @@ -220,12 +222,12 @@ Module { return "libc++"; return original; } - cpp.minimumWindowsVersion: @minWinVersion@ - cpp.minimumMacosVersion: @minMacVersion@ - cpp.minimumIosVersion: @minIosVersion@ - cpp.minimumTvosVersion: @minTvosVersion@ - cpp.minimumWatchosVersion: @minWatchosVersion@ - cpp.minimumAndroidVersion: @minAndroidVersion@ + cpp.minimumWindowsVersion: @minWinVersion_optional@ + cpp.minimumMacosVersion: @minMacVersion_optional@ + cpp.minimumIosVersion: @minIosVersion_optional@ + cpp.minimumTvosVersion: @minTvosVersion_optional@ + cpp.minimumWatchosVersion: @minWatchosVersion_optional@ + cpp.minimumAndroidVersion: @minAndroidVersion_optional@ // Universal Windows Platform support cpp.windowsApiFamily: mkspecName.startsWith("winrt-") ? "pc" : undefined diff --git a/share/qbs/module-providers/Qt/templates/dbus.qbs b/share/qbs/module-providers/Qt/templates/dbus.qbs index 08e1e49e7..bbda5a4f2 100644 --- a/share/qbs/module-providers/Qt/templates/dbus.qbs +++ b/share/qbs/module-providers/Qt/templates/dbus.qbs @@ -1,6 +1,5 @@ import qbs.FileInfo import qbs.ModUtils -import "../QtModule.qbs" as QtModule import "dbus.js" as DBus QtModule { diff --git a/share/qbs/module-providers/Qt/templates/gui.qbs b/share/qbs/module-providers/Qt/templates/gui.qbs index 6ba5e48c4..db491eafe 100644 --- a/share/qbs/module-providers/Qt/templates/gui.qbs +++ b/share/qbs/module-providers/Qt/templates/gui.qbs @@ -1,7 +1,6 @@ import qbs.FileInfo import qbs.ModUtils import qbs.Utilities -import '../QtModule.qbs' as QtModule QtModule { qtModuleName: "Gui" diff --git a/share/qbs/module-providers/Qt/templates/module.qbs b/share/qbs/module-providers/Qt/templates/module.qbs index ccafe4122..9f0313ab5 100644 --- a/share/qbs/module-providers/Qt/templates/module.qbs +++ b/share/qbs/module-providers/Qt/templates/module.qbs @@ -1,5 +1,3 @@ -import '../QtModule.qbs' as QtModule - QtModule { qtModuleName: @name@ Depends { name: "Qt"; submodules: @dependencies@} diff --git a/share/qbs/module-providers/Qt/templates/plugin.qbs b/share/qbs/module-providers/Qt/templates/plugin.qbs index e73e2a4d9..34d4f4153 100644 --- a/share/qbs/module-providers/Qt/templates/plugin.qbs +++ b/share/qbs/module-providers/Qt/templates/plugin.qbs @@ -1,5 +1,3 @@ -import '../QtPlugin.qbs' as QtPlugin - QtPlugin { qtModuleName: @name@ Depends { name: "Qt"; submodules: @dependencies@} diff --git a/share/qbs/module-providers/Qt/templates/qml.js b/share/qbs/module-providers/Qt/templates/qml.js index 2a2ff85ab..38462dcf7 100644 --- a/share/qbs/module-providers/Qt/templates/qml.js +++ b/share/qbs/module-providers/Qt/templates/qml.js @@ -39,17 +39,32 @@ function getPrlRhs(line) return line.split('=')[1].trim(); } -function getLibsForPlugin(pluginData, buildVariant, targetOS, toolchain, qtLibDir, qtPluginDir, - qtDir) +function getLibsForPlugin(pluginData, product) { + var targetOS = product.qbs.targetOS; + var toolchain = product.qbs.toolchain; + var buildVariant = product.Qt.core.qtBuildVariant; + var qtLibDir = product.Qt.core.libPath; + var qtPluginDir = product.Qt.core.pluginPath; + var qtDir = product.Qt.core.installPrefixPath; + var qtQmlPath = product.Qt.qml.qmlPath; + if (!pluginData.path) return ""; var prlFileName = ""; if (!targetOS.contains("windows")) prlFileName += "lib"; prlFileName += pluginData.plugin; - if (buildVariant === "debug" && targetOS.contains("windows")) - prlFileName += "d"; + if (buildVariant === "debug") { + if (targetOS.contains("windows")) { + prlFileName += "d"; + } else if (product.Qt.core.versionMajor >= 6 && + (targetOS.contains("ios") + || targetOS.contains("tvos") + || targetOS.contains("watchos"))) { + prlFileName += "_debug"; + } + } prlFileName += ".prl"; var prlFilePath = FileInfo.joinPaths(pluginData.path, prlFileName); if (!File.exists(prlFilePath)) { @@ -77,7 +92,8 @@ function getLibsForPlugin(pluginData, buildVariant, targetOS, toolchain, qtLibDi otherLibsLine = otherLibsLine.replace(/\$\$\[QT_INSTALL_LIBS\]/g, qtLibDir); otherLibsLine = otherLibsLine.replace(/\$\$\[QT_INSTALL_PLUGINS\]/g, qtPluginDir); otherLibsLine = otherLibsLine.replace(/\$\$\[QT_INSTALL_PREFIX\]/g, qtDir); - otherLibs = otherLibs.concat(otherLibsLine.split(' ')); + otherLibsLine = otherLibsLine.replace(/\$\$\[QT_INSTALL_QML\]/g, qtQmlPath); + otherLibs = otherLibs.concat(otherLibsLine.split(' ').map(FileInfo.cleanPath)); } } if (!pluginLib) diff --git a/share/qbs/module-providers/Qt/templates/qml.qbs b/share/qbs/module-providers/Qt/templates/qml.qbs index f15705cc5..0a938e58d 100644 --- a/share/qbs/module-providers/Qt/templates/qml.qbs +++ b/share/qbs/module-providers/Qt/templates/qml.qbs @@ -1,7 +1,6 @@ import qbs.FileInfo import qbs.Host import qbs.TextFile -import '../QtModule.qbs' as QtModule import "qml.js" as Qml QtModule { @@ -170,13 +169,7 @@ QtModule { } 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, - product.Qt.core.pluginPath, - product.Qt.core.installPrefixPath); + var libs = Qml.getLibsForPlugin(scannerData[p], product); for (var i = 0; i < libs.length; ++i) { var lib = libs[i]; if (!lib.endsWith(product.cpp.objectSuffix) diff --git a/share/qbs/module-providers/Qt/templates/quick.qbs b/share/qbs/module-providers/Qt/templates/quick.qbs index 27f49cbd6..5fc4aa349 100644 --- a/share/qbs/module-providers/Qt/templates/quick.qbs +++ b/share/qbs/module-providers/Qt/templates/quick.qbs @@ -33,7 +33,6 @@ import qbs.FileInfo import qbs.Process import qbs.TextFile import qbs.Utilities -import '../QtModule.qbs' as QtModule import 'quick.js' as QC QtModule { diff --git a/share/qbs/module-providers/Qt/templates/scxml.qbs b/share/qbs/module-providers/Qt/templates/scxml.qbs index b800dfe70..757041b52 100644 --- a/share/qbs/module-providers/Qt/templates/scxml.qbs +++ b/share/qbs/module-providers/Qt/templates/scxml.qbs @@ -1,6 +1,5 @@ import qbs.FileInfo import qbs.Utilities -import "../QtModule.qbs" as QtModule QtModule { qtModuleName: "Scxml" diff --git a/share/qbs/module-providers/__fallback/fallback.qbs b/share/qbs/module-providers/__fallback/fallback.qbs index 52a3f080a..349af3a52 100644 --- a/share/qbs/module-providers/__fallback/fallback.qbs +++ b/share/qbs/module-providers/__fallback/fallback.qbs @@ -46,6 +46,8 @@ Module { property string theName: FileInfo.completeBaseName(filePath) + readonly property bool __fallback: true // Hack, please look away + Probes.PkgConfigProbe { id: pkgConfigProbe condition: pkgconfig.present diff --git a/share/qbs/module-providers/conan.js b/share/qbs/module-providers/conan.js new file mode 100644 index 000000000..a44af7eec --- /dev/null +++ b/share/qbs/module-providers/conan.js @@ -0,0 +1,239 @@ +/**************************************************************************** +** +** Copyright (C) 2024 Kai Dohmen +** Copyright (C) 2024 Ivan Komissarov (abbapoh@gmail.com). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qbs. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +var File = require("qbs.File"); +var FileInfo = require("qbs.FileInfo"); +var ModUtils = require("qbs.ModUtils"); +var PathProbe = require("../imports/qbs/Probes/path-probe.js") +var PathTools = require("qbs.PathTools"); +var TextFile = require("qbs.TextFile"); +var Utilities = require("qbs.Utilities"); + +const architectureMap = { + 'x86': 'x86', + 'x86_64': 'x86_64', + 'ppc32be': 'ppc', + 'ppc32': 'ppc', + 'ppc64le': 'ppc64', + 'ppc64': 'ppc64', + 'armv4': 'arm', + 'armv4i': 'arm', + 'armv5el': 'arm', + 'armv5hf': 'arm', + 'armv6': 'arm', + 'armv7': 'arm', + 'armv7hf': 'arm', + 'armv7s': 'arm', + 'armv7k': 'arm', + 'armv8': 'arm64', + 'armv8_32': 'arm64', + 'armv8.3': 'arm64', + 'sparc': 'sparc', + 'sparcv9': 'sparc64', + 'mips': 'mips', + 'mips64': 'mips64', + 'avr': 'avr', + 's390': 's390x', + 's390x': 's390x', + 'sh4le': 'sh' +} + +const platformMap = { + 'Windows': 'windows', + 'WindowsStore': 'windows', + 'WindowsCE': 'windows', + 'Linux': 'linux', + 'Macos': 'macos', + 'Android': 'android', + 'iOS': 'ios', + 'watchOS': 'watchos', + 'tvOS': 'tvos', + 'FreeBSD': 'freebsd', + 'SunOS': 'solaris', + 'AIX': 'aix', + 'Emscripten': undefined, + 'Arduino': 'none', + 'Neutrino': 'qnx', + 'baremetal': 'none', + 'VxWorks': 'vxworks', +} + +function findLibs(libnames, libdirs, libtypes, targetOS, forImport) { + var result = []; + if (libnames === null || libdirs === null) + return result; + libnames.forEach(function(libraryName) { + const suffixes = PathTools.librarySuffixes(targetOS, libtypes, forImport); + const lib = PathProbe.configure( + undefined, // selectors + [libraryName], + suffixes, + PathTools.libraryNameFilter(targetOS), + undefined, // candidateFilter + libdirs, // searchPaths + undefined, // pathSuffixes + [], // platformSearchPaths + undefined, // environmentPaths + undefined // platformEnvironmentPaths + ); + if (lib.found) + result.push(lib.files[0].filePath); + }); + return result; +} + +function getLibraryTypes(options) { + if (options !== undefined && options !== null) { + if (options.shared === undefined) + return ["shared", "static"]; + else if (options.shared === "True") + return ["shared"]; + else if (options.shared === "False") + return ["static"]; + } + return ["shared", "static"]; +} + +function configure(installDirectory, moduleName, outputBaseDir, jsonProbe) { + const moduleMapping = {"protobuflib": "protobuf"} + const realModuleName = moduleMapping[moduleName] || moduleName; + + const moduleFilePath = + FileInfo.joinPaths(installDirectory, "conan-qbs-deps", realModuleName + ".json") + if (!File.exists(moduleFilePath)) + return []; + + var reverseMapping = {} + for (var key in moduleMapping) + reverseMapping[moduleMapping[key]] = key + + console.info("Setting up Conan module '" + moduleName + "'"); + + var moduleFile = new TextFile(moduleFilePath, TextFile.ReadOnly); + const moduleInfo = JSON.parse(moduleFile.readAll()); + + const outputDir = FileInfo.joinPaths(outputBaseDir, "modules", moduleName.replace(".", "/")); + File.makePath(outputDir); + const outputFilePath = FileInfo.joinPaths(outputDir, "module.qbs"); + + const cppInfo = moduleInfo.cpp_info; + + var moduleContent = ""; + + // function write(data) { moduleContent = moduleContent + data } + function writeLine(data) { moduleContent = moduleContent + data + "\n"; } + + function writeProperty(propertyName, propertyValue) { + if (propertyValue === undefined || propertyValue === null) + propertyValue = []; + writeLine(" readonly property stringList " + propertyName + + ": " + ModUtils.toJSLiteral(propertyValue)); + } + function writeCppProperty(propertyName, propertyValue) { + writeProperty(propertyName, propertyValue); + // skip empty props for simplicity of the module file + if (propertyValue !== undefined && propertyValue != null && propertyValue.length !== 0) { + writeLine(" cpp." + propertyName + ": " + propertyName); + } + } + + writeLine("Module {"); + + writeLine(" version: " + ModUtils.toJSLiteral(moduleInfo.version)); + + const architecture = architectureMap[moduleInfo.settings.arch]; + const platform = platformMap[moduleInfo.settings.os]; + const targetOS = Utilities.canonicalPlatform(platform); + + writeLine(" readonly property string architecture: " + ModUtils.toJSLiteral(architecture)); + writeLine(" readonly property string platform: " + ModUtils.toJSLiteral(platform)); + writeLine(" condition: true"); + if (architecture !== undefined) { + writeLine(" && (!qbs.architecture || qbs.architecture === architecture)"); + } + if (platform !== undefined) { + if (["ios", "tvos", "watchos"].includes(platform)) { + writeLine(" && (qbs.targetPlatform === platform || qbs.targetPlatform === platform + \"-simulator\")"); + } else { + writeLine(" && qbs.targetPlatform === platform"); + } + } + + writeLine(" Depends { name: 'cpp' }"); + + moduleInfo.dependencies.forEach(function(dep) { + const realDepName = reverseMapping[dep.name] || dep.name; + writeLine(" Depends { name: " + ModUtils.toJSLiteral(realDepName) + + "; version: " + ModUtils.toJSLiteral(dep.version) + "}"); + }); + + writeLine(" readonly property stringList hostBinDirs: (" + ModUtils.toJSLiteral(moduleInfo.build_bindirs) + ")"); + // target bindirs + writeLine(" readonly property stringList binDirs: (" + ModUtils.toJSLiteral(cppInfo.bindirs) + ")"); + + // TODO: there's a weird issue with system include dirs with xcode-less clang - incorrect include order? + writeCppProperty("includePaths", cppInfo.includedirs); + writeCppProperty("frameworkPaths", cppInfo.frameworkdirs); + writeCppProperty("frameworks", cppInfo.frameworks); + writeCppProperty("defines", cppInfo.defines); + writeCppProperty("cFlags", cppInfo.cflags); + writeCppProperty("cxxFlags", cppInfo.cxxflags); + writeCppProperty("linkerFlags", (cppInfo.sharedlinkflags || []).concat(cppInfo.exelinkflags || [])); + + writeProperty("resources", cppInfo.resdirs); + + const isForImport = targetOS.includes("windows") + const libraryTypes = getLibraryTypes(moduleInfo.options); + libraryTypes.forEach(function(libraryType){ + const cppInfoLibs = cppInfo.libs === null ? [] : cppInfo.libs; + const libs = findLibs(cppInfoLibs, cppInfo.libdirs, libraryType, targetOS, isForImport) + .concat(cppInfo.system_libs === null ? [] : cppInfo.system_libs); + const property = libraryType === "shared" ? "dynamicLibraries" : "staticLibraries"; + writeCppProperty(property, libs); + }); + + writeLine("}"); + + var moduleFile = new TextFile(outputFilePath, TextFile.WriteOnly); + moduleFile.write(moduleContent); + moduleFile.close(); + + return ""; +} diff --git a/share/qbs/module-providers/conan.qbs b/share/qbs/module-providers/conan.qbs new file mode 100644 index 000000000..6391eeb65 --- /dev/null +++ b/share/qbs/module-providers/conan.qbs @@ -0,0 +1,12 @@ +import "conan.js" as ConanHelper + +ModuleProvider { + /* input */ + property path installDirectory + + isEager: false + + relativeSearchPaths: { + return ConanHelper.configure(installDirectory, moduleName, outputBaseDir); + } +} diff --git a/share/qbs/module-providers/qbspkgconfig.qbs b/share/qbs/module-providers/qbspkgconfig.qbs index ccd08febd..885a6da7a 100644 --- a/share/qbs/module-providers/qbspkgconfig.qbs +++ b/share/qbs/module-providers/qbspkgconfig.qbs @@ -40,45 +40,54 @@ import qbs.Environment import qbs.File import qbs.FileInfo +import qbs.Host import qbs.ModUtils import qbs.PkgConfig +import qbs.ProviderUtils +import qbs.Probes import qbs.Process import qbs.TextFile import "Qt/setup-qt.js" as SetupQt ModuleProvider { - property string executableFilePath + property stringList executableNames: ["pkgconf", "pkg-config"] + property string executableFilePath: pkgConfigProbe.filePath property stringList extraPaths property stringList libDirs property bool staticMode: false - property path sysroot: qbs.sysroot - property bool mergeDependencies: true + property bool definePrefix: Host.os().includes("windows") - relativeSearchPaths: { + // We take the sysroot default from qbs.sysroot, except for Xcode toolchains, where + // the sysroot points into the Xcode installation and does not contain .pc files. + property path sysroot: qbs.toolchain && qbs.toolchain.includes("xcode") + ? undefined : qbs.sysroot - function exeSuffix(qbs) { return FileInfo.executableSuffix(); } + Probes.BinaryProbe { + id: pkgConfigProbe + condition: !executableFilePath + names: executableNames + } - // we need Probes in Providers... - function getPkgConfigExecutable(qbs) { - function splitNonEmpty(s, c) { return s.split(c).filter(function(e) { return e; }) } + Probes.QbsPkgConfigProbe { + id: theProbe + _executableFilePath: executableFilePath + _extraPaths: extraPaths + _sysroot: sysroot + _libDirs: libDirs + _staticMode: staticMode + _definePrefix: definePrefix + } - var pathValue = Environment.getEnv("PATH"); - if (!pathValue) - return undefined; - var dirs = splitNonEmpty(pathValue, FileInfo.pathListSeparator()); - var suffix = exeSuffix(qbs); - var filePaths = []; - for (var i = 0; i < dirs.length; ++i) { - var candidate = FileInfo.joinPaths(dirs[i], "pkg-config" + suffix); - var canonicalCandidate = FileInfo.canonicalPath(candidate); - if (!canonicalCandidate || !File.exists(canonicalCandidate)) - continue; - return canonicalCandidate; - } - return undefined; - } + Probes.QmakeProbe { + id: qmakeProbe + condition: moduleName.startsWith("Qt") && theProbe.qmakePaths + qmakePaths: theProbe.qmakePaths + } + + isEager: false + relativeSearchPaths: { function getModuleInfo(pkg, staticMode) { var result = {}; @@ -120,14 +129,12 @@ ModuleProvider { return result; } - function getModuleName(packageName) { return packageName.replace(/\./g, '-'); } - function getModuleDependencies(pkg, staticMode) { var mapper = function(p) { var result = {}; for (var key in p) result[key] = p[key]; - result.name = getModuleName(result.name); + result.name = ProviderUtils.pkgConfigToModuleName(result.name); return result; } var result = pkg.requires.map(mapper); @@ -136,136 +143,83 @@ ModuleProvider { return result; } - console.debug("Running pkgconfig provider.") + console.debug("Running pkgconfig provider for " + moduleName + "."); var outputDir = FileInfo.joinPaths(outputBaseDir, "modules"); File.makePath(outputDir); - var options = {}; - options.libDirs = libDirs; - options.sysroot = sysroot; - if (options.sysroot) - options.allowSystemLibraryPaths = true; - options.staticMode = staticMode; - options.mergeDependencies = mergeDependencies; - options.extraPaths = extraPaths; - if (options.sysroot && !options.libDirs) { - options.libDirs = [ - sysroot + "/usr/lib/pkgconfig", - sysroot + "/usr/share/pkgconfig" - ]; - } - if (!options.libDirs) { - // if we have pkg-config installed, let's ask it for its search paths (since - // built-in search paths can differ between platforms) - var executable = executableFilePath ? executableFilePath : getPkgConfigExecutable(qbs); - if (executable) { - var p = new Process() - if (p.exec(executable, ['pkg-config', '--variable=pc_path']) === 0) { - var stdout = p.readStdOut().trim(); - // TODO: pathListSeparator? depends on what pkg-config prints on Windows - options.libDirs = stdout ? stdout.split(':'): []; - } - } + var moduleMapping = { + "protobuf": "protobuflib" } - - function setupQt(pkg) { - var packageName = pkg.baseFileName; - if (packageName === "QtCore" - || packageName === "Qt5Core" - || packageName === "Qt6Core") { - var binDir = pkg.variables["bindir"] || pkg.variables["host_bins"]; - if (!binDir) { - if (packageName === "QtCore") { // Qt4 does not have host_bins - var mocLocation = pkg.variables["moc_location"]; - if (!mocLocation) { - console.warn("No moc_location variable in " + packageName); - return; - } - binDir = FileInfo.path(mocLocation); - } else { - console.warn("No 'bindir' or 'host_bins' variable in " + packageName); - return; - } - } - var suffix = exeSuffix(qbs); - var qmakePaths = [FileInfo.joinPaths(binDir, "qmake" + suffix)]; + var reverseMapping = {} + for (var key in moduleMapping) + reverseMapping[moduleMapping[key]] = key + + if (moduleName.startsWith("Qt")) { + function setupQt(packageName, qtInfos) { + if (qtInfos === undefined || qtInfos.length === 0) + return []; var qtProviderDir = FileInfo.joinPaths(path, "Qt"); - SetupQt.doSetup(qmakePaths, outputBaseDir, qtProviderDir, qbs); + return SetupQt.doSetup(packageName, qtInfos, outputBaseDir, qtProviderDir); } - } - var moduleMapping = { - "protobuf": "protobuflib", - "grpc++": "grpcpp" + if (!sysroot) { + return setupQt(moduleName, qmakeProbe.qtInfos); + } + return []; } - var pkgConfig = new PkgConfig(options); - - var brokenPackages = []; - var packages = pkgConfig.packages(); - for (var packageName in packages) { - var pkg = packages[packageName]; - if (pkg.isBroken) { - brokenPackages.push(pkg); - continue; - } - if (packageName.startsWith("Qt")) { - setupQt(pkg); - continue; - } - var moduleName = getModuleName(moduleMapping[packageName] - ? moduleMapping[packageName] - : packageName); - var moduleInfo = getModuleInfo(pkg, staticMode); - var deps = getModuleDependencies(pkg, staticMode); + var pkg; + pkg = theProbe.packages[reverseMapping[moduleName]]; + if (pkg === undefined) + pkg = theProbe.packagesByModuleName[moduleName]; + if (pkg === undefined) + return []; - var moduleDir = FileInfo.joinPaths(outputDir, moduleName); - File.makePath(moduleDir); - var module = - new TextFile(FileInfo.joinPaths(moduleDir, "module.qbs"), TextFile.WriteOnly); - module.writeLine("Module {"); - module.writeLine(" version: " + ModUtils.toJSLiteral(moduleInfo.version)); - module.writeLine(" Depends { name: 'cpp' }"); - deps.forEach(function(dep) { - var depName = getModuleName( - moduleMapping[dep.name] ? moduleMapping[dep.name] : dep.name); - module.write(" Depends { name: '" + depName + "'"); - for (var k in dep) { - if (k === "name") - continue; - module.write("; " + k + ": " + ModUtils.toJSLiteral(dep[k])); - } - module.writeLine(" }"); - }) - function writeProperty(propertyName) { - var value = moduleInfo[propertyName]; - if (value.length !== 0) { // skip empty props for simplicity of the module file - module.writeLine( - " cpp." + propertyName + ":" + ModUtils.toJSLiteral(value)); - } - } - writeProperty("includePaths"); - writeProperty("systemIncludePaths"); - writeProperty("defines"); - writeProperty("commonCompilerFlags"); - writeProperty("dynamicLibraries"); - writeProperty("staticLibraries"); - writeProperty("libraryPaths"); - writeProperty("frameworks"); - writeProperty("frameworkPaths"); - writeProperty("driverLinkerFlags"); - module.writeLine("}"); - module.close(); + if (pkg.isBroken) { + console.warn("Failed to load " + moduleName + " as it's pkg-config package is broken"); + return []; } - - if (brokenPackages.length !== 0) { - console.warn("Failed to load some pkg-config packages:"); - for (var i = 0; i < brokenPackages.length; ++i) { - console.warn(" " + brokenPackages[i].filePath - + ": " + brokenPackages[i].errorText); + var moduleInfo = getModuleInfo(pkg, staticMode); + var deps = getModuleDependencies(pkg, staticMode); + + var moduleDir = FileInfo.joinPaths(outputDir, moduleName); + File.makePath(moduleDir); + var module = + new TextFile(FileInfo.joinPaths(moduleDir, "module.qbs"), TextFile.WriteOnly); + module.writeLine("Module {"); + module.writeLine(" version: " + ModUtils.toJSLiteral(moduleInfo.version)); + module.writeLine(" Depends { name: 'cpp' }"); + deps.forEach(function(dep) { + var depName = ProviderUtils.pkgConfigToModuleName( + moduleMapping[dep.name] ? moduleMapping[dep.name] : dep.name); + module.write(" Depends { name: '" + depName + "'"); + for (var k in dep) { + if (k === "name") + continue; + module.write("; " + k + ": " + ModUtils.toJSLiteral(dep[k])); + } + module.writeLine(" }"); + }) + function writeProperty(propertyName) { + var value = moduleInfo[propertyName]; + if (value.length !== 0) { // skip empty props for simplicity of the module file + module.writeLine( + " cpp." + propertyName + ":" + ModUtils.toJSLiteral(value)); } } + writeProperty("includePaths"); + writeProperty("systemIncludePaths"); + writeProperty("defines"); + writeProperty("commonCompilerFlags"); + writeProperty("dynamicLibraries"); + writeProperty("staticLibraries"); + writeProperty("libraryPaths"); + writeProperty("frameworks"); + writeProperty("frameworkPaths"); + writeProperty("driverLinkerFlags"); + module.writeLine("}"); + module.close(); return ""; } diff --git a/share/qbs/modules/Android/sdk/sdk.qbs b/share/qbs/modules/Android/sdk/sdk.qbs index d663a01e4..440448dcf 100644 --- a/share/qbs/modules/Android/sdk/sdk.qbs +++ b/share/qbs/modules/Android/sdk/sdk.qbs @@ -52,7 +52,7 @@ Module { Probes.PathProbe { id: bundletoolProbe - platformSearchPaths: [Android.sdk.sdkDir] + platformSearchPaths: [sdkDir] names: ["bundletool-all"] nameSuffixes: ["-0.11.0.jar", "-0.12.0.jar", "-0.13.0.jar", "-0.13.3.jar", "-0.13.4.jar", "-0.14.0.jar", "-0.15.0.jar", "-1.0.0.jar", "-1.1.0.jar", "-1.2.0.jar", "-1.3.0.jar", @@ -102,36 +102,36 @@ Module { Group { name: "java sources" - condition: Android.sdk.automaticSources - prefix: FileInfo.resolvePath(product.sourceDirectory, Android.sdk.sourcesDir + '/') + condition: product.Android.sdk.automaticSources + prefix: FileInfo.resolvePath(product.sourceDirectory, product.Android.sdk.sourcesDir + '/') files: "**/*.java" } Group { name: "android resources" - condition: Android.sdk.automaticSources + condition: product.Android.sdk.automaticSources fileTags: ["android.resources"] - prefix: FileInfo.resolvePath(product.sourceDirectory, Android.sdk.resourcesDir + '/') + prefix: FileInfo.resolvePath(product.sourceDirectory, product.Android.sdk.resourcesDir + '/') files: "**/*" } Group { name: "android assets" - condition: Android.sdk.automaticSources + condition: product.Android.sdk.automaticSources fileTags: ["android.assets"] - prefix: FileInfo.resolvePath(product.sourceDirectory, Android.sdk.assetsDir + '/') + prefix: FileInfo.resolvePath(product.sourceDirectory, product.Android.sdk.assetsDir + '/') files: "**/*" } Group { name: "manifest" - condition: Android.sdk.automaticSources + condition: product.Android.sdk.automaticSources fileTags: ["android.manifest"] - files: Android.sdk.manifestFile - && Android.sdk.manifestFile !== Android.sdk.defaultManifestFile - ? [Android.sdk.manifestFile] - : (File.exists(Android.sdk.defaultManifestFile) - ? [Android.sdk.defaultManifestFile] : []) + files: product.Android.sdk.manifestFile + && product.Android.sdk.manifestFile !== product.Android.sdk.defaultManifestFile + ? [product.Android.sdk.manifestFile] + : (File.exists(product.Android.sdk.defaultManifestFile) + ? [product.Android.sdk.defaultManifestFile] : []) } @@ -196,8 +196,8 @@ Module { java.languageVersion: platformJavaVersion java.runtimeVersion: platformJavaVersion java.bootClassPaths: androidJarFilePath - codesign.apksignerFilePath: Android.sdk.apksignerFilePath - codesign._packageName: Android.sdk.apkBaseName + (_generateAab ? ".aab" : ".apk") + codesign.apksignerFilePath: apksignerFilePath + codesign._packageName: apkBaseName + (_generateAab ? ".aab" : ".apk") codesign.useApksigner: !_generateAab } @@ -263,7 +263,7 @@ Module { property bool customManifestProcessing: false Group { - condition: !Android.sdk.customManifestProcessing + condition: !product.Android.sdk.customManifestProcessing fileTagsFilter: "android.manifest_processed" fileTags: "android.manifest_final" } diff --git a/share/qbs/modules/Exporter/cmake/cmakeexporter.js b/share/qbs/modules/Exporter/cmake/cmakeexporter.js new file mode 100644 index 000000000..093032f2e --- /dev/null +++ b/share/qbs/modules/Exporter/cmake/cmakeexporter.js @@ -0,0 +1,239 @@ +/**************************************************************************** +** +** Copyright (C) 2024 Raphaël Cotty <raphael.cotty@gmail.com> +** Copyright (C) 2024 Ivan Komissarov (abbapoh@gmail.com) +** Contact: http://www.qt.io/licensing +** +** This file is part of the Qbs. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +var FileInfo = require("qbs.FileInfo"); +var ModUtils = require("qbs.ModUtils"); +var ExporterHelpers = require("../exporter.js"); + +function tagListToString(tagList) +{ + return JSON.stringify(tagList); +} + +function collectAutodetectedData(project, topLevelProduct, outputs) +{ + var packageName = topLevelProduct.Exporter.cmake.packageName; + + var data = {}; + data.packageName = packageName; + data.installPrefixDir = "_" + packageName.toUpperCase() + "_INSTALL_PREFIX"; + data.packages = []; + + function quote(value) + { + return "\"" + value + "\""; + } + + function quoteAndPrefixify(propName) + { + function quoteAndPrefixifyHelper(value) { + var prefixToStrip = + ExporterHelpers.getPrefixToStrip(project, topLevelProduct, propName, value); + if (typeof value !== "string" + || !prefixToStrip + || (value.length > prefixToStrip.length + && value[prefixToStrip.length] !== '/')) { + return quote(value); + } + return quote("${" + data.installPrefixDir + "}" + value.slice(prefixToStrip.length)); + } + return quoteAndPrefixifyHelper; + } + + var installedOutputFilePath = ModUtils.artifactInstalledFilePath( + outputs["Exporter.cmake.configFile"][0]); + var installedOutputPathName = FileInfo.path(installedOutputFilePath); + + var installRootPath = FileInfo.joinPaths(topLevelProduct.qbs.installRoot, topLevelProduct.qbs.installPrefix); + data.installPrefix = FileInfo.relativePath(installedOutputPathName, installRootPath); + + var libArtifacts; + var libImportArtifacts; + var isProduct = !topLevelProduct.present; + var considerFramework = !isProduct || (topLevelProduct.type + && topLevelProduct.type.includes("bundle.content")) + && topLevelProduct.bundle + && topLevelProduct.bundle.isBundle + && topLevelProduct.qbs.targetOS.includes("darwin"); + var considerDynamicLibs = !isProduct || (topLevelProduct.type + && topLevelProduct.type.includes("dynamiclibrary")); + var considerStaticLibs = !isProduct || (topLevelProduct.type + && topLevelProduct.type.includes("staticlibrary")); + if (considerFramework) { + libArtifacts = topLevelProduct.artifacts["bundle.symlink.executable"]; + if (considerDynamicLibs) + data.type = "SHARED"; + else if (considerStaticLibs) + data.type = "STATIC"; + else + data.type = "INTERFACE"; + } else if (considerDynamicLibs) { + libArtifacts = topLevelProduct.artifacts.dynamiclibrary; + libImportArtifacts = topLevelProduct.artifacts.dynamiclibrary_import; + data.type = "SHARED"; + } else if (considerStaticLibs) { + libArtifacts = topLevelProduct.artifacts.staticlibrary; + data.type = "STATIC"; + } else { + data.type = "INTERFACE"; + } + + for (var i = 0; i < (libArtifacts || []).length; ++i) { + var libArtifact = libArtifacts[i]; + var libImportArtifact = (libImportArtifacts || [])[i]; + if (libArtifact.qbs.install) { + var installPath = ModUtils.artifactInstalledFilePath(libArtifact); + data.importedLocation = quoteAndPrefixify("installRoot")(installPath); + data.soName = topLevelProduct.targetName; + if (libImportArtifact && libImportArtifact.qbs.install) { + installPath = ModUtils.artifactInstalledFilePath(libImportArtifact); + data.importedImplibLocation = quoteAndPrefixify("installRoot")(installPath); + } + break; + } + } + var cpp = topLevelProduct.exports.cpp; + if (cpp) { + data.libraryPaths = (cpp.libraryPaths || []).map(quoteAndPrefixify("cpp.libraryPaths")); + + data.linkLibraries = []; + data.linkLibraries = data.linkLibraries.concat(cpp.dynamicLibraries || []); + data.linkLibraries = data.linkLibraries.concat(cpp.staticLibraries || []); + data.linkLibraries = data.linkLibraries.map(quoteAndPrefixify("cpp.dynamicLibraries")); + + data.linkOptions = []; + data.linkOptions = data.linkOptions.concat(cpp.driverLinkerFlags || []); + if ((cpp.linkerFlags || []).length > 0) { + data.linkOptions = + data.linkOptions.concat("LINKER:" + (cpp.linkerFlags || []).join(",")); + } + data.linkOptions = data.linkOptions.map(quote); + + data.includeDirectories = + (cpp.includePaths || []).map(quoteAndPrefixify("cpp.includePaths")); + data.compileDefinitions = (cpp.defines || []).map(quote); + + data.compileOptions = []; + data.compileOptions = data.compileOptions.concat(cpp.commonCompilerFlags || []); + data.compileOptions = data.compileOptions.concat(cpp.driverFlags || []); + data.compileOptions = data.compileOptions.concat(cpp.cxxFlags || []); + data.compileOptions = data.compileOptions.concat(cpp.cFlags || []); + data.compileOptions = data.compileOptions.map(quote); + } + + function gatherDeps(dep) { + if (dep.name === "Exporter.cmake") + return; + var depHasExporter = dep.Exporter && dep.Exporter.cmake; + if (!depHasExporter) + return; + data.packages.push(dep.Exporter.cmake.packageName); + } + + var exportedDeps = topLevelProduct.exports ? topLevelProduct.exports.dependencies : []; + exportedDeps.forEach(gatherDeps); + + return data; +} + +function writeConfigFile(project, product, outputs) +{ + var autoDetectedData = collectAutodetectedData(project, product, outputs); + var packageName = autoDetectedData.packageName; + + function writeCommand(command, lines) + { + if ((lines || []).length === 0) + return; + cmakeConfigFile.writeLine(command + "(" + packageName + " INTERFACE"); + for (i = 0; i < lines.length; i++) { + cmakeConfigFile.writeLine(" " + lines[i]); + } + cmakeConfigFile.writeLine(")"); + } + + var cmakeConfigFile = new TextFile(outputs["Exporter.cmake.configFile"][0].filePath, + TextFile.WriteOnly); + cmakeConfigFile.writeLine("# Generated by Qbs"); + + cmakeConfigFile.writeLine("cmake_minimum_required(VERSION 3.5)"); + + cmakeConfigFile.writeLine("if(TARGET " + packageName + ")"); + cmakeConfigFile.writeLine(" return()"); + cmakeConfigFile.writeLine("endif()"); + + cmakeConfigFile.writeLine("set(" + autoDetectedData.installPrefixDir + + " \"${CMAKE_CURRENT_LIST_DIR}/" + + autoDetectedData.installPrefix + "\")"); + + autoDetectedData.packages.forEach(function(packageName) { + cmakeConfigFile.writeLine("find_package(" + packageName + " REQUIRED SILENT)"); + }); + cmakeConfigFile.writeLine( + "add_library(" + packageName + " " + autoDetectedData.type + " IMPORTED)"); + var configuration = (product.qbs.buildVariant) ? + product.qbs.buildVariant.toUpperCase() : "NONE"; + cmakeConfigFile.writeLine("set_property(TARGET " + packageName + + " APPEND PROPERTY IMPORTED_CONFIGURATIONS " + + configuration + ")"); + + cmakeConfigFile.writeLine("set_target_properties(" + packageName + " PROPERTIES"); + cmakeConfigFile.writeLine(" IMPORTED_LINK_INTERFACE_LANGUAGES_" + configuration + + " CXX"); + if (autoDetectedData.type !== "INTERFACE") { + cmakeConfigFile.writeLine(" IMPORTED_LOCATION_" + configuration + " " + + autoDetectedData.importedLocation); + } + if (autoDetectedData.importedImplibLocation) { + cmakeConfigFile.writeLine(" IMPORTED_IMPLIB_" + configuration + " " + + autoDetectedData.importedImplibLocation); + } + cmakeConfigFile.writeLine(")"); + + writeCommand("target_link_directories", autoDetectedData.libraryPaths); + writeCommand("target_link_libraries", + autoDetectedData.linkLibraries.concat(autoDetectedData.packages)); + writeCommand("target_link_options", autoDetectedData.linkOptions); + writeCommand("target_include_directories", autoDetectedData.includeDirectories); + writeCommand("target_compile_definitions", autoDetectedData.compileDefinitions); + writeCommand("target_compile_options", autoDetectedData.compileOptions); + + cmakeConfigFile.close(); +} + +function writeVersionFile(product, outputs) +{ + var cmakeVersionFile = new TextFile( + outputs["Exporter.cmake.versionFile"][0].filePath, TextFile.WriteOnly); + cmakeVersionFile.writeLine("# Generated by Qbs"); + cmakeVersionFile.writeLine("set(PACKAGE_VERSION \"" + product.version + "\")"); + cmakeVersionFile.close(); +} diff --git a/share/qbs/modules/Exporter/cmake/cmakeexporter.qbs b/share/qbs/modules/Exporter/cmake/cmakeexporter.qbs new file mode 100644 index 000000000..a578e938b --- /dev/null +++ b/share/qbs/modules/Exporter/cmake/cmakeexporter.qbs @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2024 Raphaël Cotty <raphael.cotty@gmail.com> +** Copyright (C) 2024 Ivan Komissarov (abbapoh@gmail.com) +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qbs. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import qbs.File +import qbs.FileInfo +import qbs.ModUtils +import qbs.TextFile + +import "cmakeexporter.js" as HelperFunctions + +Module { + property string configFileName: packageName + "Config.cmake" + property string versionFileName: packageName + "ConfigVersion.cmake" + property string packageName: product.targetName + + additionalProductTypes: ["Exporter.cmake.package"] + + Rule { + multiplex: true + requiresInputs: false + + auxiliaryInputs: { + if (product.type.includes("staticlibrary")) + return ["staticlibrary"]; + if (product.type.includes("dynamiclibrary")) + return ["dynamiclibrary"]; + } + + Artifact { + filePath: product.Exporter.cmake.configFileName + fileTags: ["Exporter.cmake.package", "Exporter.cmake.configFile"] + } + Artifact { + filePath: product.Exporter.cmake.versionFileName + fileTags: ["Exporter.cmake.package", "Exporter.cmake.versionFile"] + } + prepare: { + var cmd = new JavaScriptCommand(); + cmd.description = "generate cmake package files"; + cmd.sourceCode = function() { + HelperFunctions.writeConfigFile(project, product, outputs); + HelperFunctions.writeVersionFile(product, outputs); + } + return [cmd]; + } + } +} diff --git a/share/qbs/modules/Exporter/exporter.js b/share/qbs/modules/Exporter/exporter.js new file mode 100644 index 000000000..65a632ac8 --- /dev/null +++ b/share/qbs/modules/Exporter/exporter.js @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Copyright (C) 2024 Ivan Komissarov (abbapoh@gmail.com) +** Contact: http://www.qt.io/licensing +** +** This file is part of the Qbs. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +function getPrefixToStrip(project, product, propName, value) +{ + function checkValuePrefix(forbiddenPrefix, prefixDescription) + { + if (value.startsWith(forbiddenPrefix)) { + throw "Value '" + value + "' for exported property '" + propName + "' in product '" + + product.name + "' points into " + prefixDescription + ".\n" + + "Did you forget to set the prefixMapping property in an Export item?"; + } + } + + // Catch user oversights: Paths that point into the project source or build directories + // make no sense in the module. + if (!value.startsWith(product.qbs.installRoot)) { + checkValuePrefix(project.buildDirectory, "project build directory"); + checkValuePrefix(project.sourceDirectory, "project source directory"); + } + + // Adapt file paths pointing into the install dir, that is, make them relative to the + // module file for relocatability. We accept them with or without the install root. + // The latter form will typically be a result of applying the prefixMapping property, + // while the first one could be an untransformed path, for instance if the project + // file is written in such a way that include paths are picked up from the installed + // location rather than the source directory. + var result; + var fullInstallPrefix = FileInfo.joinPaths(product.qbs.installRoot, product.qbs.installPrefix); + if (fullInstallPrefix.length > 1 && value.startsWith(fullInstallPrefix)) { + result = fullInstallPrefix; + } else { + var installPrefix = FileInfo.joinPaths("/", product.qbs.installPrefix); + if (installPrefix.length > 1 && value.startsWith(installPrefix)) + result = installPrefix; + } + return result; +} diff --git a/share/qbs/modules/Exporter/qbs/qbsexporter.js b/share/qbs/modules/Exporter/qbs/qbsexporter.js index f09dd2d0c..145474a4b 100644 --- a/share/qbs/modules/Exporter/qbs/qbsexporter.js +++ b/share/qbs/modules/Exporter/qbs/qbsexporter.js @@ -30,6 +30,7 @@ var FileInfo = require("qbs.FileInfo"); var ModUtils = require("qbs.ModUtils"); +var ExporterHelpers = require("../exporter.js"); function tagListToString(tagList) { @@ -102,15 +103,6 @@ function writeTargetArtifactGroups(product, output, moduleFile) } } -function checkValuePrefix(name, value, forbiddenPrefix, prefixDescription) -{ - if (value.startsWith(forbiddenPrefix)) { - throw "Value '" + value + "' for exported property '" + name + "' in product '" - + product.name + "' points into " + prefixDescription + ".\n" - + "Did you forget to set the prefixMapping property in an Export item?"; - } -} - function stringifyValue(project, product, moduleInstallDir, prop, value) { if (value instanceof Array) { @@ -128,29 +120,9 @@ function stringifyValue(project, product, moduleInstallDir, prop, value) return value; } - // Catch user oversights: Paths that point into the project source or build directories - // make no sense in the module. - if (!value.startsWith(product.qbs.installRoot)) { - checkValuePrefix(prop.name, value, project.buildDirectory, "project build directory"); - checkValuePrefix(prop.name, value, project.sourceDirectory, "project source directory"); - } - - // Adapt file paths pointing into the install dir, that is, make them relative to the - // module file for relocatability. We accept them with or without the install root. - // The latter form will typically be a result of applying the prefixMapping property, - // while the first one could be an untransformed path, for instance if the project - // file is written in such a way that include paths are picked up from the installed - // location rather than the source directory. - var valuePrefixToStrip; - var fullInstallPrefix = FileInfo.joinPaths(product.qbs.installRoot, product.qbs.installPrefix); - if (fullInstallPrefix.length > 1 && value.startsWith(fullInstallPrefix)) { - valuePrefixToStrip = fullInstallPrefix; - } else { - var installPrefix = FileInfo.joinPaths("/", product.qbs.installPrefix); - if (installPrefix.length > 1 && value.startsWith(installPrefix)) - valuePrefixToStrip = installPrefix; - } + var valuePrefixToStrip = ExporterHelpers.getPrefixToStrip(project, product, prop.name, value); if (valuePrefixToStrip) { + var fullInstallPrefix = FileInfo.joinPaths(product.qbs.installRoot, product.qbs.installPrefix); var deployedModuleInstallDir = moduleInstallDir.slice(fullInstallPrefix.length); return "FileInfo.cleanPath(FileInfo.joinPaths(path, FileInfo.relativePath(" + JSON.stringify(deployedModuleInstallDir) + ", " diff --git a/share/qbs/modules/Sanitizers/address/asan.qbs b/share/qbs/modules/Sanitizers/address/asan.qbs index 9ae6f285e..9d8f5b97e 100644 --- a/share/qbs/modules/Sanitizers/address/asan.qbs +++ b/share/qbs/modules/Sanitizers/address/asan.qbs @@ -64,7 +64,8 @@ Module { flags.push("-fsanitize-address-use-after-scope"); if (detectUseAfterReturn) { if (qbs.toolchain.includes("llvm")) { - if (Utilities.versionCompare(cpp.compilerVersion, "13") >= 0) + var minVersion = qbs.toolchain.contains("xcode") ? "14" : "13"; + if (Utilities.versionCompare(cpp.compilerVersion, minVersion) >= 0) flags.push("-fsanitize-address-use-after-return=" + detectUseAfterReturn); } else if (detectUseAfterReturn === "never") { flags.push("--param", "asan-use-after-return=0"); diff --git a/share/qbs/modules/bundle/BundleModule.qbs b/share/qbs/modules/bundle/BundleModule.qbs index 0d8452a7e..f640fd55f 100644 --- a/share/qbs/modules/bundle/BundleModule.qbs +++ b/share/qbs/modules/bundle/BundleModule.qbs @@ -193,6 +193,11 @@ Module { property string _productTypeIdentifier: Bundle.productTypeIdentifier(product.type) property stringList _productTypeIdentifierChain: bundleSettingsProbe.productTypeIdentifierChain + readonly property path _developerPath: xcode.developerPath + readonly property path _platformInfoPlist: xcode.platformInfoPlist + readonly property path _sdkSettingsPlist: xcode.sdkSettingsPlist + readonly property path _toolchainInfoPlist: xcode.toolchainInfoPlist + property bool _useXcodeBuildSpecs: true // TODO: remove in 1.25 property var extraEnv: ({ @@ -281,8 +286,8 @@ Module { outputFileTags: ["bundle.input", "aggregate_infoplist"] outputArtifacts: { var artifacts = []; - var embed = ModUtils.moduleProperty(product, "embedInfoPlist"); - if (ModUtils.moduleProperty(product, "isBundle") || embed) { + var embed = product.bundle.embedInfoPlist; + if (product.bundle.isBundle || embed) { artifacts.push({ filePath: FileInfo.joinPaths( product.destinationDirectory, product.name + "-Info.plist"), @@ -290,7 +295,7 @@ Module { bundle: { _bundleFilePath: FileInfo.joinPaths( product.destinationDirectory, - ModUtils.moduleProperty(product, "infoPlistPath")), + product.bundle.infoPlistPath), } }); } @@ -301,20 +306,21 @@ Module { var cmd = new JavaScriptCommand(); cmd.description = "generating Info.plist for " + product.name; cmd.highlight = "codegen"; - cmd.infoPlist = ModUtils.moduleProperty(product, "infoPlist") || {}; - cmd.processInfoPlist = ModUtils.moduleProperty(product, "processInfoPlist"); - cmd.infoPlistFormat = ModUtils.moduleProperty(product, "infoPlistFormat"); - cmd.extraEnv = ModUtils.moduleProperty(product, "extraEnv"); - cmd.qmakeEnv = ModUtils.moduleProperty(product, "qmakeEnv"); + cmd.infoPlist = product.bundle.infoPlist || {}; + cmd.processInfoPlist = product.bundle.processInfoPlist; + cmd.infoPlistFormat = product.bundle.infoPlistFormat; + cmd.extraEnv = product.bundle.extraEnv; + cmd.qmakeEnv = product.bundle.qmakeEnv; + // TODO: bundle module should know nothing about cpp module cmd.buildEnv = product.moduleProperty("cpp", "buildEnv"); - cmd.developerPath = product.moduleProperty("xcode", "developerPath"); - cmd.platformInfoPlist = product.moduleProperty("xcode", "platformInfoPlist"); - cmd.sdkSettingsPlist = product.moduleProperty("xcode", "sdkSettingsPlist"); - cmd.toolchainInfoPlist = product.moduleProperty("xcode", "toolchainInfoPlist"); + cmd.developerPath = product.bundle._developerPath; + cmd.platformInfoPlist = product.bundle._platformInfoPlist; + cmd.sdkSettingsPlist = product.bundle._sdkSettingsPlist; + cmd.toolchainInfoPlist = product.bundle._toolchainInfoPlist; - cmd.osBuildVersion = product.moduleProperty("qbs", "hostOSBuildVersion"); + cmd.osBuildVersion = product.qbs.hostOSBuildVersion; cmd.sourceCode = function() { var plist, process, key, i; @@ -343,7 +349,7 @@ Module { if (processInfoPlist) { // Add default values to the aggregate plist if the corresponding keys // for those values are not already present - var defaultValues = ModUtils.moduleProperty(product, "defaultInfoPlist"); + var defaultValues = product.bundle.defaultInfoPlist; for (key in defaultValues) { if (defaultValues.hasOwnProperty(key) && !(key in aggregatePlist)) aggregatePlist[key] = defaultValues[key]; @@ -480,11 +486,11 @@ Module { outputFileTags: ["bundle.input", "pkginfo"] outputArtifacts: { var artifacts = []; - if (ModUtils.moduleProperty(product, "isBundle") && ModUtils.moduleProperty(product, "generatePackageInfo")) { + if (product.bundle.isBundle && product.bundle.generatePackageInfo) { artifacts.push({ filePath: FileInfo.joinPaths(product.destinationDirectory, "PkgInfo"), fileTags: ["bundle.input", "pkginfo"], - bundle: { _bundleFilePath: FileInfo.joinPaths(product.destinationDirectory, ModUtils.moduleProperty(product, "pkgInfoPath")) } + bundle: { _bundleFilePath: FileInfo.joinPaths(product.destinationDirectory, product.bundle.pkgInfoPath) } }); } return artifacts; @@ -535,9 +541,9 @@ Module { "bundle.code-signature"] outputArtifacts: { var i, artifacts = []; - if (ModUtils.moduleProperty(product, "isBundle")) { + if (product.bundle.isBundle) { for (i in inputs["bundle.input"]) { - var fp = inputs["bundle.input"][i].moduleProperty("bundle", "_bundleFilePath"); + var fp = inputs["bundle.input"][i].bundle._bundleFilePath; if (!fp) throw("Artifact " + inputs["bundle.input"][i].filePath + " has no associated bundle file path"); var extraTags = inputs["bundle.input"][i].fileTags.includes("application") @@ -552,20 +558,19 @@ Module { for (i in provprofiles) { artifacts.push({ filePath: FileInfo.joinPaths(product.destinationDirectory, - ModUtils.moduleProperty(product, - "contentsFolderPath"), + product.bundle.contentsFolderPath, provprofiles[i].fileName), fileTags: ["bundle.provisioningprofile", "bundle.content"] }); } - var packageType = ModUtils.moduleProperty(product, "packageType"); - var isShallow = ModUtils.moduleProperty(product, "isShallow"); + var packageType = product.bundle.packageType; + var isShallow = product.bundle.isShallow; if (packageType === "FMWK" && !isShallow) { - var publicHeaders = ModUtils.moduleProperty(product, "publicHeaders"); + var publicHeaders = product.bundle.publicHeaders; if (publicHeaders && publicHeaders.length) { artifacts.push({ - filePath: FileInfo.joinPaths(product.destinationDirectory, ModUtils.moduleProperty(product, "bundleName"), "Headers"), + filePath: FileInfo.joinPaths(product.destinationDirectory, product.bundle.bundleName, "Headers"), fileTags: ["bundle.symlink.headers", "bundle.content"] }); } @@ -573,23 +578,23 @@ Module { var privateHeaders = ModUtils.moduleProperty(product, "privateHeaders"); if (privateHeaders && privateHeaders.length) { artifacts.push({ - filePath: FileInfo.joinPaths(product.destinationDirectory, ModUtils.moduleProperty(product, "bundleName"), "PrivateHeaders"), + filePath: FileInfo.joinPaths(product.destinationDirectory, product.bundle.bundleName, "PrivateHeaders"), fileTags: ["bundle.symlink.private-headers", "bundle.content"] }); } artifacts.push({ - filePath: FileInfo.joinPaths(product.destinationDirectory, ModUtils.moduleProperty(product, "bundleName"), "Resources"), + filePath: FileInfo.joinPaths(product.destinationDirectory, product.bundle.bundleName, "Resources"), fileTags: ["bundle.symlink.resources", "bundle.content"] }); artifacts.push({ - filePath: FileInfo.joinPaths(product.destinationDirectory, ModUtils.moduleProperty(product, "bundleName"), product.targetName), + filePath: FileInfo.joinPaths(product.destinationDirectory, product.bundle.bundleName, product.targetName), fileTags: ["bundle.symlink.executable", "bundle.content"] }); artifacts.push({ - filePath: FileInfo.joinPaths(product.destinationDirectory, ModUtils.moduleProperty(product, "versionsFolderPath"), "Current"), + filePath: FileInfo.joinPaths(product.destinationDirectory, product.bundle.versionsFolderPath, "Current"), fileTags: ["bundle.symlink.version", "bundle.content"] }); } @@ -606,7 +611,7 @@ Module { } } - sources = ModUtils.moduleProperty(product, "resources"); + sources = product.bundle.resources; for (i in sources) { destination = BundleTools.destinationDirectoryForResource(product, {baseDir: FileInfo.path(sources[i]), fileName: FileInfo.fileName(sources[i])}); artifacts.push({ @@ -617,7 +622,7 @@ Module { var wrapperPath = FileInfo.joinPaths( product.destinationDirectory, - ModUtils.moduleProperty(product, "bundleName")); + product.bundle.bundleName); for (var i = 0; i < artifacts.length; ++i) artifacts[i].bundle = { wrapperPath: wrapperPath }; @@ -634,7 +639,7 @@ Module { prepare: { var i, cmd, commands = []; - var packageType = ModUtils.moduleProperty(product, "packageType"); + var packageType = product.bundle.packageType; var bundleType = "bundle"; if (packageType === "APPL") @@ -652,7 +657,7 @@ Module { var symlinks = outputs["bundle.symlink.version"]; for (i in symlinks) { - cmd = new Command("ln", ["-sfn", ModUtils.moduleProperty(product, "frameworkVersion"), + cmd = new Command("ln", ["-sfn", product.bundle.frameworkVersion, symlinks[i].filePath]); cmd.silent = true; commands.push(cmd); @@ -699,8 +704,8 @@ Module { } var bundleInputs = sortedArtifactList(inputs["bundle.input"], function (a, b) { - return a.moduleProperty("bundle", "_bundleFilePath").localeCompare( - b.moduleProperty("bundle", "_bundleFilePath")); + return a.bundle._bundleFilePath.localeCompare( + b.bundle._bundleFilePath); }); var bundleContents = sortedArtifactList(outputs["bundle.content.copied"]); for (i in bundleContents) { @@ -733,8 +738,8 @@ Module { cmd = new JavaScriptCommand(); cmd.description = "copying public headers"; cmd.highlight = "filegen"; - cmd.sources = ModUtils.moduleProperty(product, "publicHeaders"); - cmd.destination = FileInfo.joinPaths(product.destinationDirectory, ModUtils.moduleProperty(product, "publicHeadersFolderPath")); + cmd.sources = product.bundle.publicHeaders; + cmd.destination = FileInfo.joinPaths(product.destinationDirectory, product.bundle.publicHeadersFolderPath); cmd.sourceCode = function() { var i; for (var i in sources) { @@ -747,8 +752,8 @@ Module { cmd = new JavaScriptCommand(); cmd.description = "copying private headers"; cmd.highlight = "filegen"; - cmd.sources = ModUtils.moduleProperty(product, "privateHeaders"); - cmd.destination = FileInfo.joinPaths(product.destinationDirectory, ModUtils.moduleProperty(product, "privateHeadersFolderPath")); + cmd.sources = product.bundle.privateHeaders; + cmd.destination = FileInfo.joinPaths(product.destinationDirectory, product.bundle.privateHeadersFolderPath); cmd.sourceCode = function() { var i; for (var i in sources) { @@ -761,7 +766,7 @@ Module { cmd = new JavaScriptCommand(); cmd.description = "copying resources"; cmd.highlight = "filegen"; - cmd.sources = ModUtils.moduleProperty(product, "resources"); + cmd.sources = product.bundle.resources; cmd.sourceCode = function() { var i; for (var i in sources) { @@ -772,17 +777,17 @@ Module { if (cmd.sources && cmd.sources.length) commands.push(cmd); - if (product.moduleProperty("qbs", "hostOS").includes("darwin")) { + if (product.qbs.hostOS.includes("darwin")) { Array.prototype.push.apply(commands, Codesign.prepareSign( project, product, inputs, outputs, input, output)); if (bundleType === "application" - && product.moduleProperty("qbs", "targetOS").includes("macos")) { + && product.qbs.targetOS.includes("macos")) { var bundlePath = FileInfo.joinPaths( product.destinationDirectory, product.bundle.bundleName); - cmd = new Command(ModUtils.moduleProperty(product, "lsregisterPath"), + cmd = new Command(product.bundle.lsregisterPath, ["-f", bundlePath]); - cmd.description = "registering " + ModUtils.moduleProperty(product, "bundleName"); + cmd.description = "registering " + product.bundle.bundleName; commands.push(cmd); } } diff --git a/share/qbs/modules/bundle/bundle.js b/share/qbs/modules/bundle/bundle.js index ec0e30054..cf765f7be 100644 --- a/share/qbs/modules/bundle/bundle.js +++ b/share/qbs/modules/bundle/bundle.js @@ -152,13 +152,21 @@ function _assign(target, source) { function macOSSpecsPaths(version, developerPath) { var result = []; - if (Utilities.versionCompare(version, "12.5") >= 0) { + if (Utilities.versionCompare(version, "15.3") >= 0) { + result.push(FileInfo.joinPaths( + developerPath, "..", "SharedFrameworks", "XCBuild.framework", "PlugIns", + "XCBBuildService.bundle", "Contents", "PlugIns", "XCBSpecifications.ideplugin", + "Contents", "Resources")); + } + if (Utilities.versionCompare(version, "14.3") >= 0) { + result.push(FileInfo.joinPaths( + developerPath, "Library", "Xcode", "Plug-ins", "XCBSpecifications.ideplugin", + "Contents", "Resources")); + } else if (Utilities.versionCompare(version, "12.5") >= 0) { result.push(FileInfo.joinPaths( developerPath, "..", "PlugIns", "XCBSpecifications.ideplugin", "Contents", "Resources")); - } - - if (Utilities.versionCompare(version, "12") >= 0) { + } else if (Utilities.versionCompare(version, "12") >= 0) { result.push(FileInfo.joinPaths( developerPath, "Platforms", "MacOSX.platform", "Developer", "Library", "Xcode", "PrivatePlugIns", "IDEOSXSupportCore.ideplugin", "Contents", "Resources")); @@ -311,7 +319,8 @@ var XcodeBuildSpecsReader = (function () { }; XcodeBuildSpecsReader.prototype.expandedSetting = function (typeIdentifier, baseSettings, settingName) { - var obj = baseSettings || {}; + var obj = {}; + _assign(obj, baseSettings); // todo: copy recursively obj = _assign(obj, this.settings(typeIdentifier, true)); if (obj) { for (var x in this._additionalSettings) { diff --git a/share/qbs/modules/capnproto/capnprotobase.qbs b/share/qbs/modules/capnproto/capnprotobase.qbs index e84d39433..916e53a51 100644 --- a/share/qbs/modules/capnproto/capnprotobase.qbs +++ b/share/qbs/modules/capnproto/capnprotobase.qbs @@ -28,6 +28,7 @@ ** ****************************************************************************/ +import qbs.FileInfo import qbs.Probes import "capnproto.js" as HelperFunctions @@ -40,16 +41,20 @@ Module { property pathList importPaths: [] - readonly property string outputDir: product.buildDirectory + "/capnp" + property string outputDir: product.buildDirectory + "/capnp" + + property var _searchPaths Probes.BinaryProbe { id: compilerProbe names: compilerName ? [compilerName] : [] + searchPaths: _searchPaths } Probes.BinaryProbe { id: pluginProbe names: pluginName ? [pluginName] : [] + searchPaths: _searchPaths } FileTagger { diff --git a/share/qbs/modules/capnproto/cpp/capnprotocpp.qbs b/share/qbs/modules/capnproto/cpp/capnprotocpp.qbs index f33bc9a48..83192b7de 100644 --- a/share/qbs/modules/capnproto/cpp/capnprotocpp.qbs +++ b/share/qbs/modules/capnproto/cpp/capnprotocpp.qbs @@ -39,6 +39,8 @@ CapnProtoBase { Depends { name: "capnp-rpc"; condition: useRpc } pluginName: "capnpc-c++" + version: capnp.version + _searchPaths: capnp.hostBinDirs cpp.systemIncludePaths: outputDir cpp.cxxLanguageVersion: "c++14" diff --git a/share/qbs/modules/codesign/apple.qbs b/share/qbs/modules/codesign/apple.qbs index 72384a06a..0d1335d92 100644 --- a/share/qbs/modules/codesign/apple.qbs +++ b/share/qbs/modules/codesign/apple.qbs @@ -181,7 +181,7 @@ CodeSignModule { } readonly property string _embeddedProfileName: - (xcode._platformProps || {})["EMBEDDED_PROFILE_NAME"] + (xcode._platformProps || {})["EMBEDDED_PROFILE_NAME"] || "embedded.mobileprovision" setupBuildEnvironment: { var prefixes = product.xcode ? [ diff --git a/share/qbs/modules/codesign/codesign.js b/share/qbs/modules/codesign/codesign.js index 903d16f80..482225ea2 100644 --- a/share/qbs/modules/codesign/codesign.js +++ b/share/qbs/modules/codesign/codesign.js @@ -280,20 +280,21 @@ function prepareSign(project, product, inputs, outputs, input, output) { return cmds; var isBundle = "bundle.content" in outputs; - var outputFilePath = isBundle - ? FileInfo.joinPaths(product.destinationDirectory, product.bundle.bundleName) - : outputs["codesign.signed_artifact"][0].filePath; - var outputFileName = isBundle - ? product.bundle.bundleName - : outputs["codesign.signed_artifact"][0].fileName; - var isProductBundle = product.bundle && product.bundle.isBundle; - // If the product is a bundle, just sign the bundle - // instead of signing the bundle and executable separately + var artifacts = []; + if (isBundle) { + artifacts = [{ + filePath: FileInfo.joinPaths(product.destinationDirectory, product.bundle.bundleName), + fileName: product.bundle.bundleName + }]; + } else { + artifacts = outputs["codesign.signed_artifact"]; + } + var isProductBundle = product.bundle && product.bundle.isBundle; var shouldSignArtifact = !isProductBundle || isBundle; var enableCodeSigning = product.codesign.enableCodeSigning; - if (enableCodeSigning && shouldSignArtifact) { + if (enableCodeSigning) { var actualSigningIdentity = product.codesign._actualSigningIdentity; if (!actualSigningIdentity) { throw "No codesigning identities (i.e. certificate and private key pairs) matching “" @@ -310,36 +311,53 @@ function prepareSign(project, product, inputs, outputs, input, output) { } } - var args = ["--force", "--sign", actualSigningIdentity.SHA1]; - - // If signingTimestamp is undefined or empty, do not specify the flag at all - - // this uses the system-specific default behavior - var signingTimestamp = product.codesign.signingTimestamp; - if (signingTimestamp) { - // If signingTimestamp is an empty string, specify the flag but do - // not specify a value - this uses a default Apple-provided server - var flag = "--timestamp"; - if (signingTimestamp) - flag += "=" + signingTimestamp; - args.push(flag); + // The codesign tool behaves weirdly. It can sign a bundle with a single artifact, but if + // say debug build variant is present, it starts complaining that it is not signed. + // We could always sign everything, but again, in case of a framework (but not in case of + // app or loadable bundle), codesign produces a warning that artifact is already signed. + // So, we skip signing the release artifact and only sign if other build variants present. + if (!shouldSignArtifact && artifacts.length == 1) { + artifacts = []; } + for (var i = 0; i < artifacts.length; ++i) { + if (!shouldSignArtifact + && artifacts[i].qbs && artifacts[i].qbs.buildVariant === "release") { + continue; + } + var outputFilePath = artifacts[i].filePath; + var outputFileName = artifacts[i].fileName; + + var args = ["--force", "--sign", actualSigningIdentity.SHA1]; + + // If signingTimestamp is undefined or empty, do not specify the flag at all - + // this uses the system-specific default behavior + var signingTimestamp = product.codesign.signingTimestamp; + if (signingTimestamp) { + // If signingTimestamp is an empty string, specify the flag but do + // not specify a value - this uses a default Apple-provided server + var flag = "--timestamp"; + if (signingTimestamp) + flag += "=" + signingTimestamp; + args.push(flag); + } - for (var j in inputs["codesign.xcent"]) { - args.push("--entitlements", inputs["codesign.xcent"][j].filePath); - break; // there should only be one - } + for (var j in inputs["codesign.xcent"]) { + args.push("--entitlements", inputs["codesign.xcent"][j].filePath); + break; // there should only be one + } - args = args.concat(product.codesign.codesignFlags || []); + args = args.concat(product.codesign.codesignFlags || []); - args.push(outputFilePath + subpath); - cmd = new Command(product.codesign.codesignPath, args); - cmd.description = "codesign " + outputFileName - + " (" + actualSigningIdentity.subjectInfo.CN + ")"; - cmd.outputFilePath = outputFilePath; - cmd.stderrFilterFunction = function(stderr) { - return stderr.replace(outputFilePath + ": replacing existing signature\n", ""); - }; - cmds.push(cmd); + args.push(outputFilePath + subpath); + cmd = new Command(product.codesign.codesignPath, args); + cmd.description = "codesign " + outputFileName + + " (" + actualSigningIdentity.subjectInfo.CN + ")"; + cmd.outputFilePath = outputFilePath; + cmd.stderrFilterFunction = function(stderr) { + return stderr.replace(outputFilePath + ": replacing existing signature\n", ""); + }; + cmds.push(cmd); + } } if (isBundle) { diff --git a/share/qbs/modules/cpp/GenericGCC.qbs b/share/qbs/modules/cpp/GenericGCC.qbs index 22a98ad57..f84028940 100644 --- a/share/qbs/modules/cpp/GenericGCC.qbs +++ b/share/qbs/modules/cpp/GenericGCC.qbs @@ -170,7 +170,7 @@ CppModule { property string linkerVariant PropertyOptions { name: "linkerVariant" - allowedValues: ["bfd", "gold", "lld"] + allowedValues: ["bfd", "gold", "lld", "mold"] description: "Allows to specify the linker variant. Maps to gcc's and clang's -fuse-ld " + "option." } @@ -216,7 +216,7 @@ CppModule { linkerScriptFlag: "-T" readonly property bool shouldCreateSymlinks: { - return createSymlinks && internalVersion && ["macho", "elf"].includes(cpp.imageFormat); + return createSymlinks && internalVersion && ["macho", "elf"].includes(imageFormat); } readonly property bool shouldSignArtifacts: codesign._canSignArtifacts @@ -252,7 +252,7 @@ CppModule { property var buildEnv: { var env = {}; if (qbs.toolchain.includes("mingw")) - env.PATH = [toolchainInstallPath]; // For libwinpthread etc + env.PATH = toolchainInstallPath; // For libwinpthread etc return env; } diff --git a/share/qbs/modules/cpp/cpp.js b/share/qbs/modules/cpp/cpp.js index a13504013..9f907580a 100644 --- a/share/qbs/modules/cpp/cpp.js +++ b/share/qbs/modules/cpp/cpp.js @@ -327,7 +327,10 @@ function collectIncludePaths(input) { var includePaths = input.cpp.includePaths; if (includePaths) allIncludePaths = allIncludePaths.uniqueConcat(includePaths); - return allIncludePaths; + var builtIns = input.cpp.compilerIncludePaths; + return allIncludePaths.filter(function(p) { + return !builtIns.includes(p); + }); } function collectSystemIncludePaths(input) { @@ -338,7 +341,10 @@ function collectSystemIncludePaths(input) { var distributionIncludePaths = input.cpp.distributionIncludePaths; if (distributionIncludePaths) allIncludePaths = allIncludePaths.uniqueConcat(distributionIncludePaths); - return allIncludePaths; + var builtIns = input.cpp.compilerIncludePaths; + return allIncludePaths.filter(function(p) { + return !builtIns.includes(p); + }); } function collectPreincludePaths(input) { diff --git a/share/qbs/modules/cpp/gcc.js b/share/qbs/modules/cpp/gcc.js index 747c6c9ee..90f8fc933 100644 --- a/share/qbs/modules/cpp/gcc.js +++ b/share/qbs/modules/cpp/gcc.js @@ -78,6 +78,7 @@ function useCompilerDriverLinker(product, inputs) { function collectLibraryDependencies(product, isDarwin) { var publicDeps = {}; + var privateDeps = {}; var objects = []; var objectByFilePath = {}; var tagForLinkingAgainstSharedLib = product.cpp.imageFormat === "pe" @@ -170,6 +171,8 @@ function collectLibraryDependencies(product, isDarwin) { && typeof dep.artifacts[tagForLinkingAgainstSharedLib] !== "undefined"; if (!isStaticLibrary && !isDynamicLibrary) return; + if (isBelowIndirectDynamicLib && privateDeps[dep.name]) + return; var nextIsBelowIndirectDynamicLib = isBelowIndirectDynamicLib || isDynamicLibrary; dep.dependencies.forEach(function(depdep) { @@ -193,6 +196,7 @@ function collectLibraryDependencies(product, isDarwin) { publicDeps[dep.name] = true; } else { addArtifactFilePaths(dep, tagForLinkingAgainstSharedLib, addPrivateFilePath); + privateDeps[dep.name] = true; } } } @@ -204,7 +208,6 @@ function collectLibraryDependencies(product, isDarwin) { product.dependencies.forEach(traverseDirectDependency); addExternalLibs(product); - var seenRPathLinkDirs = {}; var result = { libraries: [], rpath_link: [] }; objects.forEach( function (obj) { @@ -215,10 +218,7 @@ function collectLibraryDependencies(product, isDarwin) { framework: obj.framework }); } else { var dirPath = FileInfo.path(obj.filePath); - if (!seenRPathLinkDirs.hasOwnProperty(dirPath)) { - seenRPathLinkDirs[dirPath] = true; - result.rpath_link.push(dirPath); - } + result.rpath_link.push(dirPath); } }); return result; @@ -377,6 +377,9 @@ function linkerFlags(project, product, inputs, outputs, primaryOutput, linkerPat var minimumWindowsVersion = product.cpp.minimumWindowsVersion; if (minimumWindowsVersion) { + // workaround for QBS-1724, mingw seems to be broken + if (Utilities.versionCompare(minimumWindowsVersion, "6.2") > 0) + minimumWindowsVersion = "6.2"; var subsystemVersion = WindowsUtils.getWindowsVersionInFormat(minimumWindowsVersion, 'subsystem'); if (subsystemVersion) { var major = subsystemVersion.split('.')[0]; @@ -403,8 +406,8 @@ function linkerFlags(project, product, inputs, outputs, primaryOutput, linkerPat // Flags for library search paths var allLibraryPaths = Cpp.collectLibraryPaths(product); - if (systemRunPaths.length > 0) - allLibraryPaths = allLibraryPaths.filter(isNotSystemRunPath); + var builtIns = product.cpp.compilerLibraryPaths + allLibraryPaths = allLibraryPaths.filter(function(p) { return !builtIns.includes(p); }); args = args.concat(allLibraryPaths.map(function(path) { return product.cpp.libraryPathFlag + path })); escapableLinkerFlags = escapableLinkerFlags.concat(Cpp.collectLinkerScriptPathsArguments(product, inputs)); @@ -474,7 +477,10 @@ function linkerFlags(project, product, inputs, outputs, primaryOutput, linkerPat if (isDarwin && symbolLinkMode) { if (!["lazy", "reexport", "upward", "weak"].includes(symbolLinkMode)) throw new Error("unknown value '" + symbolLinkMode + "' for cpp.symbolLinkMode"); + } + var supportsLazyMode = Utilities.versionCompare(product.cpp.compilerVersion, "15.0.0") < 0; + if (isDarwin && symbolLinkMode && (symbolLinkMode !== "lazy" || supportsLazyMode)) { if (FileInfo.isAbsolutePath(lib) || lib.startsWith('@')) escapableLinkerFlags.push("-" + symbolLinkMode + "_library", lib); else if (dep.framework) diff --git a/share/qbs/modules/cpp/msvc.js b/share/qbs/modules/cpp/msvc.js index 8be4bff24..1700c21b3 100644 --- a/share/qbs/modules/cpp/msvc.js +++ b/share/qbs/modules/cpp/msvc.js @@ -79,8 +79,8 @@ function hasCxx17Option(input) { // Probably this is not the earliest version to support the flag, but we have tested this one // and it's a pain to find out the exact minimum. - return Utilities.versionCompare(input.cpp.compilerVersion, "19.12.25831") >= 0 - || (input.qbs.toolchain.includes("clang-cl") && input.cpp.compilerVersionMajor >= 7); + return (input.qbs.toolchain.includes("clang-cl") && input.cpp.compilerVersionMajor >= 7) + || Utilities.versionCompare(input.cpp.compilerVersion, "19.12.25831") >= 0; } function hasZCplusPlusOption(input) @@ -92,20 +92,20 @@ function hasZCplusPlusOption(input) // clang-cl supports this option starting around-ish versions 8/9, but it // ignores this option, so this doesn't really matter // https://reviews.llvm.org/D45877 - return Utilities.versionCompare(input.cpp.compilerVersion, "19.14.26433") >= 0 - || (input.qbs.toolchain.includes("clang-cl") && input.cpp.compilerVersionMajor >= 9); + return (input.qbs.toolchain.includes("clang-cl") && input.cpp.compilerVersionMajor >= 9) + || Utilities.versionCompare(input.cpp.compilerVersion, "19.14.26433") >= 0; } function hasCxx20Option(input) { - return Utilities.versionCompare(input.cpp.compilerVersion, "19.29.30133.0") >= 0 - || (input.qbs.toolchain.includes("clang-cl") && input.cpp.compilerVersionMajor >= 13); + return (input.qbs.toolchain.includes("clang-cl") && input.cpp.compilerVersionMajor >= 13) + || Utilities.versionCompare(input.cpp.compilerVersion, "19.29.30133.0") >= 0; } function hasCVerOption(input) { - return Utilities.versionCompare(input.cpp.compilerVersion, "19.29.30138.0") >= 0 - || (input.qbs.toolchain.includes("clang-cl") && input.cpp.compilerVersionMajor >= 13); + return (input.qbs.toolchain.includes("clang-cl") && input.cpp.compilerVersionMajor >= 13) + || Utilities.versionCompare(input.cpp.compilerVersion, "19.29.30138.0") >= 0; } function supportsExternalIncludesOption(input) { @@ -124,10 +124,9 @@ function addCxxLanguageVersionFlag(input, args) { if (!cxxVersion) return; - // Visual C++ 2013, Update 3 - var hasStdOption = Utilities.versionCompare(input.cpp.compilerVersion, "18.00.30723") >= 0 - // or clang-cl - || input.qbs.toolchain.includes("clang-cl"); + // Visual C++ 2013, Update 3 or clang-cl + var hasStdOption = input.qbs.toolchain.includes("clang-cl") + || Utilities.versionCompare(input.cpp.compilerVersion, "18.00.30723") >= 0; if (!hasStdOption) return; @@ -250,14 +249,17 @@ function prepareCompiler(project, product, inputs, outputs, input, output, expli return input.cpp.includeFlag + FileInfo.toWindowsSeparators(path); })); - var includeFlag = input.cpp.includeFlag; - if (supportsExternalIncludesOption(input)) { - args.push("/experimental:external"); - var enforcesSlashW = - Utilities.versionCompare(input.cpp.compilerVersion, "19.29.30037") >= 0 - if (enforcesSlashW) - args.push("/external:W0") - includeFlag = input.cpp.systemIncludeFlag; + var includeFlag = input.qbs.toolchain.includes("clang-cl") + ? input.cpp.systemIncludeFlag : input.cpp.includeFlag; + if (!input.qbs.toolchain.includes("clang-cl")) { + if (supportsExternalIncludesOption(input)) { + args.push("/experimental:external"); + var enforcesSlashW = + Utilities.versionCompare(input.cpp.compilerVersion, "19.29.30037") >= 0 + if (enforcesSlashW) + args.push("/external:W0") + includeFlag = input.cpp.systemIncludeFlag; + } } var systemIncludePaths = Cpp.collectSystemIncludePaths(input); args = args.concat([].uniqueConcat(systemIncludePaths).map(function(path) { @@ -371,7 +373,8 @@ function prepareCompiler(project, product, inputs, outputs, input, output, expli function linkerSupportsWholeArchive(product) { - return Utilities.versionCompare(product.cpp.compilerVersion, "19.0.24215.1") >= 0 + return product.qbs.toolchainType.includes("clang-cl") || + Utilities.versionCompare(product.cpp.compilerVersion, "19.0.24215.1") >= 0 } function handleDiscardProperty(product, flags) { diff --git a/share/qbs/modules/cpp/windows-clang-cl.qbs b/share/qbs/modules/cpp/windows-clang-cl.qbs index 32abb572a..9aa9d7395 100644 --- a/share/qbs/modules/cpp/windows-clang-cl.qbs +++ b/share/qbs/modules/cpp/windows-clang-cl.qbs @@ -85,6 +85,8 @@ MsvcBaseModule { linkerName: "lld-link.exe" linkerPath: FileInfo.joinPaths(toolchainInstallPath, linkerName) + systemIncludeFlag: "/imsvc" + validateFunc: { var baseFunc = base; return function() { diff --git a/share/qbs/modules/cpp/windows-msvc-base.qbs b/share/qbs/modules/cpp/windows-msvc-base.qbs index 1a2c338db..9613800e5 100644 --- a/share/qbs/modules/cpp/windows-msvc-base.qbs +++ b/share/qbs/modules/cpp/windows-msvc-base.qbs @@ -320,12 +320,11 @@ CppModule { outputFileTags: Cpp.assemblerOutputTags(false) outputArtifacts: Cpp.assemblerOutputArtifacts(input) prepare: { - var args = ["/nologo", "/c", - "/Fo" + FileInfo.toWindowsSeparators(output.filePath), - FileInfo.toWindowsSeparators(input.filePath)]; + var args = ["/nologo", "/c", "/Fo" + FileInfo.toWindowsSeparators(output.filePath)]; if (product.cpp.debugInformation) args.push("/Zi"); args = args.concat(Cpp.collectMiscAssemblerArguments(input, "asm")); + args.push(FileInfo.toWindowsSeparators(input.filePath)); var cmd = new Command(product.cpp.assemblerPath, args); cmd.description = "assembling " + input.fileName; cmd.jobPool = "assembler"; diff --git a/share/qbs/modules/dmg/DMGModule.qbs b/share/qbs/modules/dmg/DMGModule.qbs index 59161b1db..27a945033 100644 --- a/share/qbs/modules/dmg/DMGModule.qbs +++ b/share/qbs/modules/dmg/DMGModule.qbs @@ -34,6 +34,7 @@ import qbs.FileInfo import qbs.Host import qbs.ModUtils import qbs.Process +import qbs.Probes import qbs.TextFile import "dmg.js" as Dmg @@ -73,6 +74,12 @@ Module { property string sourceBase + Probes.BinaryProbe { + id: pythonProbe + names: ["python3"] + } + property string pythonExePath: pythonProbe.found ? pythonProbe.filePath : "python3" + readonly property string pythonPath: File.canonicalFilePath(FileInfo.joinPaths(path, "..", "..", "python")) diff --git a/share/qbs/modules/dmg/dmg.js b/share/qbs/modules/dmg/dmg.js index 7d50d95f3..06fe7b906 100644 --- a/share/qbs/modules/dmg/dmg.js +++ b/share/qbs/modules/dmg/dmg.js @@ -135,7 +135,7 @@ function dmgbuildSettings(product, inputs) { } }); - return { + var result = { "title": product.dmg.volumeName, "icon": !product.dmg.badgeVolumeIcon ? volumeIcon : undefined, "badge-icon": product.dmg.badgeVolumeIcon ? volumeIcon : undefined, @@ -154,13 +154,16 @@ function dmgbuildSettings(product, inputs) { }, "format": product.dmg.format, "compression-level": product.dmg.compressionLevel, - "license": { + "contents": contentsArray + }; + if (licenseFileObjects.length >= 0) { + result["license"] = { "default-language": product.dmg.defaultLicenseLocale, "licenses": reduceLicensesForKey(licenseFileObjects, "licenses"), "buttons": reduceLicensesForKey(licenseFileObjects, "buttons") - }, - "contents": contentsArray - }; + }; + } + return result; } function prepareLicense(project, product, inputs, outputs, input, output) { @@ -199,8 +202,10 @@ function prepareDmg(project, product, inputs, outputs, input, output) { cmds.push(cmd); // Create the actual DMG via dmgbuild - cmd = new Command(FileInfo.joinPaths(product.qbs.libexecPath, "dmgbuild"), - [product.dmg.volumeName, + cmd = new Command(product.dmg.pythonExePath, + ["-m", + "dmgbuild", + product.dmg.volumeName, output.filePath, "--no-hidpi", // qbs handles this by itself "--settings", settingsJsonFilePath]); diff --git a/share/qbs/modules/flatbuf/c/flatbuffers-c.qbs b/share/qbs/modules/flatbuf/c/flatbuffers-c.qbs new file mode 100644 index 000000000..9f5b2b70c --- /dev/null +++ b/share/qbs/modules/flatbuf/c/flatbuffers-c.qbs @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2024 Ivan Komissarov (abbapoh@gmail.com) +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +import qbs +import qbs.FileInfo + +import "../flatbuffers.js" as Flatbuf +import "../flatbuffersbase.qbs" as FlatbufBase + +FlatbufBase { + Depends { name: "cpp" } + Depends { name: "flatcc" } + + compilerName: "flatcc" + + _outputDir: FileInfo.joinPaths(product.buildDirectory, "flatbuf", "c") + _searchPaths: flatbuffers.hostBinDirs + + cpp.systemIncludePaths: base.concat([_outputDir]) + + Rule { + inputs: ["flatbuf.input"] + outputFileTags: ["hpp"] + outputArtifacts: [Flatbuf.artifactC(input.flatbuf.c, input, "hpp", "_generated.h")] + + prepare: { + return Flatbuf.doPrepareC(input.flatbuf.c, input); + } + } + + validate: { + Flatbuf.validateCompiler(compilerName, compilerPath); + } +} diff --git a/share/qbs/modules/flatbuf/cpp/flatbuffers-cpp.qbs b/share/qbs/modules/flatbuf/cpp/flatbuffers-cpp.qbs new file mode 100644 index 000000000..4614d4949 --- /dev/null +++ b/share/qbs/modules/flatbuf/cpp/flatbuffers-cpp.qbs @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2024 Ivan Komissarov (abbapoh@gmail.com) +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +import qbs +import qbs.FileInfo + +import "../flatbuffers.js" as Flatbuf +import "../flatbuffersbase.qbs" as FlatbufBase + +FlatbufBase { + Depends { name: "cpp" } + Depends { name: "flatbuffers" } + + property string filenameExtension: "h" + property string filenameSuffix: "_generated" + property string includePrefix // TODO: test + property bool keepPrefix: false + + _outputDir: FileInfo.joinPaths(product.buildDirectory, "flatbuf", "cpp") + _searchPaths: flatbuffers.hostBinDirs + + cpp.cxxLanguageVersion: "c++11" + cpp.systemIncludePaths: base.concat([_outputDir]) + + Rule { + inputs: ["flatbuf.input"] + outputFileTags: ["hpp"] + outputArtifacts: { + var module = input.flatbuf.cpp; + var fullSuffix = module.filenameSuffix + "." + module.filenameExtension; + return [ Flatbuf.artifact(module, input, "hpp", fullSuffix) ]; + } + + prepare: { + return Flatbuf.doPrepareCpp(input.flatbuf.cpp, input, output); + } + } + + validate: { + Flatbuf.validateCompiler(compilerName, compilerPath); + } +} diff --git a/share/qbs/modules/flatbuf/flatbuffers.js b/share/qbs/modules/flatbuf/flatbuffers.js new file mode 100644 index 000000000..24fd91168 --- /dev/null +++ b/share/qbs/modules/flatbuf/flatbuffers.js @@ -0,0 +1,126 @@ +/**************************************************************************** +** +** Copyright (C) 2024 Ivan Komissarov (abbapoh@gmail.com) +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +var File = require("qbs.File"); + +function validateCompiler(compilerName, compilerPath) { + if (!File.exists(compilerPath)) { + throw "Can't find '" + compilerName + "' binary. Please set the compilerPath property or " + + "make sure the compiler is found in PATH"; + } +} + +function getOutputDir(module, input) { + var outputDir = module._outputDir; + if (!module.keepPrefix) + return outputDir; + var importPaths = module.importPaths; + if (importPaths !== undefined && importPaths.length !== 0) { + var canonicalInput = File.canonicalFilePath(FileInfo.path(input.filePath)); + for (var i = 0; i < importPaths.length; ++i) { + var path = File.canonicalFilePath(importPaths[i]); + + if (canonicalInput.startsWith(path)) { + return outputDir + "/" + FileInfo.relativePath(path, canonicalInput); + } + } + } + return outputDir; +} + +function artifactC(module, input, tag, suffix) { + var outputDir = module._outputDir; + return { + fileTags: [tag], + filePath: outputDir + "/" + FileInfo.baseName(input.fileName) + suffix, + cpp: { warningLevel: "none"} + }; +} + +function doPrepareC(module, input) +{ + var args = []; + args.push("-a") // write all + args.push("-o", input.flatbuf.c._outputDir) // output dir + + var importPaths = module.importPaths; + importPaths.forEach(function(path) { + args.push("-I", path); + }); + + args.push(input.filePath); + + var cmd = new Command(module.compilerPath, args); + cmd.workingDirectory = FileInfo.path(module._outputDir) + cmd.highlight = "codegen"; + cmd.description = "generating C files for " + input.fileName; + return [cmd]; +} + +function artifact(module, input, tag, suffix) { + var outputDir = getOutputDir(module, input); + return { + fileTags: [tag], + filePath: outputDir + "/" + FileInfo.baseName(input.fileName) + suffix, + cpp: { warningLevel: "none" } + }; +} + +function doPrepareCpp(module, input, output) +{ + var outputDir = FileInfo.path(output.filePath); + var result = []; + + var args = []; + args.push("--cpp") + + var importPaths = module.importPaths; + importPaths.forEach(function(path) { + args.push("-I", path); + }); + + args.push("--filename-ext", module.filenameExtension); + args.push("--filename-suffix", module.filenameSuffix); + + if (module.includePrefix) + args.push("--include-prefix", module.includePrefix); + + if (module.keepPrefix) + args.push("--keep-prefix"); + + args.push(input.filePath); + var cmd = new Command(input.flatbuf.cpp.compilerPath, args); + cmd.workingDirectory = outputDir; + cmd.highlight = "codegen"; + cmd.description = "generating C++ files for " + input.fileName; + result.push(cmd); + + return result; +} diff --git a/share/qbs/modules/flatbuf/flatbuffersbase.qbs b/share/qbs/modules/flatbuf/flatbuffersbase.qbs new file mode 100644 index 000000000..98eb2f344 --- /dev/null +++ b/share/qbs/modules/flatbuf/flatbuffersbase.qbs @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2024 Ivan Komissarov (abbapoh@gmail.com) +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +import qbs +import qbs.File +import qbs.FileInfo +import qbs.Probes + +import "flatbuffers.js" as HelperFunctions + +Module { + property string compilerName: "flatc" + property string compilerPath: compilerProbe.filePath + + property pathList importPaths: [] + + property string _outputDir: FileInfo.joinPaths(product.buildDirectory, "flatbuf") + + property stringList _searchPaths + + FileTagger { + patterns: ["*.fbs"] + fileTags: ["flatbuf.input"]; + } + + Probes.BinaryProbe { + id: compilerProbe + names: [compilerName] + searchPaths: _searchPaths + } +} diff --git a/share/qbs/modules/java/utils.js b/share/qbs/modules/java/utils.js index 9ee5932dc..a59b8d41d 100644 --- a/share/qbs/modules/java/utils.js +++ b/share/qbs/modules/java/utils.js @@ -99,16 +99,44 @@ function findJdkPath(hostOS, arch, environmentPaths, searchPaths) { try { // We filter by architecture here so that we'll get a compatible JVM for JNI use. var args = []; + var canonicalArch; if (arch) { // Hardcoding apple/macosx/macho here is fine because we know we're on macOS - args.push("--arch", - Utilities.canonicalTargetArchitecture(arch, undefined, - "apple", "macosx", "macho")); + canonicalArch = Utilities.canonicalTargetArchitecture(arch, undefined, "apple", + "macosx", "macho"); + args.push("--arch", canonicalArch); } // --failfast doesn't print the default JVM if nothing matches the filter(s). var status = p.exec("/usr/libexec/java_home", args.concat(["--failfast"])); - return status === 0 ? p.readStdOut().trim() : undefined; + if (status === 0) + return p.readStdOut().trim(); + + // It has been obvserved that java_home fails for any architecture that is passed, + // so try without the filter and look up the JDK architecture manually. + if (!canonicalArch) + return undefined; + + if (p.exec("/usr/libexec/java_home", ["--failfast"]) !== 0) + return undefined; + var jdkPath = p.readStdOut().trim(); + var releaseFile = new TextFile(jdkPath + "/release", TextFile.ReadOnly); + var line; + while ((line = releaseFile.readLine())) { + if (!line.startsWith("OS_ARCH=")) + continue; + var firstQuote = line.indexOf('"'); + if (firstQuote === -1) + break; + var secondQuote = line.indexOf('"', firstQuote + 1); + if (secondQuote === -1) + break; + var archFromFile = line.substring(firstQuote + 1, secondQuote); + if (archFromFile !== canonicalArch) + break; + return jdkPath; + } + return undefined; } finally { p.close(); } diff --git a/share/qbs/modules/protobuf/cpp/protobufcpp.qbs b/share/qbs/modules/protobuf/cpp/protobufcpp.qbs index ae218a0c2..bd4a08557 100644 --- a/share/qbs/modules/protobuf/cpp/protobufcpp.qbs +++ b/share/qbs/modules/protobuf/cpp/protobufcpp.qbs @@ -6,40 +6,29 @@ import "../protobufbase.qbs" as ProtobufBase import "../protobuf.js" as HelperFunctions ProtobufBase { - property string includePath: includeProbe.found ? includeProbe.path : undefined - property string libraryPath: libraryProbe.found ? libraryProbe.path : undefined - property bool useGrpc: false property bool _linkLibraries: true - property stringList _extraGrpcLibs: [] readonly property bool _hasModules: protobuflib.present && (!useGrpc || grpcpp.present) - property string grpcIncludePath: grpcIncludeProbe.found ? grpcIncludeProbe.path : undefined - property string grpcLibraryPath: grpcLibraryProbe.found ? grpcLibraryProbe.path : undefined + property string _cxxLanguageVersion: "c++17" - readonly property string _libraryName: { - var libraryName; - if (libraryProbe.found) { - libraryName = FileInfo.baseName(libraryProbe.fileName); - if (libraryName.startsWith("lib")) - libraryName = libraryName.substring(3); - } - return libraryName; - } + _searchPaths: protobuflib.present ? protobuflib.hostBinDirs : undefined + property stringList _grpcSearchPaths: grpcpp.present ? grpcpp.hostBinDirs : undefined + + cpp.includePaths: outputDir Depends { name: "cpp" } Depends { name: "protobuflib"; condition: _linkLibraries; - required: false; - enableFallback: false + required: false } Depends { - name: "grpcpp"; + name: "grpc++"; + id: grpcpp condition: _linkLibraries && useGrpc; - required: false; - enableFallback: false + required: false } property path grpcPluginPath: grpcPluginProbe.filePath @@ -48,45 +37,10 @@ ProtobufBase { condition: useGrpc id: grpcPluginProbe names: "grpc_cpp_plugin" + searchPaths: _grpcSearchPaths } - cpp.libraryPaths: { - if (!_linkLibraries || _hasModules) - return []; - - var result = []; - if (libraryProbe.found) - result.push(libraryProbe.path); - if (useGrpc && grpcLibraryProbe.found) - result.push(grpcLibraryPath); - return result; - } - cpp.dynamicLibraries: { - if (!_linkLibraries || _hasModules) - return []; - - var result = []; - if (_libraryName) - result.push(_libraryName) - if (qbs.targetOS.includes("unix")) - result.push("pthread"); - if (useGrpc) { - result = result.concat(_extraGrpcLibs); - result.push("grpc++"); - } - return result; - } - cpp.includePaths: { - if (!_linkLibraries || _hasModules) - return [outputDir]; - - var result = [outputDir]; - if (includeProbe.found) - result.push(includePath); - if (useGrpc && grpcIncludeProbe.found) - result.push(grpcIncludePath); - return result; - } + cpp.cxxLanguageVersion: _cxxLanguageVersion Rule { inputs: ["protobuf.input", "protobuf.grpc"] @@ -120,56 +74,16 @@ ProtobufBase { } } - Probes.IncludeProbe { - id: includeProbe - names: "google/protobuf/message.h" - platformSearchPaths: includePath ? [] : base - searchPaths: includePath ? [includePath] : [] - } - - Probes.LibraryProbe { - id: libraryProbe - names: [ - "protobuf", - "protobufd", - ] - platformSearchPaths: libraryPath ? [] : base - searchPaths: libraryPath ? [libraryPath] : [] - } - - Probes.IncludeProbe { - id: grpcIncludeProbe - pathSuffixes: "grpc++" - names: "grpc++.h" - platformSearchPaths: grpcIncludePath ? [] : base - searchPaths: grpcIncludePath ? [grpcIncludePath] : [] - } - - Probes.LibraryProbe { - id: grpcLibraryProbe - names: "grpc++" - platformSearchPaths: grpcLibraryPath ? [] : base - searchPaths: grpcLibraryPath ? [grpcLibraryPath] : [] - } - validate: { HelperFunctions.validateCompiler(compilerName, compilerPath); - if (_hasModules) - return; - - if (_linkLibraries && !includeProbe.found) - throw "Can't find cpp protobuf include files. Please set the includePath property."; - if (_linkLibraries && !libraryProbe.found) - throw "Can't find cpp protobuf library. Please set the libraryPath property."; + if (_linkLibraries && ! _hasModules) { + throw "Can't find cpp protobuf runtime. Make sure .pc files are present"; + } if (useGrpc) { if (!File.exists(grpcPluginPath)) throw "Can't find grpc_cpp_plugin plugin. Please set the grpcPluginPath property."; - if (_linkLibraries && !grpcIncludeProbe.found) - throw "Can't find grpc++ include files. Please set the grpcIncludePath property."; - if (_linkLibraries && !grpcLibraryProbe.found) - throw "Can't find grpc++ library. Please set the grpcLibraryPath property."; } } } diff --git a/share/qbs/modules/protobuf/nanopb/nanopb.qbs b/share/qbs/modules/protobuf/nanopb/nanopb.qbs index 898e230b6..ada7c20bb 100644 --- a/share/qbs/modules/protobuf/nanopb/nanopb.qbs +++ b/share/qbs/modules/protobuf/nanopb/nanopb.qbs @@ -41,6 +41,7 @@ ProtobufBase { result.push(includePath); return result; } + cpp.cxxLanguageVersion: qbs.targetOS.contains("darwin") ? ["c++17"] : ["c++11"] Rule { inputs: ["protobuf.input"] diff --git a/share/qbs/modules/protobuf/protobufbase.qbs b/share/qbs/modules/protobuf/protobufbase.qbs index e302d3758..e32ee30b9 100644 --- a/share/qbs/modules/protobuf/protobufbase.qbs +++ b/share/qbs/modules/protobuf/protobufbase.qbs @@ -6,6 +6,7 @@ import "protobuf.js" as HelperFunctions Module { property string compilerName: "protoc" property string compilerPath: compilerProbe.filePath + property var _searchPaths property pathList importPaths: [] @@ -19,5 +20,6 @@ Module { Probes.BinaryProbe { id: compilerProbe names: [compilerName] + searchPaths: _searchPaths } } diff --git a/share/qbs/modules/qbs/common.qbs b/share/qbs/modules/qbs/common.qbs index 7723c6050..8b31092a9 100644 --- a/share/qbs/modules/qbs/common.qbs +++ b/share/qbs/modules/qbs/common.qbs @@ -102,7 +102,7 @@ Module { property path installSourceBase property string installRoot: project.buildDirectory + "/install-root" property string installDir - property string installPrefix: qbs.targetOS.includes("unix") ? "/usr/local" : "" + property string installPrefix: targetOS.includes("unix") ? "/usr/local" : "" property path sysroot PropertyOptions { diff --git a/share/qbs/modules/xcode/xcode.js b/share/qbs/modules/xcode/xcode.js index 15afddb95..726974579 100644 --- a/share/qbs/modules/xcode/xcode.js +++ b/share/qbs/modules/xcode/xcode.js @@ -112,7 +112,7 @@ function sdkInfoList(sdksPath) { if (!sdks[i].match(/[0-9]+/)) continue; - if (sdks[i].startsWith("DriverKit")) + if (sdks[i].startsWith("DriverKit") || sdks[i].startsWith("AssetRuntime")) continue; var settingsPlist = FileInfo.joinPaths(sdksPath, sdks[i], "SDKSettings.plist"); @@ -205,8 +205,19 @@ function boolFromSdkOrPlatform(varName, sdkProps, platformProps, defaultValue) { function archsSpecsPath(version, targetOS, platformType, platformPath, devicePlatformPath, developerPath) { if (Utilities.versionCompare(version, "13.3") >= 0) { - var baseDir = FileInfo.joinPaths(developerPath, "..", - "PlugIns/XCBSpecifications.ideplugin/Contents/Resources"); + var pluginsDir; + if (Utilities.versionCompare(version, "15.3") >= 0) { + pluginsDir = FileInfo.joinPaths(developerPath, "..", + "SharedFrameworks", "XCBuild.framework", "PlugIns", "XCBBuildService.bundle", + "Contents", "PlugIns"); + } else if (Utilities.versionCompare(version, "14.3") >= 0) { + pluginsDir = FileInfo.joinPaths(developerPath, "Library", "Xcode", "Plug-ins"); + } else { + pluginsDir = FileInfo.joinPaths(developerPath, "..", "PlugIns"); + } + var baseDir = FileInfo.joinPaths(pluginsDir, + "XCBSpecifications.ideplugin", "Contents", "Resources"); + var baseName = targetOS.includes("macos") ? "MacOSX Architectures" : targetOS.includes("ios-simulator") ? "iOS Simulator" : targetOS.includes("ios") ? "iOS Device" diff --git a/share/qbs/modules/xcode/xcode.qbs b/share/qbs/modules/xcode/xcode.qbs index 941b8d395..2c0cd001a 100644 --- a/share/qbs/modules/xcode/xcode.qbs +++ b/share/qbs/modules/xcode/xcode.qbs @@ -9,21 +9,19 @@ import qbs.PropertyList import qbs.Utilities Module { - id: xcodeModule - Probes.XcodeLocationProbe { id: xcodeLocationProbe - condition: !xcodeModule.developerPath + condition: !developerPath } Probes.XcodeProbe { id: xcodeProbe - developerPath: xcodeModule.developerPath - platformType: xcodeModule.platformType - platformPath: xcodeModule.platformPath - devicePlatformPath: xcodeModule.devicePlatformPath - xcodebuildPath: xcodeModule.xcodebuildPath - sdksPath: xcodeModule.sdksPath + developerPath: parent.developerPath + platformType: parent.platformType + platformPath: parent.platformPath + devicePlatformPath: parent.devicePlatformPath + xcodebuildPath: parent.xcodebuildPath + sdksPath: parent.sdksPath } condition: qbs.targetOS.includes("darwin") && @@ -134,6 +132,7 @@ Module { readonly property var _sdkSettings: { if (_availableSdks) { + // see 'sdk' property doc to understand why this loop is needed for (var i in _availableSdks) { if (_availableSdks[i]["Version"] === sdk) return _availableSdks[i]; @@ -141,7 +140,7 @@ Module { return _availableSdks[i]; } - // Latest SDK available for the platform + // Latest SDK available for the platform (default case) if (DarwinTools.applePlatformName(qbs.targetOS, platformType) === sdk) return _latestSdk; } diff --git a/share/share.qbs b/share/share.qbs index 97af30396..75e1e83ba 100644 --- a/share/share.qbs +++ b/share/share.qbs @@ -18,22 +18,13 @@ Product { } Group { - name: "Python executables" - files: ["../src/3rdparty/python/bin/dmgbuild"] - fileTags: ["qbs resources"] - qbs.install: true - qbs.installDir: qbsbuildconfig.libexecInstallDir - qbs.installSourceBase: "../src/3rdparty/python/bin" - } - - Group { name: "Python packages" prefix: "../src/3rdparty/python/**/" files: ["*.py"] fileTags: ["qbs resources"] qbs.install: true qbs.installDir: qbsbuildconfig.resourcesInstallDir + "/share/qbs/python" - qbs.installSourceBase: "../src/3rdparty/python/lib/python2.7/site-packages" + qbs.installSourceBase: "../src/3rdparty/python/lib/python3.9/site-packages" } Group { |