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 "cmConfigure.h" // IWYU pragma: keep
6 
7 #include <iosfwd>
8 #include <memory>
9 #include <string>
10 #include <vector>
11 
12 #include "cmLocalVisualStudioGenerator.h"
13 #include "cmVisualStudioGeneratorOptions.h"
14 
15 class cmCustomCommand;
16 class cmGeneratorTarget;
17 class cmGlobalGenerator;
18 class cmLocalVisualStudio7GeneratorFCInfo;
19 class cmLocalVisualStudio7GeneratorInternals;
20 class cmMakefile;
21 class cmSourceFile;
22 class cmSourceGroup;
23 
24 class cmVS7GeneratorOptions : public cmVisualStudioGeneratorOptions
25 {
26 public:
27   cmVS7GeneratorOptions(cmLocalVisualStudioGenerator* lg, Tool tool,
28                         cmVS7FlagTable const* table = nullptr,
29                         cmVS7FlagTable const* extraTable = nullptr)
cmVisualStudioGeneratorOptions(lg,tool,table,extraTable)30     : cmVisualStudioGeneratorOptions(lg, tool, table, extraTable)
31   {
32   }
33   void OutputFlag(std::ostream& fout, int indent, const std::string& tag,
34                   const std::string& content) override;
35 };
36 
37 /** \class cmLocalVisualStudio7Generator
38  * \brief Write Visual Studio .NET project files.
39  *
40  * cmLocalVisualStudio7Generator produces a Visual Studio .NET project
41  * file for each target in its directory.
42  */
43 class cmLocalVisualStudio7Generator : public cmLocalVisualStudioGenerator
44 {
45 public:
46   //! Set cache only and recurse to false by default.
47   cmLocalVisualStudio7Generator(cmGlobalGenerator* gg, cmMakefile* mf);
48 
49   virtual ~cmLocalVisualStudio7Generator();
50 
51   cmLocalVisualStudio7Generator(const cmLocalVisualStudio7Generator&) = delete;
52   const cmLocalVisualStudio7Generator& operator=(
53     const cmLocalVisualStudio7Generator&) = delete;
54 
55   void AddHelperCommands() override;
56 
57   /**
58    * Generate the makefile for this directory.
59    */
60   void Generate() override;
61 
62   enum BuildType
63   {
64     STATIC_LIBRARY,
65     DLL,
66     EXECUTABLE,
67     WIN32_EXECUTABLE,
68     UTILITY
69   };
70 
71   /**
72    * Specify the type of the build: static, dll, or executable.
73    */
74   void SetBuildType(BuildType, const std::string& name);
75 
76   std::string GetTargetDirectory(
77     cmGeneratorTarget const* target) const override;
78   cmSourceFile* CreateVCProjBuildRule();
79   void WriteStampFiles();
80   std::string ComputeLongestObjectDirectory(
81     cmGeneratorTarget const*) const override;
82 
83   virtual void ReadAndStoreExternalGUID(const std::string& name,
84                                         const char* path);
85 
GetSourcesVisited(cmGeneratorTarget const * target)86   std::set<cmSourceFile const*>& GetSourcesVisited(
87     cmGeneratorTarget const* target)
88   {
89     return this->SourcesVisited[target];
90   };
91 
92 protected:
93   virtual void GenerateTarget(cmGeneratorTarget* target);
94 
95 private:
96   using Options = cmVS7GeneratorOptions;
97   using FCInfo = cmLocalVisualStudio7GeneratorFCInfo;
98   std::string GetBuildTypeLinkerFlags(std::string rootLinkerFlags,
99                                       const std::string& configName);
100   void FixGlobalTargets();
101   void WriteVCProjHeader(std::ostream& fout, const std::string& libName,
102                          cmGeneratorTarget* tgt,
103                          std::vector<cmSourceGroup>& sgs);
104   void WriteVCProjFooter(std::ostream& fout, cmGeneratorTarget* target);
105   void WriteVCProjFile(std::ostream& fout, const std::string& libName,
106                        cmGeneratorTarget* tgt);
107   void WriteConfigurations(std::ostream& fout,
108                            std::vector<std::string> const& configs,
109                            const std::string& libName, cmGeneratorTarget* tgt);
110   void WriteConfiguration(std::ostream& fout, const std::string& configName,
111                           const std::string& libName, cmGeneratorTarget* tgt);
112   std::string EscapeForXML(const std::string& s);
113   std::string ConvertToXMLOutputPath(const std::string& path);
114   std::string ConvertToXMLOutputPathSingle(const std::string& path);
115   void OutputTargetRules(std::ostream& fout, const std::string& configName,
116                          cmGeneratorTarget* target,
117                          const std::string& libName);
118   void OutputBuildTool(std::ostream& fout, const std::string& configName,
119                        cmGeneratorTarget* t, const Options& targetOptions);
120   void OutputDeploymentDebuggerTool(std::ostream& fout,
121                                     std::string const& config,
122                                     cmGeneratorTarget* target);
123   void OutputLibraryDirectories(std::ostream& fout,
124                                 std::vector<std::string> const& dirs);
125   void WriteProjectSCC(std::ostream& fout, cmGeneratorTarget* target);
126   void WriteProjectStart(std::ostream& fout, const std::string& libName,
127                          cmGeneratorTarget* tgt,
128                          std::vector<cmSourceGroup>& sgs);
129   void WriteProjectStartFortran(std::ostream& fout, const std::string& libName,
130                                 cmGeneratorTarget* tgt);
131   void WriteVCProjBeginGroup(std::ostream& fout, const char* group,
132                              const char* filter);
133   void WriteVCProjEndGroup(std::ostream& fout);
134 
135   void WriteCustomRule(std::ostream& fout,
136                        std::vector<std::string> const& configs,
137                        const char* source, const cmCustomCommand& command,
138                        FCInfo& fcinfo);
139   void WriteTargetVersionAttribute(std::ostream& fout, cmGeneratorTarget* gt);
140 
141   class AllConfigSources;
142   bool WriteGroup(const cmSourceGroup* sg, cmGeneratorTarget* target,
143                   std::ostream& fout, const std::string& libName,
144                   std::vector<std::string> const& configs,
145                   AllConfigSources const& sources);
146 
147   friend class cmLocalVisualStudio7GeneratorFCInfo;
148   friend class cmLocalVisualStudio7GeneratorInternals;
149 
150   class EventWriter;
151 
152   friend class EventWriter;
153 
154   bool FortranProject;
155   bool WindowsCEProject;
156   std::unique_ptr<cmLocalVisualStudio7GeneratorInternals> Internal;
157 
158   std::map<cmGeneratorTarget const*, std::set<cmSourceFile const*>>
159     SourcesVisited;
160 };
161