cmGlobalVisualStudio71Generator.cxx 11 KB

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