cmGlobalVisualStudio10Generator.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. #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. const std::string& makeProgram, const std::string& projectName,
  32. const std::string& projectDir, std::vector<std::string> const& targetNames,
  33. const std::string& config, int jobs, bool verbose,
  34. const cmBuildOptions& buildOptions = cmBuildOptions(),
  35. std::vector<std::string> const& makeOptions =
  36. std::vector<std::string>()) 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(const std::string& 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. const char* GetCustomVCTargetsPath() const;
  56. /** The toolset name for the target platform. */
  57. const char* 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. const char* GetPlatformToolsetHostArchitecture() const;
  63. std::string const& GetPlatformToolsetHostArchitectureString() const;
  64. /** The cuda toolset version. */
  65. const char* GetPlatformToolsetCuda() const;
  66. std::string const& GetPlatformToolsetCudaString() const;
  67. /** The custom cuda install directory */
  68. const char* 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. {
  78. return this->GeneratorToolsetFortran;
  79. }
  80. /** Return whether we need to use No/Debug instead of false/true
  81. for GenerateDebugInformation. */
  82. bool GetPlatformToolsetNeedsDebugEnum() const
  83. {
  84. return this->PlatformToolsetNeedsDebugEnum;
  85. }
  86. /** Return the CMAKE_SYSTEM_NAME. */
  87. std::string const& GetSystemName() const { return this->SystemName; }
  88. /** Return the CMAKE_SYSTEM_VERSION. */
  89. std::string const& GetSystemVersion() const { return this->SystemVersion; }
  90. /** Return the Windows version targeted on VS 2015 and above. */
  91. std::string const& GetWindowsTargetPlatformVersion() const
  92. {
  93. return this->WindowsTargetPlatformVersion;
  94. }
  95. /** Return true if building for WindowsCE */
  96. bool TargetsWindowsCE() const override { return this->SystemIsWindowsCE; }
  97. /** Return true if building for WindowsPhone */
  98. bool TargetsWindowsPhone() const { return this->SystemIsWindowsPhone; }
  99. /** Return true if building for WindowsStore */
  100. bool TargetsWindowsStore() const { return this->SystemIsWindowsStore; }
  101. /** Return true if building for WindowsKernelModeDriver */
  102. bool TargetsWindowsKernelModeDriver() const
  103. {
  104. return this->SystemIsWindowsKernelModeDriver;
  105. }
  106. /** Return true if building for Android */
  107. bool TargetsAndroid() const { return this->SystemIsAndroid; }
  108. const char* GetCMakeCFGIntDir() const override { return "$(Configuration)"; }
  109. /** Generate an <output>.rule file path for a given command output. */
  110. std::string GenerateRuleFile(std::string const& output) const override;
  111. void PathTooLong(cmGeneratorTarget* target, cmSourceFile const* sf,
  112. std::string const& sfRel);
  113. std::string Encoding() override;
  114. const char* GetToolsVersion() const;
  115. virtual cm::optional<std::string> GetVSInstanceVersion() const { return {}; }
  116. bool GetSupportsUnityBuilds() const { return this->SupportsUnityBuilds; }
  117. virtual cm::optional<std::string> FindMSBuildCommandEarly(cmMakefile* mf);
  118. bool FindMakeProgram(cmMakefile* mf) override;
  119. bool IsIPOSupported() const override { return true; }
  120. virtual bool IsStdOutEncodingSupported() const { return false; }
  121. virtual bool IsUtf8EncodingSupported() const { return false; }
  122. virtual bool IsScanDependenciesSupported() const { return false; }
  123. static std::string GetInstalledNsightTegraVersion();
  124. /** Return the first two components of CMAKE_SYSTEM_VERSION. */
  125. std::string GetApplicationTypeRevision() const;
  126. virtual const char* GetAndroidApplicationTypeRevision() const { return ""; }
  127. cmIDEFlagTable const* GetClFlagTable() const;
  128. cmIDEFlagTable const* GetCSharpFlagTable() const;
  129. cmIDEFlagTable const* GetRcFlagTable() const;
  130. cmIDEFlagTable const* GetLibFlagTable() const;
  131. cmIDEFlagTable const* GetLinkFlagTable() const;
  132. cmIDEFlagTable const* GetCudaFlagTable() const;
  133. cmIDEFlagTable const* GetCudaHostFlagTable() const;
  134. cmIDEFlagTable const* GetMarmasmFlagTable() const;
  135. cmIDEFlagTable const* GetMasmFlagTable() const;
  136. cmIDEFlagTable const* GetNasmFlagTable() const;
  137. bool IsMsBuildRestoreSupported() const;
  138. bool IsBuildInParallelSupported() const;
  139. protected:
  140. cmGlobalVisualStudio10Generator(cmake* cm, const std::string& name);
  141. void Generate() override;
  142. virtual bool InitializeSystem(cmMakefile* mf);
  143. virtual bool InitializeWindows(cmMakefile* mf);
  144. virtual bool InitializeWindowsCE(cmMakefile* mf);
  145. virtual bool InitializeWindowsPhone(cmMakefile* mf);
  146. virtual bool InitializeWindowsStore(cmMakefile* mf);
  147. virtual bool InitializeWindowsKernelModeDriver(cmMakefile* mf);
  148. virtual bool InitializeTegraAndroid(cmMakefile* mf);
  149. virtual bool InitializeAndroid(cmMakefile* mf);
  150. bool InitializePlatform(cmMakefile* mf) override;
  151. virtual bool InitializePlatformWindows(cmMakefile* mf);
  152. virtual bool VerifyNoGeneratorPlatformVersion(cmMakefile* mf) const;
  153. virtual bool ProcessGeneratorToolsetField(std::string const& key,
  154. std::string const& value);
  155. virtual std::string SelectWindowsCEToolset() const;
  156. virtual bool SelectWindowsPhoneToolset(std::string& toolset) const;
  157. virtual bool SelectWindowsStoreToolset(std::string& toolset) const;
  158. enum class AuxToolset
  159. {
  160. None,
  161. Default,
  162. PropsExist,
  163. PropsMissing,
  164. PropsIndeterminate
  165. };
  166. virtual AuxToolset FindAuxToolset(std::string& version,
  167. std::string& props) const;
  168. std::string const& GetMSBuildCommand();
  169. cmIDEFlagTable const* LoadFlagTable(std::string const& toolSpecificName,
  170. std::string const& defaultName,
  171. std::string const& table) const;
  172. std::string GeneratorToolset;
  173. std::string GeneratorToolsetVersionProps;
  174. std::string GeneratorToolsetHostArchitecture;
  175. std::string GeneratorToolsetCustomVCTargetsDir;
  176. std::string GeneratorToolsetCuda;
  177. std::string GeneratorToolsetCudaCustomDir;
  178. std::string GeneratorToolsetCudaNvccSubdir;
  179. std::string GeneratorToolsetCudaVSIntegrationSubdir;
  180. cm::optional<std::string> GeneratorToolsetFortran;
  181. std::string DefaultPlatformToolset;
  182. std::string DefaultPlatformToolsetHostArchitecture;
  183. std::string DefaultAndroidToolset;
  184. std::string WindowsTargetPlatformVersion;
  185. std::string SystemName;
  186. std::string SystemVersion;
  187. std::string NsightTegraVersion;
  188. std::string DefaultCLFlagTableName;
  189. std::string DefaultCSharpFlagTableName;
  190. std::string DefaultLibFlagTableName;
  191. std::string DefaultLinkFlagTableName;
  192. std::string DefaultCudaFlagTableName;
  193. std::string DefaultCudaHostFlagTableName;
  194. std::string DefaultMarmasmFlagTableName;
  195. std::string DefaultMasmFlagTableName;
  196. std::string DefaultNasmFlagTableName;
  197. std::string DefaultRCFlagTableName;
  198. bool SupportsUnityBuilds = false;
  199. bool SystemIsWindowsCE = false;
  200. bool SystemIsWindowsPhone = false;
  201. bool SystemIsWindowsStore = false;
  202. bool SystemIsWindowsKernelModeDriver = false;
  203. bool SystemIsAndroid = false;
  204. bool MSBuildCommandInitialized = false;
  205. private:
  206. struct LongestSourcePath
  207. {
  208. LongestSourcePath() = default;
  209. size_t Length = 0;
  210. cmGeneratorTarget* Target = nullptr;
  211. cmSourceFile const* SourceFile = nullptr;
  212. std::string SourceRel;
  213. };
  214. LongestSourcePath LongestSource;
  215. std::string MSBuildCommand;
  216. std::set<std::string> AndroidExecutableWarnings;
  217. virtual std::string FindMSBuildCommand();
  218. std::string FindDevEnvCommand() override;
  219. std::string GetVSMakeProgram() override { return this->GetMSBuildCommand(); }
  220. std::string GeneratorToolsetVersion;
  221. bool PlatformToolsetNeedsDebugEnum = false;
  222. bool ParseGeneratorToolset(std::string const& ts, cmMakefile* mf);
  223. std::string GetClFlagTableName() const;
  224. std::string GetCSharpFlagTableName() const;
  225. std::string GetRcFlagTableName() const;
  226. std::string GetLibFlagTableName() const;
  227. std::string GetLinkFlagTableName() const;
  228. std::string GetMasmFlagTableName() const;
  229. std::string CanonicalToolsetName(std::string const& toolset) const;
  230. cm::optional<std::string> FindFlagTable(cm::string_view toolsetName,
  231. cm::string_view table) const;
  232. std::string CustomFlagTableDir;
  233. std::string CustomVCTargetsPath;
  234. std::string VCTargetsPath;
  235. bool FindVCTargetsPath(cmMakefile* mf);
  236. bool CudaEnabled = false;
  237. // We do not use the reload macros for VS >= 10.
  238. std::string GetUserMacrosDirectory() override { return ""; }
  239. };