cmGlobalVisualStudio10Generator.h 10 KB

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