cmGlobalVisualStudio10Generator.h 9.6 KB

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