resolve cyclic dependency with zstd
[platform/upstream/cmake.git] / Source / cmGlobalGhsMultiGenerator.h
1 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2    file Copyright.txt or https://cmake.org/licensing for details.  */
3 #pragma once
4
5 #include <iosfwd>
6 #include <memory>
7 #include <set>
8 #include <string>
9 #include <utility>
10 #include <vector>
11
12 #include "cmBuildOptions.h"
13 #include "cmGlobalGenerator.h"
14 #include "cmGlobalGeneratorFactory.h"
15 #include "cmTargetDepend.h"
16
17 class cmGeneratorTarget;
18 class cmLocalGenerator;
19 class cmMakefile;
20 class cmake;
21 struct cmDocumentationEntry;
22
23 class cmGlobalGhsMultiGenerator : public cmGlobalGenerator
24 {
25 public:
26   // The default filename extension of GHS MULTI's build files.
27   static const char* FILE_EXTENSION;
28
29   cmGlobalGhsMultiGenerator(cmake* cm);
30   ~cmGlobalGhsMultiGenerator() override;
31
32   static std::unique_ptr<cmGlobalGeneratorFactory> NewFactory()
33   {
34     return std::unique_ptr<cmGlobalGeneratorFactory>(
35       new cmGlobalGeneratorSimpleFactory<cmGlobalGhsMultiGenerator>());
36   }
37
38   //! create the correct local generator
39   std::unique_ptr<cmLocalGenerator> CreateLocalGenerator(
40     cmMakefile* mf) override;
41
42   /// @return the name of this generator.
43   static std::string GetActualName() { return "Green Hills MULTI"; }
44
45   //! Get the name for this generator
46   std::string GetName() const override { return GetActualName(); }
47
48   /// Overloaded methods. @see cmGlobalGenerator::GetDocumentation()
49   static void GetDocumentation(cmDocumentationEntry& entry);
50
51   /**
52    * Utilized by the generator factory to determine if this generator
53    * supports toolsets.
54    */
55   static bool SupportsToolset() { return true; }
56
57   /**
58    * Utilized by the generator factory to determine if this generator
59    * supports platforms.
60    */
61   static bool SupportsPlatform() { return true; }
62
63   // Toolset / Platform Support
64   bool SetGeneratorToolset(std::string const& ts, bool build,
65                            cmMakefile* mf) override;
66   bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf) override;
67
68   /**
69    * Try to determine system information such as shared library
70    * extension, pthreads, byte order etc.
71    */
72   void EnableLanguage(std::vector<std::string> const& languages, cmMakefile*,
73                       bool optional) override;
74   /*
75    * Determine what program to use for building the project.
76    */
77   bool FindMakeProgram(cmMakefile* mf) override;
78
79   void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const override;
80
81   // Write the common disclaimer text at the top of each build file.
82   void WriteFileHeader(std::ostream& fout);
83
84 protected:
85   void Generate() override;
86   std::vector<GeneratedMakeCommand> GenerateBuildCommand(
87     const std::string& makeProgram, const std::string& projectName,
88     const std::string& projectDir, std::vector<std::string> const& targetNames,
89     const std::string& config, int jobs, bool verbose,
90     const cmBuildOptions& buildOptions = cmBuildOptions(),
91     std::vector<std::string> const& makeOptions =
92       std::vector<std::string>()) override;
93   void AddExtraIDETargets() override;
94
95 private:
96   void GetToolset(cmMakefile* mf, std::string& tsd, const std::string& ts);
97
98   /* top-level project */
99   void OutputTopLevelProject(cmLocalGenerator* root,
100                              std::vector<cmLocalGenerator*>& generators);
101   void WriteTopLevelProject(std::ostream& fout, cmLocalGenerator* root);
102   void WriteMacros(std::ostream& fout, cmLocalGenerator* root);
103   void WriteHighLevelDirectives(std::ostream& fout, cmLocalGenerator* root);
104   void WriteSubProjects(std::ostream& fout, bool filterPredefined);
105   void WriteTargets(cmLocalGenerator* root);
106   void WriteProjectLine(std::ostream& fout, cmGeneratorTarget const* target,
107                         std::string& rootBinaryDir);
108   void WriteCustomRuleBOD(std::ostream& fout);
109   void WriteCustomTargetBOD(std::ostream& fout);
110   bool AddCheckTarget();
111   void AddAllTarget();
112
113   std::string StampFile;
114   static std::string TrimQuotes(std::string str);
115
116   static const char* DEFAULT_BUILD_PROGRAM;
117   static const char* CHECK_BUILD_SYSTEM_TARGET;
118
119   bool ComputeTargetBuildOrder(cmGeneratorTarget const* tgt,
120                                std::vector<cmGeneratorTarget const*>& build);
121   bool ComputeTargetBuildOrder(std::vector<cmGeneratorTarget const*>& tgt,
122                                std::vector<cmGeneratorTarget const*>& build);
123   bool VisitTarget(std::set<cmGeneratorTarget const*>& temp,
124                    std::set<cmGeneratorTarget const*>& perm,
125                    std::vector<cmGeneratorTarget const*>& order,
126                    cmGeneratorTarget const* ti);
127
128   std::vector<cmGeneratorTarget const*> ProjectTargets;
129
130   // Target sorting
131   class TargetSet : public std::set<cmGeneratorTarget const*>
132   {
133   };
134   class TargetCompare
135   {
136     std::string First;
137
138   public:
139     TargetCompare(std::string first)
140       : First(std::move(first))
141     {
142     }
143     bool operator()(cmGeneratorTarget const* l,
144                     cmGeneratorTarget const* r) const;
145   };
146   class OrderedTargetDependSet;
147 };
148
149 class cmGlobalGhsMultiGenerator::OrderedTargetDependSet
150   : public std::multiset<cmTargetDepend,
151                          cmGlobalGhsMultiGenerator::TargetCompare>
152 {
153   using derived =
154     std::multiset<cmTargetDepend, cmGlobalGhsMultiGenerator::TargetCompare>;
155
156 public:
157   using TargetDependSet = cmGlobalGenerator::TargetDependSet;
158   OrderedTargetDependSet(TargetDependSet const&, std::string const& first);
159 };