1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
11 #include <cm/optional>
12 #include <cm/string_view>
14 #include "cmGlobalVisualStudio8Generator.h"
16 class cmGeneratorTarget;
17 class cmGlobalGeneratorFactory;
18 class cmLocalGenerator;
22 struct cmIDEFlagTable;
24 /** \class cmGlobalVisualStudio10Generator
25 * \brief Write a Unix makefiles.
27 * cmGlobalVisualStudio10Generator manages UNIX build process for a tree
29 class cmGlobalVisualStudio10Generator : public cmGlobalVisualStudio8Generator
32 static std::unique_ptr<cmGlobalGeneratorFactory> NewFactory();
34 bool IsVisualStudioAtLeast10() const override { return true; }
36 bool MatchesGeneratorName(const std::string& name) const override;
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;
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;
51 //! create the correct local generator
52 std::unique_ptr<cmLocalGenerator> CreateLocalGenerator(
53 cmMakefile* mf) override;
56 * Try to determine system information such as shared library
57 * extension, pthreads, byte order etc.
59 void EnableLanguage(std::vector<std::string> const& languages, cmMakefile*,
60 bool optional) override;
62 void AddAndroidExecutableWarning(const std::string& name)
64 this->AndroidExecutableWarnings.insert(name);
67 bool IsCudaEnabled() const { return this->CudaEnabled; }
69 /** Generating for Nsight Tegra VS plugin? */
70 bool IsNsightTegra() const;
71 std::string GetNsightTegraVersion() const;
73 /** The vctargets path for the target platform. */
74 const char* GetCustomVCTargetsPath() const;
76 /** The toolset name for the target platform. */
77 const char* GetPlatformToolset() const;
78 std::string const& GetPlatformToolsetString() const;
80 /** The toolset version props file, if any. */
81 std::string const& GetPlatformToolsetVersionProps() const;
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;
87 /** The cuda toolset version. */
88 const char* GetPlatformToolsetCuda() const;
89 std::string const& GetPlatformToolsetCudaString() const;
91 /** The custom cuda install directory */
92 const char* GetPlatformToolsetCudaCustomDir() const;
93 std::string const& GetPlatformToolsetCudaCustomDirString() const;
95 /** The nvcc subdirectory of a custom cuda install directory */
96 std::string const& GetPlatformToolsetCudaNvccSubdirString() const;
98 /** The visual studio integration subdirectory of a custom cuda install
100 std::string const& GetPlatformToolsetCudaVSIntegrationSubdirString() const;
102 /** Return whether we need to use No/Debug instead of false/true
103 for GenerateDebugInformation. */
104 bool GetPlatformToolsetNeedsDebugEnum() const
106 return this->PlatformToolsetNeedsDebugEnum;
109 /** Return the CMAKE_SYSTEM_NAME. */
110 std::string const& GetSystemName() const { return this->SystemName; }
112 /** Return the CMAKE_SYSTEM_VERSION. */
113 std::string const& GetSystemVersion() const { return this->SystemVersion; }
115 /** Return the Windows version targeted on VS 2015 and above. */
116 std::string const& GetWindowsTargetPlatformVersion() const
118 return this->WindowsTargetPlatformVersion;
121 /** Return true if building for WindowsCE */
122 bool TargetsWindowsCE() const override { return this->SystemIsWindowsCE; }
124 /** Return true if building for WindowsPhone */
125 bool TargetsWindowsPhone() const { return this->SystemIsWindowsPhone; }
127 /** Return true if building for WindowsStore */
128 bool TargetsWindowsStore() const { return this->SystemIsWindowsStore; }
130 /** Return true if building for Android */
131 bool TargetsAndroid() const { return this->SystemIsAndroid; }
133 const char* GetCMakeCFGIntDir() const override { return "$(Configuration)"; }
134 bool Find64BitTools(cmMakefile* mf);
136 /** Generate an <output>.rule file path for a given command output. */
137 std::string GenerateRuleFile(std::string const& output) const override;
139 void PathTooLong(cmGeneratorTarget* target, cmSourceFile const* sf,
140 std::string const& sfRel);
142 std::string Encoding() override;
143 const char* GetToolsVersion() const;
145 virtual cm::optional<std::string> GetVSInstanceVersion() const { return {}; }
147 bool GetSupportsUnityBuilds() const { return this->SupportsUnityBuilds; }
149 virtual cm::optional<std::string> FindMSBuildCommandEarly(cmMakefile* mf);
151 bool FindMakeProgram(cmMakefile* mf) override;
153 bool IsIPOSupported() const override { return true; }
155 virtual bool IsStdOutEncodingSupported() const { return false; }
157 virtual bool IsUtf8EncodingSupported() const { return false; }
159 static std::string GetInstalledNsightTegraVersion();
161 /** Return the first two components of CMAKE_SYSTEM_VERSION. */
162 std::string GetApplicationTypeRevision() const;
164 virtual const char* GetAndroidApplicationTypeRevision() const { return ""; }
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;
176 bool IsMsBuildRestoreSupported() const;
179 cmGlobalVisualStudio10Generator(cmake* cm, const std::string& name,
180 std::string const& platformInGeneratorName);
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);
191 virtual bool ProcessGeneratorToolsetField(std::string const& key,
192 std::string const& value);
194 virtual std::string SelectWindowsCEToolset() const;
195 virtual bool SelectWindowsPhoneToolset(std::string& toolset) const;
196 virtual bool SelectWindowsStoreToolset(std::string& toolset) const;
198 enum class AuxToolset
205 virtual AuxToolset FindAuxToolset(std::string& version,
206 std::string& props) const;
208 std::string const& GetMSBuildCommand();
210 cmIDEFlagTable const* LoadFlagTable(std::string const& toolSpecificName,
211 std::string const& defaultName,
212 std::string const& table) const;
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;
247 friend class Factory;
249 struct LongestSourcePath
258 cmGeneratorTarget* Target;
259 cmSourceFile const* SourceFile;
260 std::string SourceRel;
262 LongestSourcePath LongestSource;
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(); }
270 std::string GeneratorToolsetVersion;
272 bool PlatformToolsetNeedsDebugEnum;
274 bool ParseGeneratorToolset(std::string const& ts, cmMakefile* mf);
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;
284 cm::optional<std::string> FindFlagTable(cm::string_view toolsetName,
285 cm::string_view table) const;
287 std::string CustomFlagTableDir;
289 std::string CustomVCTargetsPath;
290 std::string VCTargetsPath;
291 bool FindVCTargetsPath(cmMakefile* mf);
295 // We do not use the reload macros for VS >= 10.
296 std::string GetUserMacrosDirectory() override { return ""; }