cmGlobalVisualStudio71Generator.cxx 11 KB

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