cmVSSolution.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file LICENSE.rst or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include "cmConfigure.h" // IWYU pragma: keep
  5. #include <map>
  6. #include <set>
  7. #include <string>
  8. #include <vector>
  9. #include <cm/memory>
  10. #include <cm/optional>
  11. #include <cm/string_view>
  12. #include "cmVSVersion.h"
  13. namespace cm {
  14. namespace VS {
  15. /** Represent a Visual Studio Solution.
  16. In VS terminology, a "project" corresponds to a CMake "target". */
  17. struct Solution final
  18. {
  19. Solution() = default;
  20. Solution(Solution&&) = default;
  21. Solution& operator=(Solution&&) = default;
  22. /** Represent how a project behaves under one solution config. */
  23. struct ProjectConfig final
  24. {
  25. /** Project-specific config corresponding to this solution config.
  26. This is usually the same as the solution config, but it can map
  27. to another config in some cases. */
  28. std::string Config;
  29. /** Does the project build under this solution config? */
  30. bool Build = false;
  31. /** Does the project deploy under this solution config? */
  32. bool Deploy = false;
  33. };
  34. /** Represent one project in a Solution.
  35. This corresponds to one CMake "target". */
  36. struct Project final
  37. {
  38. /** Project name. This corresponds to the CMake "target" name. */
  39. std::string Name;
  40. /** Project GUID. */
  41. std::string Id;
  42. /** Project type GUID. */
  43. std::string TypeId;
  44. /** Path to the project file on disk.
  45. This is either absolute or relative to the Solution file. */
  46. std::string Path;
  47. /** Project-specific platform. This is usually the same as the
  48. Solution::Platform, but it can be different in some cases. */
  49. std::string Platform;
  50. /** Project-specific configuration corresponding to each solution config.
  51. This vector has the same length as the Solution::Configs vector. */
  52. std::vector<ProjectConfig> Configs;
  53. /** Solution-level dependencies of the project on other projects. */
  54. std::vector<Project const*> BuildDependencies;
  55. // Project type GUIDs used during creation.
  56. static cm::string_view const TypeIdAspNetCore;
  57. static cm::string_view const TypeIdCSharp;
  58. static cm::string_view const TypeIdDatabase;
  59. static cm::string_view const TypeIdDefault;
  60. static cm::string_view const TypeIdDotNetCore;
  61. static cm::string_view const TypeIdFSharp;
  62. static cm::string_view const TypeIdFortran;
  63. static cm::string_view const TypeIdJScript;
  64. static cm::string_view const TypeIdMisc;
  65. static cm::string_view const TypeIdNodeJS;
  66. static cm::string_view const TypeIdPython;
  67. static cm::string_view const TypeIdSqlSrv;
  68. static cm::string_view const TypeIdVDProj;
  69. static cm::string_view const TypeIdVisualBasic;
  70. static cm::string_view const TypeIdWebSite;
  71. static cm::string_view const TypeIdWinAppPkg;
  72. static cm::string_view const TypeIdWiX;
  73. };
  74. /** Represent one folder in a Solution. */
  75. struct Folder final
  76. {
  77. /** Canonical folder name. This includes parent folders separated by
  78. forward slashes. */
  79. std::string Name;
  80. /** Folder GUID. */
  81. std::string Id;
  82. /** List of folders contained inside this folder. */
  83. std::vector<Folder const*> Folders;
  84. /** List of projects contained inside this folder. */
  85. std::vector<Project const*> Projects;
  86. /** Solution-level files contained inside this folder. */
  87. std::set<std::string> Files;
  88. // Folder type GUID.
  89. static cm::string_view const TypeId;
  90. };
  91. /** Represent a group of solution-level Properties. */
  92. struct PropertyGroup final
  93. {
  94. enum class Load
  95. {
  96. Pre,
  97. Post,
  98. };
  99. /** Properties group name. */
  100. std::string Name;
  101. /** Properties group load behavior. */
  102. Load Scope = Load::Post;
  103. /** Property key-value pairs in the group. */
  104. std::map<std::string, std::string> Map;
  105. };
  106. /** Visual Studio major version number, if known. */
  107. cm::optional<Version> VSVersion;
  108. /** Whether this is a VS Express edition, if known. */
  109. cm::optional<VersionExpress> VSExpress;
  110. /** Solution-wide target platform. This is a Windows architecture. */
  111. std::string Platform;
  112. /** Solution-wide build configurations.
  113. This corresponds to CMAKE_CONFIGURATION_TYPES. */
  114. std::vector<std::string> Configs;
  115. /** List of all folders in the solution. */
  116. std::vector<Folder const*> Folders;
  117. /** List of projects in the solution that are not in folders. */
  118. std::vector<Project const*> Projects;
  119. /** List of solution-level property groups. */
  120. std::vector<PropertyGroup const*> PropertyGroups;
  121. /** Name of the default startup project. */
  122. std::string StartupProject;
  123. /** Get all projects in the solution, including all folders. */
  124. std::vector<Project const*> GetAllProjects() const;
  125. // Non-const methods used during creation.
  126. Folder* GetFolder(cm::string_view name);
  127. Project* GetProject(cm::string_view name);
  128. PropertyGroup* GetPropertyGroup(cm::string_view name);
  129. void CanonicalizeOrder();
  130. private:
  131. Solution(Solution const&) = delete;
  132. Solution& operator=(Solution const&) = delete;
  133. // Own and index named entities.
  134. // The string_view keys point at the Name members.
  135. std::map<cm::string_view, std::unique_ptr<Folder>> FolderMap;
  136. std::map<cm::string_view, std::unique_ptr<Project>> ProjectMap;
  137. std::map<cm::string_view, std::unique_ptr<PropertyGroup>> PropertyGroupMap;
  138. };
  139. /** Write the .sln-format representation. */
  140. void WriteSln(std::ostream& sln, Solution const& solution);
  141. /** Write the .slnx-format representation. */
  142. void WriteSlnx(std::ostream& slnx, Solution const& solution);
  143. }
  144. }