cmVSSolution.h 4.8 KB

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