cmVSSolution.h 5.2 KB

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