cmGlobalVisualStudio71Generator.cxx 11 KB

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