cmGlobalVisualStudio71Generator.cxx 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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 "windows.h" // this must be first to define GetCurrentDirectory
  4. #include "cmGlobalVisualStudio71Generator.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. this->Version = VS71;
  15. }
  16. std::string cmGlobalVisualStudio71Generator::GetUserMacrosDirectory()
  17. {
  18. // Macros not supported on Visual Studio 7.1 and earlier because
  19. // they do not appear to work *during* a build when called by an
  20. // outside agent...
  21. //
  22. return "";
  23. #if 0
  24. //
  25. // The COM result from calling a Visual Studio macro with 7.1 indicates
  26. // that the call succeeds, but the macro does not appear to execute...
  27. //
  28. // So, I am leaving this code here to show how to do it, but have not
  29. // yet figured out what the issue is in terms of why the macro does not
  30. // appear to execute...
  31. //
  32. std::string base;
  33. std::string path;
  34. // base begins with the VisualStudioProjectsLocation reg value...
  35. if (cmSystemTools::ReadRegistryValue(
  36. "HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\7.1;"
  37. "VisualStudioProjectsLocation",
  38. base))
  39. {
  40. cmSystemTools::ConvertToUnixSlashes(base);
  41. // 7.1 macros folder:
  42. path = base + "/VSMacros71";
  43. }
  44. // path is (correctly) still empty if we did not read the base value from
  45. // the Registry value
  46. return path;
  47. #endif
  48. }
  49. std::string cmGlobalVisualStudio71Generator::GetUserMacrosRegKeyBase()
  50. {
  51. // Macros not supported on Visual Studio 7.1 and earlier because
  52. // they do not appear to work *during* a build when called by an
  53. // outside agent...
  54. //
  55. return "";
  56. #if 0
  57. return "Software\\Microsoft\\VisualStudio\\7.1\\vsmacros";
  58. #endif
  59. }
  60. void cmGlobalVisualStudio71Generator::WriteSLNFile(
  61. std::ostream& fout, cmLocalGenerator* root,
  62. std::vector<cmLocalGenerator*>& generators)
  63. {
  64. std::vector<std::string> configs;
  65. root->GetMakefile()->GetConfigurations(configs);
  66. // Write out the header for a SLN file
  67. this->WriteSLNHeader(fout);
  68. // Collect all targets under this root generator and the transitive
  69. // closure of their dependencies.
  70. TargetDependSet projectTargets;
  71. TargetDependSet originalTargets;
  72. this->GetTargetSets(projectTargets, originalTargets, root, generators);
  73. OrderedTargetDependSet orderedProjectTargets(
  74. projectTargets, this->GetStartupProjectName(root));
  75. // Generate the targets specification to a string. We will put this in
  76. // the actual .sln file later. As a side effect, this method also
  77. // populates the set of folders.
  78. std::ostringstream targetsSlnString;
  79. this->WriteTargetsToSolution(targetsSlnString, root, orderedProjectTargets);
  80. // VS 7 does not support folders specified first.
  81. if (this->GetVersion() <= VS71) {
  82. fout << targetsSlnString.str();
  83. }
  84. // Generate folder specification.
  85. bool useFolderProperty = this->UseFolderProperty();
  86. if (useFolderProperty) {
  87. this->WriteFolders(fout);
  88. }
  89. // Now write the actual target specification content.
  90. if (this->GetVersion() > VS71) {
  91. fout << targetsSlnString.str();
  92. }
  93. // Write out the configurations information for the solution
  94. fout << "Global\n";
  95. // Write out the configurations for the solution
  96. this->WriteSolutionConfigurations(fout, configs);
  97. fout << "\tGlobalSection(" << this->ProjectConfigurationSectionName
  98. << ") = postSolution\n";
  99. // Write out the configurations for all the targets in the project
  100. this->WriteTargetConfigurations(fout, configs, orderedProjectTargets);
  101. fout << "\tEndGlobalSection\n";
  102. if (useFolderProperty) {
  103. // Write out project folders
  104. fout << "\tGlobalSection(NestedProjects) = preSolution\n";
  105. this->WriteFoldersContent(fout);
  106. fout << "\tEndGlobalSection\n";
  107. }
  108. // Write out global sections
  109. this->WriteSLNGlobalSections(fout, root);
  110. // Write the footer for the SLN file
  111. this->WriteSLNFooter(fout);
  112. }
  113. void cmGlobalVisualStudio71Generator::WriteSolutionConfigurations(
  114. std::ostream& fout, std::vector<std::string> const& configs)
  115. {
  116. fout << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
  117. for (std::vector<std::string>::const_iterator i = configs.begin();
  118. i != configs.end(); ++i) {
  119. fout << "\t\t" << *i << " = " << *i << "\n";
  120. }
  121. fout << "\tEndGlobalSection\n";
  122. }
  123. // Write a dsp file into the SLN file,
  124. // Note, that dependencies from executables to
  125. // the libraries it uses are also done here
  126. void cmGlobalVisualStudio71Generator::WriteProject(std::ostream& fout,
  127. const std::string& dspname,
  128. const char* dir,
  129. cmGeneratorTarget const* t)
  130. {
  131. // check to see if this is a fortran build
  132. const char* ext = ".vcproj";
  133. const char* project =
  134. "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"";
  135. if (this->TargetIsFortranOnly(t)) {
  136. ext = ".vfproj";
  137. project = "Project(\"{6989167D-11E4-40FE-8C1A-2192A86A7E90}\") = \"";
  138. }
  139. if (this->TargetIsCSharpOnly(t)) {
  140. ext = ".csproj";
  141. project = "Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"";
  142. }
  143. const char* targetExt = t->GetProperty("GENERATOR_FILE_NAME_EXT");
  144. if (targetExt) {
  145. ext = targetExt;
  146. }
  147. std::string guid = this->GetGUID(dspname);
  148. fout << project << dspname << "\", \"" << this->ConvertToSolutionPath(dir)
  149. << (dir[0] ? "\\" : "") << dspname << ext << "\", \"{" << guid
  150. << "}\"\n";
  151. fout << "\tProjectSection(ProjectDependencies) = postProject\n";
  152. this->WriteProjectDepends(fout, dspname, dir, t);
  153. fout << "\tEndProjectSection\n";
  154. fout << "EndProject\n";
  155. UtilityDependsMap::iterator ui = this->UtilityDepends.find(t);
  156. if (ui != this->UtilityDepends.end()) {
  157. const char* uname = ui->second.c_str();
  158. /* clang-format off */
  159. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
  160. << uname << "\", \""
  161. << this->ConvertToSolutionPath(dir) << (dir[0]? "\\":"")
  162. << uname << ".vcproj" << "\", \"{"
  163. << this->GetGUID(uname) << "}\"\n"
  164. << "\tProjectSection(ProjectDependencies) = postProject\n"
  165. << "\t\t{" << guid << "} = {" << guid << "}\n"
  166. << "\tEndProjectSection\n"
  167. << "EndProject\n";
  168. /* clang-format on */
  169. }
  170. }
  171. // Write a dsp file into the SLN file,
  172. // Note, that dependencies from executables to
  173. // the libraries it uses are also done here
  174. void cmGlobalVisualStudio71Generator::WriteProjectDepends(
  175. std::ostream& fout, const std::string&, const char*,
  176. cmGeneratorTarget const* target)
  177. {
  178. VSDependSet const& depends = this->VSTargetDepends[target];
  179. for (VSDependSet::const_iterator di = depends.begin(); di != depends.end();
  180. ++di) {
  181. const char* name = di->c_str();
  182. std::string guid = this->GetGUID(name);
  183. if (guid.empty()) {
  184. std::string m = "Target: ";
  185. m += target->GetName();
  186. m += " depends on unknown target: ";
  187. m += name;
  188. cmSystemTools::Error(m.c_str());
  189. }
  190. fout << "\t\t{" << guid << "} = {" << guid << "}\n";
  191. }
  192. }
  193. // Write a dsp file into the SLN file, Note, that dependencies from
  194. // executables to the libraries it uses are also done here
  195. void cmGlobalVisualStudio71Generator::WriteExternalProject(
  196. std::ostream& fout, const std::string& name, const char* location,
  197. const char* typeGuid, const std::set<std::string>& depends)
  198. {
  199. fout << "Project(\"{"
  200. << (typeGuid ? typeGuid : this->ExternalProjectType(location))
  201. << "}\") = \"" << name << "\", \""
  202. << this->ConvertToSolutionPath(location) << "\", \"{"
  203. << this->GetGUID(name) << "}\"\n";
  204. // write out the dependencies here VS 7.1 includes dependencies with the
  205. // project instead of in the global section
  206. if (!depends.empty()) {
  207. fout << "\tProjectSection(ProjectDependencies) = postProject\n";
  208. std::set<std::string>::const_iterator it;
  209. for (it = depends.begin(); it != depends.end(); ++it) {
  210. if (!it->empty()) {
  211. fout << "\t\t{" << this->GetGUID(it->c_str()) << "} = {"
  212. << this->GetGUID(it->c_str()) << "}\n";
  213. }
  214. }
  215. fout << "\tEndProjectSection\n";
  216. }
  217. fout << "EndProject\n";
  218. }
  219. // Write a dsp file into the SLN file, Note, that dependencies from
  220. // executables to the libraries it uses are also done here
  221. void cmGlobalVisualStudio71Generator::WriteProjectConfigurations(
  222. std::ostream& fout, const std::string& name, cmStateEnums::TargetType,
  223. std::vector<std::string> const& configs,
  224. const std::set<std::string>& configsPartOfDefaultBuild,
  225. std::string const& platformMapping)
  226. {
  227. const std::string& platformName =
  228. !platformMapping.empty() ? platformMapping : this->GetPlatformName();
  229. std::string guid = this->GetGUID(name);
  230. for (std::vector<std::string>::const_iterator i = configs.begin();
  231. i != configs.end(); ++i) {
  232. fout << "\t\t{" << guid << "}." << *i << ".ActiveCfg = " << *i << "|"
  233. << platformName << std::endl;
  234. std::set<std::string>::const_iterator ci =
  235. configsPartOfDefaultBuild.find(*i);
  236. if (!(ci == configsPartOfDefaultBuild.end())) {
  237. fout << "\t\t{" << guid << "}." << *i << ".Build.0 = " << *i << "|"
  238. << platformName << std::endl;
  239. }
  240. }
  241. }
  242. // ouput standard header for dsw file
  243. void cmGlobalVisualStudio71Generator::WriteSLNHeader(std::ostream& fout)
  244. {
  245. fout << "Microsoft Visual Studio Solution File, Format Version 8.00\n";
  246. }
  247. void cmGlobalVisualStudio71Generator::GetDocumentation(
  248. cmDocumentationEntry& entry)
  249. {
  250. entry.Name = cmGlobalVisualStudio71Generator::GetActualName();
  251. entry.Brief = "Deprecated. Generates Visual Studio .NET 2003 project files.";
  252. }