1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #pragma once |
6 | |
7 | #include <QList> |
8 | #include <QMap> |
9 | #include <QSet> |
10 | #include <QString> |
11 | #include <QXmlStreamReader> |
12 | |
13 | #include <memory> |
14 | |
15 | enum class FileType : quint16 { |
16 | Unknown = 0, |
17 | , |
18 | Source, |
19 | Form, |
20 | StateChart, |
21 | Resource, |
22 | QML, |
23 | Project, |
24 | FileTypeSize |
25 | }; |
26 | |
27 | class ProjectFile |
28 | { |
29 | public: |
30 | ProjectFile(const QString &_filePath, const FileType _fileType, bool _generated) |
31 | : fileType(_fileType), |
32 | filePath(_filePath), |
33 | generated(_generated) |
34 | { |
35 | } |
36 | |
37 | FileType getFileType() const; |
38 | const QString &getfilePath() const |
39 | { |
40 | return filePath; |
41 | } |
42 | |
43 | private: |
44 | FileType fileType; |
45 | QString filePath; |
46 | bool generated; |
47 | }; |
48 | |
49 | enum CBPTargetType { |
50 | kExecutable = 0, |
51 | kStaticLibrary = 2, |
52 | kDynamicLibrary = 3, |
53 | kUtility = 64 |
54 | }; |
55 | |
56 | struct CMakeBuildTarget |
57 | { |
58 | public: |
59 | QString title; |
60 | QString output; |
61 | CBPTargetType type = kUtility; |
62 | QString workingDirectory; |
63 | QString sourceDirectory; |
64 | QString makeCommand; |
65 | |
66 | // code model |
67 | QList<QString> includeFiles; |
68 | QStringList compilerOptions; |
69 | QList<QString> srcfiles; |
70 | |
71 | void clear() |
72 | { |
73 | output.clear(); |
74 | makeCommand.clear(); |
75 | workingDirectory.clear(); |
76 | sourceDirectory.clear(); |
77 | title.clear(); |
78 | type = kUtility; |
79 | includeFiles.clear(); |
80 | compilerOptions.clear(); |
81 | srcfiles.clear(); |
82 | } |
83 | }; |
84 | Q_DECLARE_METATYPE(CMakeBuildTarget) |
85 | |
86 | class CMakeCbpParser : public QXmlStreamReader |
87 | { |
88 | public: |
89 | bool parseCbpFile(const QString &fileName, |
90 | const QString &sourceDirectory); |
91 | std::vector<std::unique_ptr<ProjectFile>> && |
92 | getTakeFileList() { return std::move(srcFileList); } |
93 | std::vector<std::unique_ptr<ProjectFile>> && |
94 | getCmakeFileList() { return std::move(cmakeFileList); } |
95 | const QList<CMakeBuildTarget> &getBuildTargets() const; |
96 | QString getProjectName() const; |
97 | QString getCompilerName() const; |
98 | bool hasCMakeFiles(); |
99 | |
100 | private: |
101 | void parseCodeBlocks_project_file(); |
102 | void parseProject(); |
103 | void parseBuild(); |
104 | void parseOption(); |
105 | void parseBuildTarget(); |
106 | void parseBuildTargetOption(); |
107 | void parseMakeCommands(); |
108 | void parseBuildTargetBuild(); |
109 | void parseBuildTargetClean(); |
110 | void parseCompiler(); |
111 | void parseAdd(); |
112 | void parseUnit(); |
113 | void parseUnitOption(); |
114 | void parseUnknownElement(); |
115 | void sortFiles(); |
116 | |
117 | QMap<QString, QStringList> unitTargetMap; |
118 | std::vector<std::unique_ptr<ProjectFile>> srcFileList; |
119 | std::vector<std::unique_ptr<ProjectFile>> cmakeFileList; |
120 | QSet<QString> processedUnits; |
121 | bool parsingCMakeUnit = false; |
122 | |
123 | CMakeBuildTarget buildTarget; |
124 | QList<CMakeBuildTarget> buildTargets; |
125 | QString projectName; |
126 | QString compiler; |
127 | QString sourceDirectory; |
128 | QString buildDirectory; |
129 | QStringList unitTargets; |
130 | }; |
131 | |