cmGlobalVisualStudio71Generator.cxx 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmGlobalVisualStudio71Generator.h"
  4. #include "cmDocumentationEntry.h"
  5. #include "cmGeneratorTarget.h"
  6. #include "cmLocalVisualStudio7Generator.h"
  7. #include "cmMakefile.h"
  8. #include "cmake.h"
  9. cmGlobalVisualStudio71Generator::cmGlobalVisualStudio71Generator(
  10. cmake* cm, const std::string& platformName)
  11. : cmGlobalVisualStudio7Generator(cm, platformName)
  12. {
  13. this->ProjectConfigurationSectionName = "ProjectConfiguration";
  14. }
  15. void cmGlobalVisualStudio71Generator::WriteSLNFile(
  16. std::ostream& fout, cmLocalGenerator* root,
  17. std::vector<cmLocalGenerator*>& generators)
  18. {
  19. std::vector<std::string> configs;
  20. root->GetMakefile()->GetConfigurations(configs);
  21. // Write out the header for a SLN file
  22. this->WriteSLNHeader(fout);
  23. // Collect all targets under this root generator and the transitive
  24. // closure of their dependencies.
  25. TargetDependSet projectTargets;
  26. TargetDependSet originalTargets;
  27. this->GetTargetSets(projectTargets, originalTargets, root, generators);
  28. OrderedTargetDependSet orderedProjectTargets(
  29. projectTargets, this->GetStartupProjectName(root));
  30. // Generate the targets specification to a string. We will put this in
  31. // the actual .sln file later. As a side effect, this method also
  32. // populates the set of folders.
  33. std::ostringstream targetsSlnString;
  34. this->WriteTargetsToSolution(targetsSlnString, root, orderedProjectTargets);
  35. // Generate folder specification.
  36. bool useFolderProperty = this->UseFolderProperty();
  37. if (useFolderProperty) {
  38. this->WriteFolders(fout);
  39. }
  40. // Now write the actual target specification content.
  41. fout << targetsSlnString.str();
  42. // Write out the configurations information for the solution
  43. fout << "Global\n";
  44. // Write out the configurations for the solution
  45. this->WriteSolutionConfigurations(fout, configs);
  46. fout << "\tGlobalSection(" << this->ProjectConfigurationSectionName
  47. << ") = postSolution\n";
  48. // Write out the configurations for all the targets in the project
  49. this->WriteTargetConfigurations(fout, configs, orderedProjectTargets);
  50. fout << "\tEndGlobalSection\n";
  51. if (useFolderProperty) {
  52. // Write out project folders
  53. fout << "\tGlobalSection(NestedProjects) = preSolution\n";
  54. this->WriteFoldersContent(fout);
  55. fout << "\tEndGlobalSection\n";
  56. }
  57. // Write out global sections
  58. this->WriteSLNGlobalSections(fout, root);
  59. // Write the footer for the SLN file
  60. this->WriteSLNFooter(fout);
  61. }
  62. void cmGlobalVisualStudio71Generator::WriteSolutionConfigurations(
  63. std::ostream& fout, std::vector<std::string> const& configs)
  64. {
  65. fout << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
  66. for (std::string const& i : configs) {
  67. fout << "\t\t" << i << " = " << i << "\n";
  68. }
  69. fout << "\tEndGlobalSection\n";
  70. }
  71. // Write a dsp file into the SLN file,
  72. // Note, that dependencies from executables to
  73. // the libraries it uses are also done here
  74. void cmGlobalVisualStudio71Generator::WriteProject(std::ostream& fout,
  75. const std::string& dspname,
  76. const char* dir,
  77. cmGeneratorTarget const* t)
  78. {
  79. // check to see if this is a fortran build
  80. const char* ext = ".vcproj";
  81. const char* project =
  82. "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"";
  83. if (this->TargetIsFortranOnly(t)) {
  84. ext = ".vfproj";
  85. project = "Project(\"{6989167D-11E4-40FE-8C1A-2192A86A7E90}\") = \"";
  86. }
  87. if (this->TargetIsCSharpOnly(t)) {
  88. ext = ".csproj";
  89. project = "Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"";
  90. }
  91. const char* targetExt = t->GetProperty("GENERATOR_FILE_NAME_EXT");
  92. if (targetExt) {
  93. ext = targetExt;
  94. }
  95. std::string guid = this->GetGUID(dspname);
  96. fout << project << dspname << "\", \"" << this->ConvertToSolutionPath(dir)
  97. << (dir[0] ? "\\" : "") << dspname << ext << "\", \"{" << guid
  98. << "}\"\n";
  99. fout << "\tProjectSection(ProjectDependencies) = postProject\n";
  100. this->WriteProjectDepends(fout, dspname, dir, t);
  101. fout << "\tEndProjectSection\n";
  102. fout << "EndProject\n";
  103. UtilityDependsMap::iterator ui = this->UtilityDepends.find(t);
  104. if (ui != this->UtilityDepends.end()) {
  105. const char* uname = ui->second.c_str();
  106. /* clang-format off */
  107. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
  108. << uname << "\", \""
  109. << this->ConvertToSolutionPath(dir) << (dir[0]? "\\":"")
  110. << uname << ".vcproj" << "\", \"{"
  111. << this->GetGUID(uname) << "}\"\n"
  112. << "\tProjectSection(ProjectDependencies) = postProject\n"
  113. << "\t\t{" << guid << "} = {" << guid << "}\n"
  114. << "\tEndProjectSection\n"
  115. << "EndProject\n";
  116. /* clang-format on */
  117. }
  118. }
  119. // Write a dsp file into the SLN file,
  120. // Note, that dependencies from executables to
  121. // the libraries it uses are also done here
  122. void cmGlobalVisualStudio71Generator::WriteProjectDepends(
  123. std::ostream& fout, const std::string&, const char*,
  124. cmGeneratorTarget const* target)
  125. {
  126. VSDependSet const& depends = this->VSTargetDepends[target];
  127. for (std::string const& name : depends) {
  128. std::string guid = this->GetGUID(name);
  129. if (guid.empty()) {
  130. std::string m = "Target: ";
  131. m += target->GetName();
  132. m += " depends on unknown target: ";
  133. m += name;
  134. cmSystemTools::Error(m.c_str());
  135. }
  136. fout << "\t\t{" << guid << "} = {" << guid << "}\n";
  137. }
  138. }
  139. // Write a dsp file into the SLN file, Note, that dependencies from
  140. // executables to the libraries it uses are also done here
  141. void cmGlobalVisualStudio71Generator::WriteExternalProject(
  142. std::ostream& fout, const std::string& name, const char* location,
  143. const char* typeGuid, const std::set<std::string>& depends)
  144. {
  145. fout << "Project(\"{"
  146. << (typeGuid ? typeGuid : this->ExternalProjectType(location))
  147. << "}\") = \"" << name << "\", \""
  148. << this->ConvertToSolutionPath(location) << "\", \"{"
  149. << this->GetGUID(name) << "}\"\n";
  150. // write out the dependencies here VS 7.1 includes dependencies with the
  151. // project instead of in the global section
  152. if (!depends.empty()) {
  153. fout << "\tProjectSection(ProjectDependencies) = postProject\n";
  154. for (std::string const& it : depends) {
  155. if (!it.empty()) {
  156. fout << "\t\t{" << this->GetGUID(it) << "} = {" << this->GetGUID(it)
  157. << "}\n";
  158. }
  159. }
  160. fout << "\tEndProjectSection\n";
  161. }
  162. fout << "EndProject\n";
  163. }
  164. // Write a dsp file into the SLN file, Note, that dependencies from
  165. // executables to the libraries it uses are also done here
  166. void cmGlobalVisualStudio71Generator::WriteProjectConfigurations(
  167. std::ostream& fout, const std::string& name, cmGeneratorTarget const& target,
  168. std::vector<std::string> const& configs,
  169. const std::set<std::string>& configsPartOfDefaultBuild,
  170. std::string const& platformMapping)
  171. {
  172. const std::string& platformName =
  173. !platformMapping.empty() ? platformMapping : this->GetPlatformName();
  174. std::string guid = this->GetGUID(name);
  175. for (std::string const& i : configs) {
  176. std::vector<std::string> mapConfig;
  177. const char* dstConfig = i.c_str();
  178. if (target.GetProperty("EXTERNAL_MSPROJECT")) {
  179. if (const char* m = target.GetProperty("MAP_IMPORTED_CONFIG_" +
  180. cmSystemTools::UpperCase(i))) {
  181. cmSystemTools::ExpandListArgument(m, mapConfig);
  182. if (!mapConfig.empty()) {
  183. dstConfig = mapConfig[0].c_str();
  184. }
  185. }
  186. }
  187. fout << "\t\t{" << guid << "}." << i << ".ActiveCfg = " << dstConfig << "|"
  188. << platformName << std::endl;
  189. std::set<std::string>::const_iterator ci =
  190. configsPartOfDefaultBuild.find(i);
  191. if (!(ci == configsPartOfDefaultBuild.end())) {
  192. fout << "\t\t{" << guid << "}." << i << ".Build.0 = " << dstConfig << "|"
  193. << platformName << std::endl;
  194. }
  195. }
  196. }
  197. // output standard header for dsw file
  198. void cmGlobalVisualStudio71Generator::WriteSLNHeader(std::ostream& fout)
  199. {
  200. fout << "Microsoft Visual Studio Solution File, Format Version 8.00\n";
  201. }