cmVSSolution.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 TypeIdCSharp;
  57. static cm::string_view const TypeIdDatabase;
  58. static cm::string_view const TypeIdDefault;
  59. static cm::string_view const TypeIdFSharp;
  60. static cm::string_view const TypeIdFortran;
  61. static cm::string_view const TypeIdPython;
  62. static cm::string_view const TypeIdVDProj;
  63. static cm::string_view const TypeIdVisualBasic;
  64. static cm::string_view const TypeIdWiX;
  65. };
  66. /** Represent one folder in a Solution. */
  67. struct Folder final
  68. {
  69. /** Canonical folder name. This includes parent folders separated by
  70. forward slashes. */
  71. std::string Name;
  72. /** Folder GUID. */
  73. std::string Id;
  74. /** List of folders contained inside this folder. */
  75. std::vector<Folder const*> Folders;
  76. /** List of projects contained inside this folder. */
  77. std::vector<Project const*> Projects;
  78. /** Solution-level files contained inside this folder. */
  79. std::set<std::string> Files;
  80. // Folder type GUID.
  81. static cm::string_view const TypeId;
  82. };
  83. /** Represent a group of solution-level Properties. */
  84. struct PropertyGroup final
  85. {
  86. enum class Load
  87. {
  88. Pre,
  89. Post,
  90. };
  91. /** Properties group name. */
  92. std::string Name;
  93. /** Properties group load behavior. */
  94. Load Scope = Load::Post;
  95. /** Property key-value pairs in the group. */
  96. std::map<std::string, std::string> Map;
  97. };
  98. /** Visual Studio major version number, if known. */
  99. cm::optional<Version> VSVersion;
  100. /** Whether this is a VS Express edition, if known. */
  101. cm::optional<VersionExpress> VSExpress;
  102. /** Solution-wide target platform. This is a Windows architecture. */
  103. std::string Platform;
  104. /** Solution-wide build configurations.
  105. This corresponds to CMAKE_CONFIGURATION_TYPES. */
  106. std::vector<std::string> Configs;
  107. /** List of all folders in the solution. */
  108. std::vector<Folder const*> Folders;
  109. /** List of projects in the solution that are not in folders. */
  110. std::vector<Project const*> Projects;
  111. /** List of solution-level property groups. */
  112. std::vector<PropertyGroup const*> PropertyGroups;
  113. /** Name of the default startup project. */
  114. std::string StartupProject;
  115. /** Get all projects in the solution, including all folders. */
  116. std::vector<Project const*> GetAllProjects() const;
  117. // Non-const methods used during creation.
  118. Folder* GetFolder(cm::string_view name);
  119. Project* GetProject(cm::string_view name);
  120. PropertyGroup* GetPropertyGroup(cm::string_view name);
  121. void CanonicalizeOrder();
  122. private:
  123. Solution(Solution const&) = delete;
  124. Solution& operator=(Solution const&) = delete;
  125. // Own and index named entities.
  126. // The string_view keys point at the Name members.
  127. std::map<cm::string_view, std::unique_ptr<Folder>> FolderMap;
  128. std::map<cm::string_view, std::unique_ptr<Project>> ProjectMap;
  129. std::map<cm::string_view, std::unique_ptr<PropertyGroup>> PropertyGroupMap;
  130. };
  131. /** Write the .sln-format representation. */
  132. void WriteSln(std::ostream& sln, Solution const& solution);
  133. /** Write the .slnx-format representation. */
  134. void WriteSlnx(std::ostream& slnx, Solution const& solution);
  135. }
  136. }