cmGlobalVisualStudio71Generator.cxx 11 KB

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