4977a845d01e4e30da22fb1404eea7df90c67ed8
[platform/upstream/cmake.git] / Source / cmGlobalVisualStudio10Generator.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 <cstddef>
6 #include <memory>
7 #include <set>
8 #include <string>
9 #include <vector>
10
11 #include <cm/optional>
12 #include <cm/string_view>
13
14 #include "cmGlobalVisualStudio8Generator.h"
15
16 class cmGeneratorTarget;
17 class cmGlobalGeneratorFactory;
18 class cmLocalGenerator;
19 class cmMakefile;
20 class cmSourceFile;
21 class cmake;
22 struct cmIDEFlagTable;
23
24 /** \class cmGlobalVisualStudio10Generator
25  * \brief Write a Unix makefiles.
26  *
27  * cmGlobalVisualStudio10Generator manages UNIX build process for a tree
28  */
29 class cmGlobalVisualStudio10Generator : public cmGlobalVisualStudio8Generator
30 {
31 public:
32   static std::unique_ptr<cmGlobalGeneratorFactory> NewFactory();
33
34   bool IsVisualStudioAtLeast10() const override { return true; }
35
36   bool MatchesGeneratorName(const std::string& name) const override;
37
38   bool SetSystemName(std::string const& s, cmMakefile* mf) override;
39   bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf) override;
40   bool SetGeneratorToolset(std::string const& ts, bool build,
41                            cmMakefile* mf) override;
42
43   std::vector<GeneratedMakeCommand> GenerateBuildCommand(
44     const std::string& makeProgram, const std::string& projectName,
45     const std::string& projectDir, std::vector<std::string> const& targetNames,
46     const std::string& config, int jobs, bool verbose,
47     const cmBuildOptions& buildOptions = cmBuildOptions(),
48     std::vector<std::string> const& makeOptions =
49       std::vector<std::string>()) override;
50
51   //! create the correct local generator
52   std::unique_ptr<cmLocalGenerator> CreateLocalGenerator(
53     cmMakefile* mf) override;
54
55   /**
56    * Try to determine system information such as shared library
57    * extension, pthreads, byte order etc.
58    */
59   void EnableLanguage(std::vector<std::string> const& languages, cmMakefile*,
60                       bool optional) override;
61
62   void AddAndroidExecutableWarning(const std::string& name)
63   {
64     this->AndroidExecutableWarnings.insert(name);
65   }
66
67   bool IsCudaEnabled() const { return this->CudaEnabled; }
68
69   /** Generating for Nsight Tegra VS plugin?  */
70   bool IsNsightTegra() const;
71   std::string GetNsightTegraVersion() const;
72
73   /** The vctargets path for the target platform.  */
74   const char* GetCustomVCTargetsPath() const;
75
76   /** The toolset name for the target platform.  */
77   const char* GetPlatformToolset() const;
78   std::string const& GetPlatformToolsetString() const;
79
80   /** The toolset version props file, if any.  */
81   std::string const& GetPlatformToolsetVersionProps() const;
82
83   /** The toolset host architecture name (e.g. x64 for 64-bit host tools).  */
84   const char* GetPlatformToolsetHostArchitecture() const;
85   std::string const& GetPlatformToolsetHostArchitectureString() const;
86
87   /** The cuda toolset version.  */
88   const char* GetPlatformToolsetCuda() const;
89   std::string const& GetPlatformToolsetCudaString() const;
90
91   /** The custom cuda install directory */
92   const char* GetPlatformToolsetCudaCustomDir() const;
93   std::string const& GetPlatformToolsetCudaCustomDirString() const;
94
95   /** The nvcc subdirectory of a custom cuda install directory */
96   std::string const& GetPlatformToolsetCudaNvccSubdirString() const;
97
98   /** The visual studio integration subdirectory of a custom cuda install
99    * directory */
100   std::string const& GetPlatformToolsetCudaVSIntegrationSubdirString() const;
101
102   /** Return whether we need to use No/Debug instead of false/true
103       for GenerateDebugInformation.  */
104   bool GetPlatformToolsetNeedsDebugEnum() const
105   {
106     return this->PlatformToolsetNeedsDebugEnum;
107   }
108
109   /** Return the CMAKE_SYSTEM_NAME.  */
110   std::string const& GetSystemName() const { return this->SystemName; }
111
112   /** Return the CMAKE_SYSTEM_VERSION.  */
113   std::string const& GetSystemVersion() const { return this->SystemVersion; }
114
115   /** Return the Windows version targeted on VS 2015 and above.  */
116   std::string const& GetWindowsTargetPlatformVersion() const
117   {
118     return this->WindowsTargetPlatformVersion;
119   }
120
121   /** Return true if building for WindowsCE */
122   bool TargetsWindowsCE() const override { return this->SystemIsWindowsCE; }
123
124   /** Return true if building for WindowsPhone */
125   bool TargetsWindowsPhone() const { return this->SystemIsWindowsPhone; }
126
127   /** Return true if building for WindowsStore */
128   bool TargetsWindowsStore() const { return this->SystemIsWindowsStore; }
129
130   /** Return true if building for Android */
131   bool TargetsAndroid() const { return this->SystemIsAndroid; }
132
133   const char* GetCMakeCFGIntDir() const override { return "$(Configuration)"; }
134   bool Find64BitTools(cmMakefile* mf);
135
136   /** Generate an <output>.rule file path for a given command output.  */
137   std::string GenerateRuleFile(std::string const& output) const override;
138
139   void PathTooLong(cmGeneratorTarget* target, cmSourceFile const* sf,
140                    std::string const& sfRel);
141
142   std::string Encoding() override;
143   const char* GetToolsVersion() const;
144
145   virtual cm::optional<std::string> GetVSInstanceVersion() const { return {}; }
146
147   bool GetSupportsUnityBuilds() const { return this->SupportsUnityBuilds; }
148
149   virtual cm::optional<std::string> FindMSBuildCommandEarly(cmMakefile* mf);
150
151   bool FindMakeProgram(cmMakefile* mf) override;
152
153   bool IsIPOSupported() const override { return true; }
154
155   virtual bool IsStdOutEncodingSupported() const { return false; }
156
157   virtual bool IsUtf8EncodingSupported() const { return false; }
158
159   static std::string GetInstalledNsightTegraVersion();
160
161   /** Return the first two components of CMAKE_SYSTEM_VERSION.  */
162   std::string GetApplicationTypeRevision() const;
163
164   virtual const char* GetAndroidApplicationTypeRevision() const { return ""; }
165
166   cmIDEFlagTable const* GetClFlagTable() const;
167   cmIDEFlagTable const* GetCSharpFlagTable() const;
168   cmIDEFlagTable const* GetRcFlagTable() const;
169   cmIDEFlagTable const* GetLibFlagTable() const;
170   cmIDEFlagTable const* GetLinkFlagTable() const;
171   cmIDEFlagTable const* GetCudaFlagTable() const;
172   cmIDEFlagTable const* GetCudaHostFlagTable() const;
173   cmIDEFlagTable const* GetMasmFlagTable() const;
174   cmIDEFlagTable const* GetNasmFlagTable() const;
175
176   bool IsMsBuildRestoreSupported() const;
177
178 protected:
179   cmGlobalVisualStudio10Generator(cmake* cm, const std::string& name,
180                                   std::string const& platformInGeneratorName);
181
182   void Generate() override;
183   virtual bool InitializeSystem(cmMakefile* mf);
184   virtual bool InitializeWindows(cmMakefile* mf);
185   virtual bool InitializeWindowsCE(cmMakefile* mf);
186   virtual bool InitializeWindowsPhone(cmMakefile* mf);
187   virtual bool InitializeWindowsStore(cmMakefile* mf);
188   virtual bool InitializeTegraAndroid(cmMakefile* mf);
189   virtual bool InitializeAndroid(cmMakefile* mf);
190
191   virtual bool ProcessGeneratorToolsetField(std::string const& key,
192                                             std::string const& value);
193
194   virtual std::string SelectWindowsCEToolset() const;
195   virtual bool SelectWindowsPhoneToolset(std::string& toolset) const;
196   virtual bool SelectWindowsStoreToolset(std::string& toolset) const;
197
198   enum class AuxToolset
199   {
200     None,
201     Default,
202     PropsExist,
203     PropsMissing
204   };
205   virtual AuxToolset FindAuxToolset(std::string& version,
206                                     std::string& props) const;
207
208   std::string const& GetMSBuildCommand();
209
210   cmIDEFlagTable const* LoadFlagTable(std::string const& toolSpecificName,
211                                       std::string const& defaultName,
212                                       std::string const& table) const;
213
214   std::string GeneratorToolset;
215   std::string GeneratorToolsetVersionProps;
216   std::string GeneratorToolsetHostArchitecture;
217   std::string GeneratorToolsetCustomVCTargetsDir;
218   std::string GeneratorToolsetCuda;
219   std::string GeneratorToolsetCudaCustomDir;
220   std::string GeneratorToolsetCudaNvccSubdir;
221   std::string GeneratorToolsetCudaVSIntegrationSubdir;
222   std::string DefaultPlatformToolset;
223   std::string DefaultPlatformToolsetHostArchitecture;
224   std::string DefaultAndroidToolset;
225   std::string WindowsTargetPlatformVersion;
226   std::string SystemName;
227   std::string SystemVersion;
228   std::string NsightTegraVersion;
229   std::string DefaultCLFlagTableName;
230   std::string DefaultCSharpFlagTableName;
231   std::string DefaultLibFlagTableName;
232   std::string DefaultLinkFlagTableName;
233   std::string DefaultCudaFlagTableName;
234   std::string DefaultCudaHostFlagTableName;
235   std::string DefaultMasmFlagTableName;
236   std::string DefaultNasmFlagTableName;
237   std::string DefaultRCFlagTableName;
238   bool SupportsUnityBuilds = false;
239   bool SystemIsWindowsCE = false;
240   bool SystemIsWindowsPhone = false;
241   bool SystemIsWindowsStore = false;
242   bool SystemIsAndroid = false;
243   bool MSBuildCommandInitialized = false;
244
245 private:
246   class Factory;
247   friend class Factory;
248
249   struct LongestSourcePath
250   {
251     LongestSourcePath()
252       : Length(0)
253       , Target(0)
254       , SourceFile(0)
255     {
256     }
257     size_t Length;
258     cmGeneratorTarget* Target;
259     cmSourceFile const* SourceFile;
260     std::string SourceRel;
261   };
262   LongestSourcePath LongestSource;
263
264   std::string MSBuildCommand;
265   std::set<std::string> AndroidExecutableWarnings;
266   virtual std::string FindMSBuildCommand();
267   std::string FindDevEnvCommand() override;
268   std::string GetVSMakeProgram() override { return this->GetMSBuildCommand(); }
269
270   std::string GeneratorToolsetVersion;
271
272   bool PlatformToolsetNeedsDebugEnum;
273
274   bool ParseGeneratorToolset(std::string const& ts, cmMakefile* mf);
275
276   std::string GetClFlagTableName() const;
277   std::string GetCSharpFlagTableName() const;
278   std::string GetRcFlagTableName() const;
279   std::string GetLibFlagTableName() const;
280   std::string GetLinkFlagTableName() const;
281   std::string GetMasmFlagTableName() const;
282   std::string CanonicalToolsetName(std::string const& toolset) const;
283
284   cm::optional<std::string> FindFlagTable(cm::string_view toolsetName,
285                                           cm::string_view table) const;
286
287   std::string CustomFlagTableDir;
288
289   std::string CustomVCTargetsPath;
290   std::string VCTargetsPath;
291   bool FindVCTargetsPath(cmMakefile* mf);
292
293   bool CudaEnabled;
294
295   // We do not use the reload macros for VS >= 10.
296   std::string GetUserMacrosDirectory() override { return ""; }
297 };