cmGlobalVisualStudio71Generator.cxx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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, orderedProjectTargets);
  99. bool useFolderProperty = this->UseFolderProperty();
  100. if (useFolderProperty)
  101. {
  102. this->WriteFolders(fout);
  103. }
  104. // Write out the configurations information for the solution
  105. fout << "Global\n";
  106. // Write out the configurations for the solution
  107. this->WriteSolutionConfigurations(fout);
  108. fout << "\tGlobalSection(" << this->ProjectConfigurationSectionName
  109. << ") = postSolution\n";
  110. // Write out the configurations for all the targets in the project
  111. this->WriteTargetConfigurations(fout, root, orderedProjectTargets);
  112. fout << "\tEndGlobalSection\n";
  113. if (useFolderProperty)
  114. {
  115. // Write out project folders
  116. fout << "\tGlobalSection(NestedProjects) = preSolution\n";
  117. this->WriteFoldersContent(fout);
  118. fout << "\tEndGlobalSection\n";
  119. }
  120. // Write the footer for the SLN file
  121. this->WriteSLNFooter(fout);
  122. }
  123. //----------------------------------------------------------------------------
  124. void
  125. cmGlobalVisualStudio71Generator
  126. ::WriteSolutionConfigurations(std::ostream& fout)
  127. {
  128. fout << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
  129. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  130. i != this->Configurations.end(); ++i)
  131. {
  132. fout << "\t\t" << *i << " = " << *i << "\n";
  133. }
  134. fout << "\tEndGlobalSection\n";
  135. }
  136. //----------------------------------------------------------------------------
  137. // Write a dsp file into the SLN file,
  138. // Note, that dependencies from executables to
  139. // the libraries it uses are also done here
  140. void
  141. cmGlobalVisualStudio71Generator::WriteProject(std::ostream& fout,
  142. const char* dspname,
  143. const char* dir,
  144. cmTarget& t)
  145. {
  146. // check to see if this is a fortran build
  147. const char* ext = ".vcproj";
  148. const char* project =
  149. "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"";
  150. if(this->TargetIsFortranOnly(t))
  151. {
  152. ext = ".vfproj";
  153. project = "Project(\"{6989167D-11E4-40FE-8C1A-2192A86A7E90}\") = \"";
  154. }
  155. const char* targetExt = t.GetProperty("GENERATOR_FILE_NAME_EXT");
  156. if(targetExt)
  157. {
  158. ext = targetExt;
  159. }
  160. std::string guid = this->GetGUID(dspname);
  161. fout << project
  162. << dspname << "\", \""
  163. << this->ConvertToSolutionPath(dir)
  164. << "\\" << dspname << ext << "\", \"{" << guid << "}\"\n";
  165. fout << "\tProjectSection(ProjectDependencies) = postProject\n";
  166. this->WriteProjectDepends(fout, dspname, dir, t);
  167. fout << "\tEndProjectSection\n";
  168. fout <<"EndProject\n";
  169. UtilityDependsMap::iterator ui = this->UtilityDepends.find(&t);
  170. if(ui != this->UtilityDepends.end())
  171. {
  172. const char* uname = ui->second.c_str();
  173. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
  174. << uname << "\", \""
  175. << this->ConvertToSolutionPath(dir)
  176. << "\\" << uname << ".vcproj" << "\", \"{"
  177. << this->GetGUID(uname) << "}\"\n"
  178. << "\tProjectSection(ProjectDependencies) = postProject\n"
  179. << "\t\t{" << guid << "} = {" << guid << "}\n"
  180. << "\tEndProjectSection\n"
  181. << "EndProject\n";
  182. }
  183. }
  184. //----------------------------------------------------------------------------
  185. // Write a dsp file into the SLN file,
  186. // Note, that dependencies from executables to
  187. // the libraries it uses are also done here
  188. void
  189. cmGlobalVisualStudio71Generator
  190. ::WriteProjectDepends(std::ostream& fout,
  191. const char*,
  192. const char*, cmTarget& target)
  193. {
  194. VSDependSet const& depends = this->VSTargetDepends[&target];
  195. for(VSDependSet::const_iterator di = depends.begin();
  196. di != depends.end(); ++di)
  197. {
  198. const char* name = di->c_str();
  199. std::string guid = this->GetGUID(name);
  200. if(guid.size() == 0)
  201. {
  202. std::string m = "Target: ";
  203. m += target.GetName();
  204. m += " depends on unknown target: ";
  205. m += name;
  206. cmSystemTools::Error(m.c_str());
  207. }
  208. fout << "\t\t{" << guid << "} = {" << guid << "}\n";
  209. }
  210. }
  211. //----------------------------------------------------------------------------
  212. // Write a dsp file into the SLN file, Note, that dependencies from
  213. // executables to the libraries it uses are also done here
  214. void cmGlobalVisualStudio71Generator
  215. ::WriteExternalProject(std::ostream& fout,
  216. const char* name,
  217. const char* location,
  218. const std::set<cmStdString>& depends)
  219. {
  220. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
  221. << name << "\", \""
  222. << this->ConvertToSolutionPath(location) << "\", \"{"
  223. << this->GetGUID(name)
  224. << "}\"\n";
  225. // write out the dependencies here VS 7.1 includes dependencies with the
  226. // project instead of in the global section
  227. if(!depends.empty())
  228. {
  229. fout << "\tProjectSection(ProjectDependencies) = postProject\n";
  230. std::set<cmStdString>::const_iterator it;
  231. for(it = depends.begin(); it != depends.end(); ++it)
  232. {
  233. if(it->size() > 0)
  234. {
  235. fout << "\t\t{"
  236. << this->GetGUID(it->c_str())
  237. << "} = {"
  238. << this->GetGUID(it->c_str())
  239. << "}\n";
  240. }
  241. }
  242. fout << "\tEndProjectSection\n";
  243. }
  244. fout << "EndProject\n";
  245. }
  246. //----------------------------------------------------------------------------
  247. // Write a dsp file into the SLN file, Note, that dependencies from
  248. // executables to the libraries it uses are also done here
  249. void cmGlobalVisualStudio71Generator
  250. ::WriteProjectConfigurations(std::ostream& fout, const char* name,
  251. bool partOfDefaultBuild)
  252. {
  253. std::string guid = this->GetGUID(name);
  254. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  255. i != this->Configurations.end(); ++i)
  256. {
  257. fout << "\t\t{" << guid << "}." << *i
  258. << ".ActiveCfg = " << *i << "|Win32\n";
  259. if(partOfDefaultBuild)
  260. {
  261. fout << "\t\t{" << guid << "}." << *i
  262. << ".Build.0 = " << *i << "|Win32\n";
  263. }
  264. }
  265. }
  266. //----------------------------------------------------------------------------
  267. // Standard end of dsw file
  268. void cmGlobalVisualStudio71Generator::WriteSLNFooter(std::ostream& fout)
  269. {
  270. fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n"
  271. << "\tEndGlobalSection\n"
  272. << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n"
  273. << "\tEndGlobalSection\n"
  274. << "EndGlobal\n";
  275. }
  276. //----------------------------------------------------------------------------
  277. // ouput standard header for dsw file
  278. void cmGlobalVisualStudio71Generator::WriteSLNHeader(std::ostream& fout)
  279. {
  280. fout << "Microsoft Visual Studio Solution File, Format Version 8.00\n";
  281. }
  282. //----------------------------------------------------------------------------
  283. void cmGlobalVisualStudio71Generator
  284. ::GetDocumentation(cmDocumentationEntry& entry) const
  285. {
  286. entry.Name = this->GetName();
  287. entry.Brief = "Generates Visual Studio .NET 2003 project files.";
  288. entry.Full = "";
  289. }