cmGlobalVisualStudio10Generator.h 10 KB

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