cmGlobalVisualStudio10Generator.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. virtual bool IsScanDependenciesSupported() const { return false; }
  113. static std::string GetInstalledNsightTegraVersion();
  114. /** Return the first two components of CMAKE_SYSTEM_VERSION. */
  115. std::string GetApplicationTypeRevision() const;
  116. virtual const char* GetAndroidApplicationTypeRevision() const { return ""; }
  117. cmIDEFlagTable const* GetClFlagTable() const;
  118. cmIDEFlagTable const* GetCSharpFlagTable() const;
  119. cmIDEFlagTable const* GetRcFlagTable() const;
  120. cmIDEFlagTable const* GetLibFlagTable() const;
  121. cmIDEFlagTable const* GetLinkFlagTable() const;
  122. cmIDEFlagTable const* GetCudaFlagTable() const;
  123. cmIDEFlagTable const* GetCudaHostFlagTable() const;
  124. cmIDEFlagTable const* GetMarmasmFlagTable() const;
  125. cmIDEFlagTable const* GetMasmFlagTable() const;
  126. cmIDEFlagTable const* GetNasmFlagTable() const;
  127. bool IsMsBuildRestoreSupported() const;
  128. bool IsBuildInParallelSupported() 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. bool InitializePlatform(cmMakefile* mf) override;
  141. virtual bool InitializePlatformWindows(cmMakefile* mf);
  142. virtual bool VerifyNoGeneratorPlatformVersion(
  143. cmMakefile* mf, cm::optional<std::string> reason = cm::nullopt) const;
  144. virtual bool ProcessGeneratorToolsetField(std::string const& key,
  145. std::string const& value);
  146. virtual std::string SelectWindowsCEToolset() const;
  147. virtual bool SelectWindowsPhoneToolset(std::string& toolset) const;
  148. virtual bool SelectWindowsStoreToolset(std::string& toolset) const;
  149. enum class AuxToolset
  150. {
  151. None,
  152. Default,
  153. PropsExist,
  154. PropsMissing,
  155. PropsIndeterminate
  156. };
  157. virtual AuxToolset FindAuxToolset(std::string& version,
  158. std::string& props) const;
  159. std::string const& GetMSBuildCommand();
  160. cmIDEFlagTable const* LoadFlagTable(std::string const& toolSpecificName,
  161. std::string const& defaultName,
  162. std::string const& table) const;
  163. std::string GeneratorToolset;
  164. std::string GeneratorToolsetVersionProps;
  165. std::string GeneratorToolsetHostArchitecture;
  166. std::string GeneratorToolsetCustomVCTargetsDir;
  167. std::string GeneratorToolsetCuda;
  168. std::string GeneratorToolsetCudaCustomDir;
  169. std::string GeneratorToolsetCudaNvccSubdir;
  170. std::string GeneratorToolsetCudaVSIntegrationSubdir;
  171. std::string DefaultPlatformToolset;
  172. std::string DefaultPlatformToolsetHostArchitecture;
  173. std::string DefaultAndroidToolset;
  174. std::string WindowsTargetPlatformVersion;
  175. std::string SystemName;
  176. std::string SystemVersion;
  177. std::string NsightTegraVersion;
  178. std::string DefaultCLFlagTableName;
  179. std::string DefaultCSharpFlagTableName;
  180. std::string DefaultLibFlagTableName;
  181. std::string DefaultLinkFlagTableName;
  182. std::string DefaultCudaFlagTableName;
  183. std::string DefaultCudaHostFlagTableName;
  184. std::string DefaultMarmasmFlagTableName;
  185. std::string DefaultMasmFlagTableName;
  186. std::string DefaultNasmFlagTableName;
  187. std::string DefaultRCFlagTableName;
  188. bool SupportsUnityBuilds = false;
  189. bool SystemIsWindowsCE = false;
  190. bool SystemIsWindowsPhone = false;
  191. bool SystemIsWindowsStore = false;
  192. bool SystemIsAndroid = false;
  193. bool MSBuildCommandInitialized = false;
  194. private:
  195. struct LongestSourcePath
  196. {
  197. LongestSourcePath() = default;
  198. size_t Length = 0;
  199. cmGeneratorTarget* Target = nullptr;
  200. cmSourceFile const* SourceFile = nullptr;
  201. std::string SourceRel;
  202. };
  203. LongestSourcePath LongestSource;
  204. std::string MSBuildCommand;
  205. std::set<std::string> AndroidExecutableWarnings;
  206. virtual std::string FindMSBuildCommand();
  207. std::string FindDevEnvCommand() override;
  208. std::string GetVSMakeProgram() override { return this->GetMSBuildCommand(); }
  209. std::string GeneratorToolsetVersion;
  210. bool PlatformToolsetNeedsDebugEnum = false;
  211. bool ParseGeneratorToolset(std::string const& ts, cmMakefile* mf);
  212. std::string GetClFlagTableName() const;
  213. std::string GetCSharpFlagTableName() const;
  214. std::string GetRcFlagTableName() const;
  215. std::string GetLibFlagTableName() const;
  216. std::string GetLinkFlagTableName() const;
  217. std::string GetMasmFlagTableName() const;
  218. std::string CanonicalToolsetName(std::string const& toolset) const;
  219. cm::optional<std::string> FindFlagTable(cm::string_view toolsetName,
  220. cm::string_view table) const;
  221. std::string CustomFlagTableDir;
  222. std::string CustomVCTargetsPath;
  223. std::string VCTargetsPath;
  224. bool FindVCTargetsPath(cmMakefile* mf);
  225. bool CudaEnabled = false;
  226. // We do not use the reload macros for VS >= 10.
  227. std::string GetUserMacrosDirectory() override { return ""; }
  228. };