cmGlobalVisualStudio71Generator.cxx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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 *cmGlobalVisualStudio71Generator::CreateLocalGenerator()
  25. {
  26. cmLocalVisualStudio7Generator *lg =
  27. new cmLocalVisualStudio7Generator(cmLocalVisualStudioGenerator::VS71);
  28. lg->SetExtraFlagTable(this->GetExtraFlagTableVS7());
  29. lg->SetGlobalGenerator(this);
  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. #ifdef CMAKE_ENCODING_UTF8
  85. // Add UTF-8 BOM for .sln file to indicate encoding
  86. const unsigned char utf8_bom[3] = {0xEF,0xBB,0xBF};
  87. fout.write(reinterpret_cast<const char*>(utf8_bom), 3);
  88. #endif
  89. // Write out the header for a SLN file
  90. this->WriteSLNHeader(fout);
  91. // Collect all targets under this root generator and the transitive
  92. // closure of their dependencies.
  93. TargetDependSet projectTargets;
  94. TargetDependSet originalTargets;
  95. this->GetTargetSets(projectTargets, originalTargets, root, generators);
  96. OrderedTargetDependSet orderedProjectTargets(projectTargets);
  97. this->WriteTargetsToSolution(fout, root, orderedProjectTargets);
  98. bool useFolderProperty = this->UseFolderProperty();
  99. if (useFolderProperty)
  100. {
  101. this->WriteFolders(fout);
  102. }
  103. // Write out the configurations information for the solution
  104. fout << "Global\n";
  105. // Write out the configurations for the solution
  106. this->WriteSolutionConfigurations(fout);
  107. fout << "\tGlobalSection(" << this->ProjectConfigurationSectionName
  108. << ") = postSolution\n";
  109. // Write out the configurations for all the targets in the project
  110. this->WriteTargetConfigurations(fout, orderedProjectTargets);
  111. fout << "\tEndGlobalSection\n";
  112. if (useFolderProperty)
  113. {
  114. // Write out project folders
  115. fout << "\tGlobalSection(NestedProjects) = preSolution\n";
  116. this->WriteFoldersContent(fout);
  117. fout << "\tEndGlobalSection\n";
  118. }
  119. // Write out global sections
  120. this->WriteSLNGlobalSections(fout, root);
  121. // Write the footer for the SLN file
  122. this->WriteSLNFooter(fout);
  123. }
  124. //----------------------------------------------------------------------------
  125. void
  126. cmGlobalVisualStudio71Generator
  127. ::WriteSolutionConfigurations(std::ostream& fout)
  128. {
  129. fout << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
  130. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  131. i != this->Configurations.end(); ++i)
  132. {
  133. fout << "\t\t" << *i << " = " << *i << "\n";
  134. }
  135. fout << "\tEndGlobalSection\n";
  136. }
  137. //----------------------------------------------------------------------------
  138. // Write a dsp file into the SLN file,
  139. // Note, that dependencies from executables to
  140. // the libraries it uses are also done here
  141. void
  142. cmGlobalVisualStudio71Generator::WriteProject(std::ostream& fout,
  143. const std::string& dspname,
  144. const char* dir,
  145. cmTarget const& t)
  146. {
  147. // check to see if this is a fortran build
  148. const char* ext = ".vcproj";
  149. const char* project =
  150. "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"";
  151. if(this->TargetIsFortranOnly(t))
  152. {
  153. ext = ".vfproj";
  154. project = "Project(\"{6989167D-11E4-40FE-8C1A-2192A86A7E90}\") = \"";
  155. }
  156. const char* targetExt = t.GetProperty("GENERATOR_FILE_NAME_EXT");
  157. if(targetExt)
  158. {
  159. ext = targetExt;
  160. }
  161. std::string guid = this->GetGUID(dspname);
  162. fout << project
  163. << dspname << "\", \""
  164. << this->ConvertToSolutionPath(dir) << (dir[0]? "\\":"")
  165. << dspname << ext << "\", \"{" << guid << "}\"\n";
  166. fout << "\tProjectSection(ProjectDependencies) = postProject\n";
  167. this->WriteProjectDepends(fout, dspname, dir, t);
  168. fout << "\tEndProjectSection\n";
  169. fout <<"EndProject\n";
  170. UtilityDependsMap::iterator ui = this->UtilityDepends.find(&t);
  171. if(ui != this->UtilityDepends.end())
  172. {
  173. const char* uname = ui->second.c_str();
  174. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
  175. << uname << "\", \""
  176. << this->ConvertToSolutionPath(dir) << (dir[0]? "\\":"")
  177. << uname << ".vcproj" << "\", \"{"
  178. << this->GetGUID(uname) << "}\"\n"
  179. << "\tProjectSection(ProjectDependencies) = postProject\n"
  180. << "\t\t{" << guid << "} = {" << guid << "}\n"
  181. << "\tEndProjectSection\n"
  182. << "EndProject\n";
  183. }
  184. }
  185. //----------------------------------------------------------------------------
  186. // Write a dsp file into the SLN file,
  187. // Note, that dependencies from executables to
  188. // the libraries it uses are also done here
  189. void
  190. cmGlobalVisualStudio71Generator
  191. ::WriteProjectDepends(std::ostream& fout,
  192. const std::string&,
  193. const char*, cmTarget const& target)
  194. {
  195. VSDependSet const& depends = this->VSTargetDepends[&target];
  196. for(VSDependSet::const_iterator di = depends.begin();
  197. di != depends.end(); ++di)
  198. {
  199. const char* name = di->c_str();
  200. std::string guid = this->GetGUID(name);
  201. if(guid.size() == 0)
  202. {
  203. std::string m = "Target: ";
  204. m += target.GetName();
  205. m += " depends on unknown target: ";
  206. m += name;
  207. cmSystemTools::Error(m.c_str());
  208. }
  209. fout << "\t\t{" << guid << "} = {" << guid << "}\n";
  210. }
  211. }
  212. //----------------------------------------------------------------------------
  213. // Write a dsp file into the SLN file, Note, that dependencies from
  214. // executables to the libraries it uses are also done here
  215. void cmGlobalVisualStudio71Generator
  216. ::WriteExternalProject(std::ostream& fout,
  217. const std::string& name,
  218. const char* location,
  219. const char* typeGuid,
  220. const std::set<std::string>& depends)
  221. {
  222. fout << "Project(\"{"
  223. << (typeGuid ? typeGuid : this->ExternalProjectType(location))
  224. << "}\") = \""
  225. << name << "\", \""
  226. << this->ConvertToSolutionPath(location) << "\", \"{"
  227. << this->GetGUID(name)
  228. << "}\"\n";
  229. // write out the dependencies here VS 7.1 includes dependencies with the
  230. // project instead of in the global section
  231. if(!depends.empty())
  232. {
  233. fout << "\tProjectSection(ProjectDependencies) = postProject\n";
  234. std::set<std::string>::const_iterator it;
  235. for(it = depends.begin(); it != depends.end(); ++it)
  236. {
  237. if(it->size() > 0)
  238. {
  239. fout << "\t\t{"
  240. << this->GetGUID(it->c_str())
  241. << "} = {"
  242. << this->GetGUID(it->c_str())
  243. << "}\n";
  244. }
  245. }
  246. fout << "\tEndProjectSection\n";
  247. }
  248. fout << "EndProject\n";
  249. }
  250. //----------------------------------------------------------------------------
  251. // Write a dsp file into the SLN file, Note, that dependencies from
  252. // executables to the libraries it uses are also done here
  253. void cmGlobalVisualStudio71Generator
  254. ::WriteProjectConfigurations(
  255. std::ostream& fout, const std::string& name, cmTarget::TargetType,
  256. const std::set<std::string>& configsPartOfDefaultBuild,
  257. std::string const& platformMapping)
  258. {
  259. const std::string& platformName =
  260. !platformMapping.empty() ? platformMapping : this->GetPlatformName();
  261. std::string guid = this->GetGUID(name);
  262. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  263. i != this->Configurations.end(); ++i)
  264. {
  265. fout << "\t\t{" << guid << "}." << *i
  266. << ".ActiveCfg = " << *i << "|" << platformName << std::endl;
  267. std::set<std::string>::const_iterator
  268. ci = configsPartOfDefaultBuild.find(*i);
  269. if(!(ci == configsPartOfDefaultBuild.end()))
  270. {
  271. fout << "\t\t{" << guid << "}." << *i
  272. << ".Build.0 = " << *i << "|" << platformName << std::endl;
  273. }
  274. }
  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)
  285. {
  286. entry.Name = cmGlobalVisualStudio71Generator::GetActualName();
  287. entry.Brief = "Generates Visual Studio .NET 2003 project files.";
  288. }