cmGlobalVisualStudio71Generator.cxx 11 KB

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