"Fossies" - the Fresh Open Source Software Archive

Member "qt-creator-opensource-src-4.15.1/src/plugins/projectexplorer/toolchain.h" (8 Jun 2021, 8754 Bytes) of package /linux/misc/qt-creator-opensource-src-4.15.1.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "toolchain.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: opensource-src-4.15.0_vs_opensource-src-4.15.1.

    1 /****************************************************************************
    2 **
    3 ** Copyright (C) 2016 The Qt Company Ltd.
    4 ** Contact: https://www.qt.io/licensing/
    5 **
    6 ** This file is part of Qt Creator.
    7 **
    8 ** Commercial License Usage
    9 ** Licensees holding valid commercial Qt licenses may use this file in
   10 ** accordance with the commercial license agreement provided with the
   11 ** Software or, alternatively, in accordance with the terms contained in
   12 ** a written agreement between you and The Qt Company. For licensing terms
   13 ** and conditions see https://www.qt.io/terms-conditions. For further
   14 ** information use the contact form at https://www.qt.io/contact-us.
   15 **
   16 ** GNU General Public License Usage
   17 ** Alternatively, this file may be used under the terms of the GNU
   18 ** General Public License version 3 as published by the Free Software
   19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
   20 ** included in the packaging of this file. Please review the following
   21 ** information to ensure the GNU General Public License requirements will
   22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
   23 **
   24 ****************************************************************************/
   25 
   26 #pragma once
   27 
   28 #include "projectexplorer_export.h"
   29 
   30 #include "abi.h"
   31 #include "headerpath.h"
   32 #include "projectmacro.h"
   33 #include "task.h"
   34 #include "toolchaincache.h"
   35 
   36 #include <utils/cpplanguage_details.h>
   37 #include <utils/environment.h>
   38 #include <utils/fileutils.h>
   39 #include <utils/id.h>
   40 
   41 #include <QObject>
   42 #include <QStringList>
   43 #include <QVariantMap>
   44 
   45 #include <functional>
   46 #include <memory>
   47 
   48 namespace Utils { class OutputLineParser; }
   49 
   50 namespace ProjectExplorer {
   51 
   52 namespace Internal { class ToolChainPrivate; }
   53 
   54 namespace Deprecated {
   55 // Deprecated in 4.3:
   56 namespace Toolchain {
   57 enum Language {
   58     None = 0,
   59     C,
   60     Cxx
   61 };
   62 QString languageId(Language l);
   63 } // namespace Toolchain
   64 } // namespace Deprecated
   65 
   66 class ToolChainConfigWidget;
   67 class ToolChainFactory;
   68 class Kit;
   69 
   70 namespace Internal { class ToolChainSettingsAccessor; }
   71 
   72 class PROJECTEXPLORER_EXPORT ToolChainDescription
   73 {
   74 public:
   75     Utils::FilePath compilerPath;
   76     Utils::Id language;
   77 };
   78 
   79 // --------------------------------------------------------------------------
   80 // ToolChain (documentation inside)
   81 // --------------------------------------------------------------------------
   82 
   83 class PROJECTEXPLORER_EXPORT ToolChain
   84 {
   85 public:
   86     enum Detection {
   87         ManualDetection,
   88         AutoDetection,
   89         AutoDetectionFromSdk,
   90         UninitializedDetection,
   91     };
   92 
   93     using Predicate = std::function<bool(const ToolChain *)>;
   94 
   95     virtual ~ToolChain();
   96 
   97     QString displayName() const;
   98     void setDisplayName(const QString &name);
   99 
  100     bool isAutoDetected() const;
  101     Detection detection() const;
  102 
  103     QByteArray id() const;
  104 
  105     virtual QStringList suggestedMkspecList() const;
  106 
  107     Utils::Id typeId() const;
  108     QString typeDisplayName() const;
  109 
  110     Abi targetAbi() const;
  111     void setTargetAbi(const Abi &abi);
  112 
  113     virtual ProjectExplorer::Abis supportedAbis() const;
  114     virtual QString originalTargetTriple() const { return QString(); }
  115     virtual QStringList extraCodeModelFlags() const { return QStringList(); }
  116     virtual Utils::FilePath installDir() const { return Utils::FilePath(); }
  117 
  118     virtual bool isValid() const;
  119 
  120     virtual Utils::LanguageExtensions languageExtensions(const QStringList &cxxflags) const = 0;
  121     virtual Utils::WarningFlags warningFlags(const QStringList &cflags) const = 0;
  122     virtual QStringList includedFiles(const QStringList &flags, const QString &directory) const;
  123     virtual QString sysRoot() const;
  124 
  125     class MacroInspectionReport
  126     {
  127     public:
  128         Macros macros;
  129         Utils::LanguageVersion languageVersion;
  130     };
  131 
  132     using MacrosCache = std::shared_ptr<Cache<QStringList, ToolChain::MacroInspectionReport, 64>>;
  133     using HeaderPathsCache = std::shared_ptr<Cache<QPair<Utils::Environment, QStringList>, HeaderPaths>>;
  134 
  135     // A MacroInspectionRunner is created in the ui thread and runs in another thread.
  136     using MacroInspectionRunner = std::function<MacroInspectionReport(const QStringList &cxxflags)>;
  137     virtual MacroInspectionRunner createMacroInspectionRunner() const = 0;
  138 
  139     // A BuiltInHeaderPathsRunner is created in the ui thread and runs in another thread.
  140     using BuiltInHeaderPathsRunner = std::function<HeaderPaths(
  141         const QStringList &cxxflags, const QString &sysRoot, const QString &originalTargetTriple)>;
  142     virtual BuiltInHeaderPathsRunner createBuiltInHeaderPathsRunner(const Utils::Environment &env) const = 0;
  143     virtual void addToEnvironment(Utils::Environment &env) const = 0;
  144     virtual Utils::FilePath makeCommand(const Utils::Environment &env) const = 0;
  145 
  146     Utils::Id language() const;
  147 
  148     virtual Utils::FilePath compilerCommand() const; // FIXME: De-virtualize.
  149     void setCompilerCommand(const Utils::FilePath &command);
  150 
  151     virtual QList<Utils::OutputLineParser *> createOutputParsers() const = 0;
  152 
  153     virtual bool operator ==(const ToolChain &) const;
  154 
  155     virtual std::unique_ptr<ToolChainConfigWidget> createConfigurationWidget() = 0;
  156     ToolChain *clone() const;
  157 
  158     // Used by the toolchainmanager to save user-generated tool chains.
  159     // Make sure to call this function when deriving!
  160     virtual QVariantMap toMap() const;
  161     virtual Tasks validateKit(const Kit *k) const;
  162 
  163     virtual bool isJobCountSupported() const { return true; }
  164 
  165     void setLanguage(Utils::Id language);
  166     void setDetection(Detection d);
  167 
  168     static Utils::LanguageVersion cxxLanguageVersion(const QByteArray &cplusplusMacroValue);
  169     static Utils::LanguageVersion languageVersion(const Utils::Id &language, const Macros &macros);
  170 
  171 protected:
  172     explicit ToolChain(Utils::Id typeId);
  173 
  174     void setTypeDisplayName(const QString &typeName);
  175 
  176     void setTargetAbiNoSignal(const Abi &abi);
  177     void setTargetAbiKey(const QString &abiKey);
  178 
  179     void setCompilerCommandKey(const QString &commandKey);
  180 
  181     const MacrosCache &predefinedMacrosCache() const;
  182     const HeaderPathsCache &headerPathsCache() const;
  183 
  184     void toolChainUpdated();
  185 
  186     // Make sure to call this function when deriving!
  187     virtual bool fromMap(const QVariantMap &data);
  188 
  189     static QStringList includedFiles(const QString &option,
  190                                      const QStringList &flags,
  191                                      const QString &directoryPath);
  192 
  193 private:
  194     ToolChain(const ToolChain &) = delete;
  195     ToolChain &operator=(const ToolChain &) = delete;
  196 
  197     const std::unique_ptr<Internal::ToolChainPrivate> d;
  198 
  199     friend class Internal::ToolChainSettingsAccessor;
  200     friend class ToolChainFactory;
  201 };
  202 
  203 class PROJECTEXPLORER_EXPORT ToolChainFactory
  204 {
  205     ToolChainFactory(const ToolChainFactory &) = delete;
  206     ToolChainFactory &operator=(const ToolChainFactory &) = delete;
  207 
  208 public:
  209     ToolChainFactory();
  210     virtual ~ToolChainFactory();
  211 
  212     static const QList<ToolChainFactory *> allToolChainFactories();
  213 
  214     QString displayName() const { return m_displayName; }
  215     Utils::Id supportedToolChainType() const;
  216 
  217     virtual QList<ToolChain *> autoDetect(const QList<ToolChain *> &alreadyKnown);
  218     virtual QList<ToolChain *> detectForImport(const ToolChainDescription &tcd);
  219 
  220     virtual bool canCreate() const;
  221     virtual ToolChain *create();
  222 
  223     ToolChain *restore(const QVariantMap &data);
  224 
  225     static QByteArray idFromMap(const QVariantMap &data);
  226     static Utils::Id typeIdFromMap(const QVariantMap &data);
  227     static void autoDetectionToMap(QVariantMap &data, bool detected);
  228 
  229     static ToolChain *createToolChain(Utils::Id toolChainType);
  230 
  231     QList<Utils::Id> supportedLanguages() const;
  232 
  233     void setUserCreatable(bool userCreatable);
  234 
  235 protected:
  236     void setDisplayName(const QString &name) { m_displayName = name; }
  237     void setSupportedToolChainType(const Utils::Id &supportedToolChainType);
  238     void setSupportedLanguages(const QList<Utils::Id> &supportedLanguages);
  239     void setSupportsAllLanguages(bool supportsAllLanguages);
  240     void setToolchainConstructor(const std::function<ToolChain *()> &constructor);
  241 
  242     class Candidate {
  243     public:
  244         Utils::FilePath compilerPath;
  245         QString compilerVersion;
  246 
  247         bool operator==(const ToolChainFactory::Candidate &other) const {
  248             return compilerPath == other.compilerPath
  249                     && compilerVersion == other.compilerVersion;
  250         }
  251     };
  252 
  253     using Candidates = QVector<Candidate>;
  254 
  255 private:
  256     QString m_displayName;
  257     Utils::Id m_supportedToolChainType;
  258     QList<Utils::Id> m_supportedLanguages;
  259     bool m_supportsAllLanguages = false;
  260     bool m_userCreatable = false;
  261     std::function<ToolChain *()> m_toolchainConstructor;
  262 };
  263 
  264 } // namespace ProjectExplorer