cmGlobalVisualStudio71Generator.cxx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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 all targets under this root generator and the transitive
  91. // closure of their dependencies.
  92. TargetDependSet projectTargets;
  93. TargetDependSet originalTargets;
  94. this->GetTargetSets(projectTargets, originalTargets, root, generators);
  95. OrderedTargetDependSet orderedProjectTargets(projectTargets);
  96. this->WriteTargetsToSolution(fout, root, orderedProjectTargets);
  97. // Write out the configurations information for the solution
  98. fout << "Global\n";
  99. // Write out the configurations for the solution
  100. this->WriteSolutionConfigurations(fout);
  101. fout << "\tGlobalSection(" << this->ProjectConfigurationSectionName
  102. << ") = postSolution\n";
  103. // Write out the configurations for all the targets in the project
  104. this->WriteTargetConfigurations(fout, root, orderedProjectTargets);
  105. fout << "\tEndGlobalSection\n";
  106. // Write the footer for the SLN file
  107. this->WriteSLNFooter(fout);
  108. }
  109. //----------------------------------------------------------------------------
  110. void
  111. cmGlobalVisualStudio71Generator
  112. ::WriteSolutionConfigurations(std::ostream& fout)
  113. {
  114. fout << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
  115. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  116. i != this->Configurations.end(); ++i)
  117. {
  118. fout << "\t\t" << *i << " = " << *i << "\n";
  119. }
  120. fout << "\tEndGlobalSection\n";
  121. }
  122. //----------------------------------------------------------------------------
  123. // Write a dsp file into the SLN file,
  124. // Note, that dependencies from executables to
  125. // the libraries it uses are also done here
  126. void
  127. cmGlobalVisualStudio71Generator::WriteProject(std::ostream& fout,
  128. const char* dspname,
  129. const char* dir,
  130. cmTarget& t)
  131. {
  132. // check to see if this is a fortran build
  133. const char* ext = ".vcproj";
  134. const char* project =
  135. "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"";
  136. if(this->TargetIsFortranOnly(t))
  137. {
  138. ext = ".vfproj";
  139. project = "Project(\"{6989167D-11E4-40FE-8C1A-2192A86A7E90}\") = \"";
  140. }
  141. const char* targetExt = t.GetProperty("GENERATOR_FILE_NAME_EXT");
  142. if(targetExt)
  143. {
  144. ext = targetExt;
  145. }
  146. fout << project
  147. << dspname << "\", \""
  148. << this->ConvertToSolutionPath(dir)
  149. << "\\" << dspname << ext << "\", \"{"
  150. << this->GetGUID(dspname) << "}\"\n";
  151. fout << "\tProjectSection(ProjectDependencies) = postProject\n";
  152. this->WriteProjectDepends(fout, dspname, dir, t);
  153. fout << "\tEndProjectSection\n";
  154. fout <<"EndProject\n";
  155. }
  156. //----------------------------------------------------------------------------
  157. // Write a dsp file into the SLN file,
  158. // Note, that dependencies from executables to
  159. // the libraries it uses are also done here
  160. void
  161. cmGlobalVisualStudio71Generator
  162. ::WriteProjectDepends(std::ostream& fout,
  163. const char* dspname,
  164. const char*, cmTarget& target)
  165. {
  166. #if 0
  167. // Create inter-target dependencies in the solution file. For VS
  168. // 7.1 and below we cannot let static libraries depend directly on
  169. // targets to which they "link" because the librarian tool will copy
  170. // the targets into the static library. See
  171. // cmGlobalVisualStudioGenerator::FixUtilityDependsForTarget for a
  172. // work-around. VS 8 and above do not have this problem.
  173. if (!this->VSLinksDependencies() ||
  174. target.GetType() != cmTarget::STATIC_LIBRARY);
  175. #else
  176. if (target.GetType() != cmTarget::STATIC_LIBRARY)
  177. #endif
  178. {
  179. cmTarget::LinkLibraryVectorType::const_iterator j, jend;
  180. j = target.GetLinkLibraries().begin();
  181. jend = target.GetLinkLibraries().end();
  182. for(;j!= jend; ++j)
  183. {
  184. if(j->first != dspname)
  185. {
  186. // is the library part of this SLN ? If so add dependency
  187. // find target anywhere because all depend libraries are
  188. // brought in as well
  189. if(this->FindTarget(0, j->first.c_str()))
  190. {
  191. fout << "\t\t{" << this->GetGUID(j->first.c_str()) << "} = {"
  192. << this->GetGUID(j->first.c_str()) << "}\n";
  193. }
  194. }
  195. }
  196. }
  197. std::set<cmStdString>::const_iterator i, end;
  198. // write utility dependencies.
  199. i = target.GetUtilities().begin();
  200. end = target.GetUtilities().end();
  201. for(;i!= end; ++i)
  202. {
  203. if(*i != dspname)
  204. {
  205. std::string name = this->GetUtilityForTarget(target, i->c_str());
  206. std::string guid = this->GetGUID(name.c_str());
  207. if(guid.size() == 0)
  208. {
  209. std::string m = "Target: ";
  210. m += target.GetName();
  211. m += " depends on unknown target: ";
  212. m += name;
  213. cmSystemTools::Error(m.c_str());
  214. }
  215. fout << "\t\t{" << guid << "} = {" << guid << "}\n";
  216. }
  217. }
  218. }
  219. //----------------------------------------------------------------------------
  220. // Write a dsp file into the SLN file, Note, that dependencies from
  221. // executables to the libraries it uses are also done here
  222. void cmGlobalVisualStudio71Generator
  223. ::WriteExternalProject(std::ostream& fout,
  224. const char* name,
  225. const char* location,
  226. const std::set<cmStdString>& depends)
  227. {
  228. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
  229. << name << "\", \""
  230. << this->ConvertToSolutionPath(location) << "\", \"{"
  231. << this->GetGUID(name)
  232. << "}\"\n";
  233. // write out the dependencies here VS 7.1 includes dependencies with the
  234. // project instead of in the global section
  235. if(!depends.empty())
  236. {
  237. fout << "\tProjectSection(ProjectDependencies) = postProject\n";
  238. std::set<cmStdString>::const_iterator it;
  239. for(it = depends.begin(); it != depends.end(); ++it)
  240. {
  241. if(it->size() > 0)
  242. {
  243. fout << "\t\t{"
  244. << this->GetGUID(it->c_str())
  245. << "} = {"
  246. << this->GetGUID(it->c_str())
  247. << "}\n";
  248. }
  249. }
  250. fout << "\tEndProjectSection\n";
  251. }
  252. fout << "EndProject\n";
  253. }
  254. //----------------------------------------------------------------------------
  255. // Write a dsp file into the SLN file, Note, that dependencies from
  256. // executables to the libraries it uses are also done here
  257. void cmGlobalVisualStudio71Generator
  258. ::WriteProjectConfigurations(std::ostream& fout, const char* name,
  259. bool partOfDefaultBuild)
  260. {
  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 << "|Win32\n";
  267. if(partOfDefaultBuild)
  268. {
  269. fout << "\t\t{" << guid << "}." << *i
  270. << ".Build.0 = " << *i << "|Win32\n";
  271. }
  272. }
  273. }
  274. //----------------------------------------------------------------------------
  275. // Standard end of dsw file
  276. void cmGlobalVisualStudio71Generator::WriteSLNFooter(std::ostream& fout)
  277. {
  278. fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n"
  279. << "\tEndGlobalSection\n"
  280. << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n"
  281. << "\tEndGlobalSection\n"
  282. << "EndGlobal\n";
  283. }
  284. //----------------------------------------------------------------------------
  285. // ouput standard header for dsw file
  286. void cmGlobalVisualStudio71Generator::WriteSLNHeader(std::ostream& fout)
  287. {
  288. fout << "Microsoft Visual Studio Solution File, Format Version 8.00\n";
  289. }
  290. //----------------------------------------------------------------------------
  291. void cmGlobalVisualStudio71Generator
  292. ::GetDocumentation(cmDocumentationEntry& entry) const
  293. {
  294. entry.Name = this->GetName();
  295. entry.Brief = "Generates Visual Studio .NET 2003 project files.";
  296. entry.Full = "";
  297. }