cmGlobalVisualStudio10Generator.h 10 KB

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