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()
  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->AddDefinition("MSVC71", "1");
  36. }
  37. //----------------------------------------------------------------------------
  38. std::string cmGlobalVisualStudio71Generator::GetUserMacrosDirectory()
  39. {
  40. // Macros not supported on Visual Studio 7.1 and earlier because
  41. // they do not appear to work *during* a build when called by an
  42. // outside agent...
  43. //
  44. return "";
  45. #if 0
  46. //
  47. // The COM result from calling a Visual Studio macro with 7.1 indicates
  48. // that the call succeeds, but the macro does not appear to execute...
  49. //
  50. // So, I am leaving this code here to show how to do it, but have not
  51. // yet figured out what the issue is in terms of why the macro does not
  52. // appear to execute...
  53. //
  54. std::string base;
  55. std::string path;
  56. // base begins with the VisualStudioProjectsLocation reg value...
  57. if (cmSystemTools::ReadRegistryValue(
  58. "HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\7.1;"
  59. "VisualStudioProjectsLocation",
  60. base))
  61. {
  62. cmSystemTools::ConvertToUnixSlashes(base);
  63. // 7.1 macros folder:
  64. path = base + "/VSMacros71";
  65. }
  66. // path is (correctly) still empty if we did not read the base value from
  67. // the Registry value
  68. return path;
  69. #endif
  70. }
  71. //----------------------------------------------------------------------------
  72. std::string cmGlobalVisualStudio71Generator::GetUserMacrosRegKeyBase()
  73. {
  74. // Macros not supported on Visual Studio 7.1 and earlier because
  75. // they do not appear to work *during* a build when called by an
  76. // outside agent...
  77. //
  78. return "";
  79. #if 0
  80. return "Software\\Microsoft\\VisualStudio\\7.1\\vsmacros";
  81. #endif
  82. }
  83. //----------------------------------------------------------------------------
  84. void cmGlobalVisualStudio71Generator
  85. ::WriteSLNFile(std::ostream& fout,
  86. cmLocalGenerator* root,
  87. std::vector<cmLocalGenerator*>& generators)
  88. {
  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. // Write out the configurations information for the solution
  99. fout << "Global\n";
  100. // Write out the configurations for the solution
  101. this->WriteSolutionConfigurations(fout);
  102. fout << "\tGlobalSection(" << this->ProjectConfigurationSectionName
  103. << ") = postSolution\n";
  104. // Write out the configurations for all the targets in the project
  105. this->WriteTargetConfigurations(fout, root, orderedProjectTargets);
  106. fout << "\tEndGlobalSection\n";
  107. // Write the footer for the SLN file
  108. this->WriteSLNFooter(fout);
  109. }
  110. //----------------------------------------------------------------------------
  111. void
  112. cmGlobalVisualStudio71Generator
  113. ::WriteSolutionConfigurations(std::ostream& fout)
  114. {
  115. fout << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
  116. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  117. i != this->Configurations.end(); ++i)
  118. {
  119. fout << "\t\t" << *i << " = " << *i << "\n";
  120. }
  121. fout << "\tEndGlobalSection\n";
  122. }
  123. //----------------------------------------------------------------------------
  124. // Write a dsp file into the SLN file,
  125. // Note, that dependencies from executables to
  126. // the libraries it uses are also done here
  127. void
  128. cmGlobalVisualStudio71Generator::WriteProject(std::ostream& fout,
  129. const char* dspname,
  130. const char* dir,
  131. cmTarget& t)
  132. {
  133. // check to see if this is a fortran build
  134. const char* ext = ".vcproj";
  135. const char* project =
  136. "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"";
  137. if(this->TargetIsFortranOnly(t))
  138. {
  139. ext = ".vfproj";
  140. project = "Project(\"{6989167D-11E4-40FE-8C1A-2192A86A7E90}\") = \"";
  141. }
  142. const char* targetExt = t.GetProperty("GENERATOR_FILE_NAME_EXT");
  143. if(targetExt)
  144. {
  145. ext = targetExt;
  146. }
  147. fout << project
  148. << dspname << "\", \""
  149. << this->ConvertToSolutionPath(dir)
  150. << "\\" << dspname << ext << "\", \"{"
  151. << this->GetGUID(dspname) << "}\"\n";
  152. fout << "\tProjectSection(ProjectDependencies) = postProject\n";
  153. this->WriteProjectDepends(fout, dspname, dir, t);
  154. fout << "\tEndProjectSection\n";
  155. fout <<"EndProject\n";
  156. }
  157. //----------------------------------------------------------------------------
  158. // Write a dsp file into the SLN file,
  159. // Note, that dependencies from executables to
  160. // the libraries it uses are also done here
  161. void
  162. cmGlobalVisualStudio71Generator
  163. ::WriteProjectDepends(std::ostream& fout,
  164. const char* dspname,
  165. const char*, cmTarget& target)
  166. {
  167. #if 0
  168. // Create inter-target dependencies in the solution file. For VS
  169. // 7.1 and below we cannot let static libraries depend directly on
  170. // targets to which they "link" because the librarian tool will copy
  171. // the targets into the static library. See
  172. // cmGlobalVisualStudioGenerator::FixUtilityDependsForTarget for a
  173. // work-around. VS 8 and above do not have this problem.
  174. if (!this->VSLinksDependencies() ||
  175. target.GetType() != cmTarget::STATIC_LIBRARY);
  176. #else
  177. if (target.GetType() != cmTarget::STATIC_LIBRARY)
  178. #endif
  179. {
  180. cmTarget::LinkLibraryVectorType::const_iterator j, jend;
  181. j = target.GetLinkLibraries().begin();
  182. jend = target.GetLinkLibraries().end();
  183. for(;j!= jend; ++j)
  184. {
  185. if(j->first != dspname)
  186. {
  187. // is the library part of this SLN ? If so add dependency
  188. // find target anywhere because all depend libraries are
  189. // brought in as well
  190. if(this->FindTarget(0, j->first.c_str()))
  191. {
  192. fout << "\t\t{" << this->GetGUID(j->first.c_str()) << "} = {"
  193. << this->GetGUID(j->first.c_str()) << "}\n";
  194. }
  195. }
  196. }
  197. }
  198. std::set<cmStdString>::const_iterator i, end;
  199. // write utility dependencies.
  200. i = target.GetUtilities().begin();
  201. end = target.GetUtilities().end();
  202. for(;i!= end; ++i)
  203. {
  204. if(*i != dspname)
  205. {
  206. std::string name = this->GetUtilityForTarget(target, i->c_str());
  207. std::string guid = this->GetGUID(name.c_str());
  208. if(guid.size() == 0)
  209. {
  210. std::string m = "Target: ";
  211. m += target.GetName();
  212. m += " depends on unknown target: ";
  213. m += name;
  214. cmSystemTools::Error(m.c_str());
  215. }
  216. fout << "\t\t{" << guid << "} = {" << guid << "}\n";
  217. }
  218. }
  219. }
  220. //----------------------------------------------------------------------------
  221. // Write a dsp file into the SLN file, Note, that dependencies from
  222. // executables to the libraries it uses are also done here
  223. void cmGlobalVisualStudio71Generator
  224. ::WriteExternalProject(std::ostream& fout,
  225. const char* name,
  226. const char* location,
  227. const std::set<cmStdString>& depends)
  228. {
  229. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
  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<cmStdString>::const_iterator it;
  240. for(it = depends.begin(); it != depends.end(); ++it)
  241. {
  242. if(it->size() > 0)
  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(std::ostream& fout, const char* name,
  260. bool partOfDefaultBuild)
  261. {
  262. std::string guid = this->GetGUID(name);
  263. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  264. i != this->Configurations.end(); ++i)
  265. {
  266. fout << "\t\t{" << guid << "}." << *i
  267. << ".ActiveCfg = " << *i << "|Win32\n";
  268. if(partOfDefaultBuild)
  269. {
  270. fout << "\t\t{" << guid << "}." << *i
  271. << ".Build.0 = " << *i << "|Win32\n";
  272. }
  273. }
  274. }
  275. //----------------------------------------------------------------------------
  276. // Standard end of dsw file
  277. void cmGlobalVisualStudio71Generator::WriteSLNFooter(std::ostream& fout)
  278. {
  279. fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n"
  280. << "\tEndGlobalSection\n"
  281. << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n"
  282. << "\tEndGlobalSection\n"
  283. << "EndGlobal\n";
  284. }
  285. //----------------------------------------------------------------------------
  286. // ouput standard header for dsw file
  287. void cmGlobalVisualStudio71Generator::WriteSLNHeader(std::ostream& fout)
  288. {
  289. fout << "Microsoft Visual Studio Solution File, Format Version 8.00\n";
  290. }
  291. //----------------------------------------------------------------------------
  292. void cmGlobalVisualStudio71Generator
  293. ::GetDocumentation(cmDocumentationEntry& entry) const
  294. {
  295. entry.Name = this->GetName();
  296. entry.Brief = "Generates Visual Studio .NET 2003 project files.";
  297. entry.Full = "";
  298. }