cmGlobalVisualStudio71Generator.cxx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "windows.h" // this must be first to define GetCurrentDirectory
  14. #include "cmGlobalVisualStudio71Generator.h"
  15. #include "cmLocalVisualStudio7Generator.h"
  16. #include "cmMakefile.h"
  17. #include "cmake.h"
  18. //----------------------------------------------------------------------------
  19. cmGlobalVisualStudio71Generator::cmGlobalVisualStudio71Generator()
  20. {
  21. this->FindMakeProgramFile = "CMakeVS71FindMake.cmake";
  22. this->ProjectConfigurationSectionName = "ProjectConfiguration";
  23. }
  24. //----------------------------------------------------------------------------
  25. ///! Create a local generator appropriate to this Global Generator
  26. cmLocalGenerator *cmGlobalVisualStudio71Generator::CreateLocalGenerator()
  27. {
  28. cmLocalVisualStudio7Generator *lg = new cmLocalVisualStudio7Generator;
  29. lg->SetVersion71();
  30. lg->SetExtraFlagTable(this->GetExtraFlagTableVS7());
  31. lg->SetGlobalGenerator(this);
  32. return lg;
  33. }
  34. //----------------------------------------------------------------------------
  35. void cmGlobalVisualStudio71Generator::AddPlatformDefinitions(cmMakefile* mf)
  36. {
  37. mf->AddDefinition("MSVC71", "1");
  38. }
  39. //----------------------------------------------------------------------------
  40. std::string cmGlobalVisualStudio71Generator::GetUserMacrosDirectory()
  41. {
  42. // Macros not supported on Visual Studio 7.1 and earlier because
  43. // they do not appear to work *during* a build when called by an
  44. // outside agent...
  45. //
  46. return "";
  47. #if 0
  48. //
  49. // The COM result from calling a Visual Studio macro with 7.1 indicates
  50. // that the call succeeds, but the macro does not appear to execute...
  51. //
  52. // So, I am leaving this code here to show how to do it, but have not
  53. // yet figured out what the issue is in terms of why the macro does not
  54. // appear to execute...
  55. //
  56. std::string base;
  57. std::string path;
  58. // base begins with the VisualStudioProjectsLocation reg value...
  59. if (cmSystemTools::ReadRegistryValue(
  60. "HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\7.1;"
  61. "VisualStudioProjectsLocation",
  62. base))
  63. {
  64. cmSystemTools::ConvertToUnixSlashes(base);
  65. // 7.1 macros folder:
  66. path = base + "/VSMacros71";
  67. }
  68. // path is (correctly) still empty if we did not read the base value from
  69. // the Registry value
  70. return path;
  71. #endif
  72. }
  73. //----------------------------------------------------------------------------
  74. std::string cmGlobalVisualStudio71Generator::GetUserMacrosRegKeyBase()
  75. {
  76. // Macros not supported on Visual Studio 7.1 and earlier because
  77. // they do not appear to work *during* a build when called by an
  78. // outside agent...
  79. //
  80. return "";
  81. #if 0
  82. return "Software\\Microsoft\\VisualStudio\\7.1\\vsmacros";
  83. #endif
  84. }
  85. //----------------------------------------------------------------------------
  86. void cmGlobalVisualStudio71Generator
  87. ::WriteSLNFile(std::ostream& fout,
  88. cmLocalGenerator* root,
  89. std::vector<cmLocalGenerator*>& generators)
  90. {
  91. // Write out the header for a SLN file
  92. this->WriteSLNHeader(fout);
  93. // collect the set of targets for this project by
  94. // tracing depends of all targets.
  95. // also collect the set of targets that are explicitly
  96. // in this project.
  97. cmGlobalGenerator::TargetDependSet projectTargets;
  98. cmGlobalGenerator::TargetDependSet originalTargets;
  99. this->GetTargetSets(projectTargets,
  100. originalTargets,
  101. root, generators);
  102. OrderedTargetDependSet orderedProjectTargets(projectTargets);
  103. this->WriteTargetsToSolution(fout, root, orderedProjectTargets);
  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. // Write the footer for the SLN file
  114. this->WriteSLNFooter(fout);
  115. }
  116. //----------------------------------------------------------------------------
  117. void
  118. cmGlobalVisualStudio71Generator
  119. ::WriteSolutionConfigurations(std::ostream& fout)
  120. {
  121. fout << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
  122. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  123. i != this->Configurations.end(); ++i)
  124. {
  125. fout << "\t\t" << *i << " = " << *i << "\n";
  126. }
  127. fout << "\tEndGlobalSection\n";
  128. }
  129. //----------------------------------------------------------------------------
  130. // Write a dsp file into the SLN file,
  131. // Note, that dependencies from executables to
  132. // the libraries it uses are also done here
  133. void
  134. cmGlobalVisualStudio71Generator::WriteProject(std::ostream& fout,
  135. const char* dspname,
  136. const char* dir,
  137. cmTarget& t)
  138. {
  139. // check to see if this is a fortran build
  140. const char* ext = ".vcproj";
  141. const char* project =
  142. "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"";
  143. if(this->TargetIsFortranOnly(t))
  144. {
  145. ext = ".vfproj";
  146. project = "Project(\"{6989167D-11E4-40FE-8C1A-2192A86A7E90}\") = \"";
  147. }
  148. const char* targetExt = t.GetProperty("GENERATOR_FILE_NAME_EXT");
  149. if(targetExt)
  150. {
  151. ext = targetExt;
  152. }
  153. fout << project
  154. << dspname << "\", \""
  155. << this->ConvertToSolutionPath(dir)
  156. << "\\" << dspname << ext << "\", \"{"
  157. << this->GetGUID(dspname) << "}\"\n";
  158. fout << "\tProjectSection(ProjectDependencies) = postProject\n";
  159. this->WriteProjectDepends(fout, dspname, dir, t);
  160. fout << "\tEndProjectSection\n";
  161. fout <<"EndProject\n";
  162. }
  163. //----------------------------------------------------------------------------
  164. // Write a dsp file into the SLN file,
  165. // Note, that dependencies from executables to
  166. // the libraries it uses are also done here
  167. void
  168. cmGlobalVisualStudio71Generator
  169. ::WriteProjectDepends(std::ostream& fout,
  170. const char* dspname,
  171. const char*, cmTarget& target)
  172. {
  173. #if 0
  174. // Create inter-target dependencies in the solution file. For VS
  175. // 7.1 and below we cannot let static libraries depend directly on
  176. // targets to which they "link" because the librarian tool will copy
  177. // the targets into the static library. See
  178. // cmGlobalVisualStudioGenerator::FixUtilityDependsForTarget for a
  179. // work-around. VS 8 and above do not have this problem.
  180. if (!this->VSLinksDependencies() ||
  181. target.GetType() != cmTarget::STATIC_LIBRARY);
  182. #else
  183. if (target.GetType() != cmTarget::STATIC_LIBRARY)
  184. #endif
  185. {
  186. cmTarget::LinkLibraryVectorType::const_iterator j, jend;
  187. j = target.GetLinkLibraries().begin();
  188. jend = target.GetLinkLibraries().end();
  189. for(;j!= jend; ++j)
  190. {
  191. if(j->first != dspname)
  192. {
  193. // is the library part of this SLN ? If so add dependency
  194. // find target anywhere because all depend libraries are
  195. // brought in as well
  196. if(this->FindTarget(0, j->first.c_str()))
  197. {
  198. fout << "\t\t{" << this->GetGUID(j->first.c_str()) << "} = {"
  199. << this->GetGUID(j->first.c_str()) << "}\n";
  200. }
  201. }
  202. }
  203. }
  204. std::set<cmStdString>::const_iterator i, end;
  205. // write utility dependencies.
  206. i = target.GetUtilities().begin();
  207. end = target.GetUtilities().end();
  208. for(;i!= end; ++i)
  209. {
  210. if(*i != dspname)
  211. {
  212. std::string name = this->GetUtilityForTarget(target, i->c_str());
  213. std::string guid = this->GetGUID(name.c_str());
  214. if(guid.size() == 0)
  215. {
  216. std::string m = "Target: ";
  217. m += target.GetName();
  218. m += " depends on unknown target: ";
  219. m += name;
  220. cmSystemTools::Error(m.c_str());
  221. }
  222. fout << "\t\t{" << guid << "} = {" << guid << "}\n";
  223. }
  224. }
  225. }
  226. //----------------------------------------------------------------------------
  227. // Write a dsp file into the SLN file, Note, that dependencies from
  228. // executables to the libraries it uses are also done here
  229. void cmGlobalVisualStudio71Generator
  230. ::WriteExternalProject(std::ostream& fout,
  231. const char* name,
  232. const char* location,
  233. const std::vector<std::string>& depends)
  234. {
  235. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
  236. << name << "\", \""
  237. << this->ConvertToSolutionPath(location) << "\", \"{"
  238. << this->GetGUID(name)
  239. << "}\"\n";
  240. // write out the dependencies here VS 7.1 includes dependencies with the
  241. // project instead of in the global section
  242. if(!depends.empty())
  243. {
  244. fout << "\tProjectSection(ProjectDependencies) = postProject\n";
  245. std::vector<std::string>::const_iterator it;
  246. for(it = depends.begin(); it != depends.end(); ++it)
  247. {
  248. if(it->size() > 0)
  249. {
  250. fout << "\t\t{"
  251. << this->GetGUID(it->c_str())
  252. << "} = {"
  253. << this->GetGUID(it->c_str())
  254. << "}\n";
  255. }
  256. }
  257. fout << "\tEndProjectSection\n";
  258. }
  259. fout << "EndProject\n";
  260. }
  261. //----------------------------------------------------------------------------
  262. // Write a dsp file into the SLN file, Note, that dependencies from
  263. // executables to the libraries it uses are also done here
  264. void cmGlobalVisualStudio71Generator
  265. ::WriteProjectConfigurations(std::ostream& fout, const char* name,
  266. bool partOfDefaultBuild)
  267. {
  268. std::string guid = this->GetGUID(name);
  269. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  270. i != this->Configurations.end(); ++i)
  271. {
  272. fout << "\t\t{" << guid << "}." << *i
  273. << ".ActiveCfg = " << *i << "|Win32\n";
  274. if(partOfDefaultBuild)
  275. {
  276. fout << "\t\t{" << guid << "}." << *i
  277. << ".Build.0 = " << *i << "|Win32\n";
  278. }
  279. }
  280. }
  281. //----------------------------------------------------------------------------
  282. // Standard end of dsw file
  283. void cmGlobalVisualStudio71Generator::WriteSLNFooter(std::ostream& fout)
  284. {
  285. fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n"
  286. << "\tEndGlobalSection\n"
  287. << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n"
  288. << "\tEndGlobalSection\n"
  289. << "EndGlobal\n";
  290. }
  291. //----------------------------------------------------------------------------
  292. // ouput standard header for dsw file
  293. void cmGlobalVisualStudio71Generator::WriteSLNHeader(std::ostream& fout)
  294. {
  295. fout << "Microsoft Visual Studio Solution File, Format Version 8.00\n";
  296. }
  297. //----------------------------------------------------------------------------
  298. void cmGlobalVisualStudio71Generator
  299. ::GetDocumentation(cmDocumentationEntry& entry) const
  300. {
  301. entry.Name = this->GetName();
  302. entry.Brief = "Generates Visual Studio .NET 2003 project files.";
  303. entry.Full = "";
  304. }