cmGlobalVisualStudio71Generator.cxx 11 KB

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