cmGlobalVisualStudio10Generator.h 11 KB

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