cmGlobalVisualStudio71Generator.cxx 12 KB

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