File indexing completed on 2024-05-19 04:41:20

0001 /*
0002     SPDX-FileCopyrightText: 2019 Daniel Mensinger <daniel@mensinger-ka.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <util/path.h>
0010 
0011 #include <QHash>
0012 #include <QVector>
0013 
0014 #include <memory>
0015 
0016 class QJsonArray;
0017 class QJsonObject;
0018 class MesonTarget;
0019 class MesonTargets;
0020 class MesonTargetSources;
0021 
0022 using MesonSourcePtr = std::shared_ptr<MesonTargetSources>;
0023 using MesonTargetPtr = std::shared_ptr<MesonTarget>;
0024 using MesonTargetsPtr = std::shared_ptr<MesonTargets>;
0025 
0026 class MesonTargetSources
0027 {
0028 public:
0029     explicit MesonTargetSources(const QJsonObject& json, MesonTarget* target);
0030     virtual ~MesonTargetSources();
0031 
0032     QString language() const;
0033     QStringList compiler() const;
0034     QStringList paramerters() const;
0035     KDevelop::Path::List sources() const;
0036     KDevelop::Path::List generatedSources() const;
0037     KDevelop::Path::List allSources() const;
0038 
0039     KDevelop::Path::List includeDirs() const;
0040     QHash<QString, QString> defines() const;
0041     QStringList extraArgs() const;
0042 
0043     MesonTarget* target();
0044 
0045     void fromJSON(const QJsonObject& json);
0046 
0047 private:
0048     QString m_language;
0049     QStringList m_compiler;
0050     QStringList m_paramerters;
0051     KDevelop::Path::List m_sources;
0052     KDevelop::Path::List m_generatedSources;
0053 
0054     KDevelop::Path::List m_includeDirs;
0055     QHash<QString, QString> m_defines;
0056     QStringList m_extraArgs;
0057 
0058     MesonTarget* m_target; // Store a pointer to the parent target
0059 
0060     void splitParamerters();
0061 };
0062 
0063 class MesonTarget
0064 {
0065 public:
0066     explicit MesonTarget(const QJsonObject& json);
0067     virtual ~MesonTarget();
0068 
0069     QString name() const;
0070     QString type() const;
0071     KDevelop::Path definedIn() const;
0072     KDevelop::Path::List filename() const;
0073     bool buildByDefault() const;
0074     bool installed() const;
0075 
0076     QVector<MesonSourcePtr> targetSources();
0077 
0078     void fromJSON(const QJsonObject& json);
0079 
0080 private:
0081     QString m_name;
0082     QString m_type;
0083     KDevelop::Path m_definedIn;
0084     KDevelop::Path::List m_filename;
0085     bool m_buildByDefault;
0086     bool m_installed;
0087 
0088     QVector<MesonSourcePtr> m_targetSources;
0089 };
0090 
0091 class MesonTargets
0092 {
0093 public:
0094     explicit MesonTargets(const QJsonArray& json);
0095     virtual ~MesonTargets();
0096 
0097     QVector<MesonTargetPtr> targets();
0098 
0099     MesonSourcePtr fileSource(KDevelop::Path p);
0100     MesonSourcePtr operator[](KDevelop::Path p);
0101 
0102     void fromJSON(const QJsonArray& json);
0103 
0104 private:
0105     QVector<MesonTargetPtr> m_targets;
0106     QHash<KDevelop::Path, MesonSourcePtr> m_sourceHash;
0107 
0108     void buildHashMap();
0109 };