cmGlobalVisualStudio71Generator.cxx 11 KB

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