cmGlobalVisualStudio71Generator.cxx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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 "cmGlobalVisualStudio71Generator.h"
  14. #include "cmLocalVisualStudio7Generator.h"
  15. #include "cmMakefile.h"
  16. #include "cmake.h"
  17. #include "windows.h"
  18. cmGlobalVisualStudio71Generator::cmGlobalVisualStudio71Generator()
  19. {
  20. m_FindMakeProgramFile = "CMakeVS71FindMake.cmake";
  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->SetGlobalGenerator(this);
  28. return lg;
  29. }
  30. // Write a SLN file to the stream
  31. void cmGlobalVisualStudio71Generator::WriteSLNFile(std::ostream& fout,
  32. cmLocalGenerator* root,
  33. std::vector<cmLocalGenerator*>& generators)
  34. {
  35. // Write out the header for a SLN file
  36. this->WriteSLNHeader(fout);
  37. // Get the home directory with the trailing slash
  38. std::string homedir = m_CMakeInstance->GetHomeDirectory();
  39. homedir += "/";
  40. bool doneAllBuild = false;
  41. bool doneRunTests = false;
  42. // For each cmMakefile, create a VCProj for it, and
  43. // add it to this SLN file
  44. unsigned int i;
  45. for(i = 0; i < generators.size(); ++i)
  46. {
  47. if(this->IsExcluded(root, generators[i]))
  48. {
  49. continue;
  50. }
  51. cmMakefile* mf = generators[i]->GetMakefile();
  52. // Get the source directory from the makefile
  53. std::string dir = mf->GetStartDirectory();
  54. // remove the home directory and / from the source directory
  55. // this gives a relative path
  56. cmSystemTools::ReplaceString(dir, homedir.c_str(), "");
  57. // Get the list of create dsp files names from the cmVCProjWriter, more
  58. // than one dsp could have been created per input CMakeLists.txt file
  59. // for each target
  60. std::vector<std::string> dspnames =
  61. static_cast<cmLocalVisualStudio7Generator *>(generators[i])
  62. ->GetCreatedProjectNames();
  63. cmTargets &tgts = generators[i]->GetMakefile()->GetTargets();
  64. cmTargets::iterator l = tgts.begin();
  65. for(std::vector<std::string>::iterator si = dspnames.begin();
  66. l != tgts.end(); ++l)
  67. {
  68. // special handling for the current makefile
  69. if(mf == generators[0]->GetMakefile())
  70. {
  71. dir = "."; // no subdirectory for project generated
  72. // if this is the special ALL_BUILD utility, then
  73. // make it depend on every other non UTILITY project.
  74. // This is done by adding the names to the GetUtilities
  75. // vector on the makefile
  76. if(l->first == "ALL_BUILD" && !doneAllBuild)
  77. {
  78. unsigned int j;
  79. for(j = 0; j < generators.size(); ++j)
  80. {
  81. const cmTargets &atgts =
  82. generators[j]->GetMakefile()->GetTargets();
  83. for(cmTargets::const_iterator al = atgts.begin();
  84. al != atgts.end(); ++al)
  85. {
  86. if (al->second.IsInAll())
  87. {
  88. if (al->second.GetType() == cmTarget::UTILITY)
  89. {
  90. l->second.AddUtility(al->first.c_str());
  91. }
  92. else
  93. {
  94. l->second.AddLinkLibrary(al->first,cmTarget::GENERAL);
  95. }
  96. }
  97. }
  98. }
  99. }
  100. }
  101. // Write the project into the SLN file
  102. if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
  103. {
  104. cmCustomCommand cc = l->second.GetPreLinkCommands()[0];
  105. // dodgy use of the cmCustomCommand's members to store the
  106. // arguments from the INCLUDE_EXTERNAL_MSPROJECT command
  107. std::vector<std::string> stuff = cc.GetDepends();
  108. std::vector<std::string> depends;
  109. depends.push_back(cc.GetOutput());
  110. this->WriteExternalProject(fout, stuff[0].c_str(),
  111. stuff[1].c_str(), depends);
  112. ++si;
  113. }
  114. else
  115. {
  116. if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  117. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
  118. {
  119. bool skip = false;
  120. if(l->first == "ALL_BUILD" )
  121. {
  122. if(doneAllBuild)
  123. {
  124. skip = true;
  125. }
  126. else
  127. {
  128. doneAllBuild = true;
  129. }
  130. }
  131. if(l->first == "RUN_TESTS")
  132. {
  133. if(doneRunTests)
  134. {
  135. skip = true;
  136. }
  137. else
  138. {
  139. doneRunTests = true;
  140. }
  141. }
  142. if(!skip)
  143. {
  144. this->WriteProject(fout, si->c_str(), dir.c_str(),l->second);
  145. }
  146. ++si;
  147. }
  148. }
  149. }
  150. }
  151. fout << "Global\n"
  152. << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
  153. for(std::vector<std::string>::iterator i = m_Configurations.begin();
  154. i != m_Configurations.end(); ++i)
  155. {
  156. fout << "\t\t" << *i << " = " << *i << "\n";
  157. }
  158. fout << "\tEndGlobalSection\n";
  159. fout << "\tGlobalSection(ProjectConfiguration) = postSolution\n";
  160. // loop over again and compute the depends
  161. for(i = 0; i < generators.size(); ++i)
  162. {
  163. cmMakefile* mf = generators[i]->GetMakefile();
  164. cmLocalVisualStudio7Generator* pg =
  165. static_cast<cmLocalVisualStudio7Generator*>(generators[i]);
  166. // Get the list of create dsp files names from the cmVCProjWriter, more
  167. // than one dsp could have been created per input CMakeLists.txt file
  168. // for each target
  169. std::vector<std::string> dspnames =
  170. pg->GetCreatedProjectNames();
  171. cmTargets &tgts = pg->GetMakefile()->GetTargets();
  172. cmTargets::iterator l = tgts.begin();
  173. std::string dir = mf->GetStartDirectory();
  174. for(std::vector<std::string>::iterator si = dspnames.begin();
  175. l != tgts.end(); ++l)
  176. {
  177. if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  178. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
  179. {
  180. this->WriteProjectConfigurations(fout, si->c_str(), l->second.IsInAll());
  181. ++si;
  182. }
  183. }
  184. }
  185. fout << "\tEndGlobalSection\n";
  186. // Write the footer for the SLN file
  187. this->WriteSLNFooter(fout);
  188. }
  189. // Write a dsp file into the SLN file,
  190. // Note, that dependencies from executables to
  191. // the libraries it uses are also done here
  192. void cmGlobalVisualStudio71Generator::WriteProject(std::ostream& fout,
  193. const char* dspname,
  194. const char* dir,
  195. const cmTarget& t)
  196. {
  197. std::string d = cmSystemTools::ConvertToOutputPath(dir);
  198. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
  199. << dspname << "\", \""
  200. << d << "\\" << dspname << ".vcproj\", \"{"
  201. << this->CreateGUID(dspname) << "}\"\n";
  202. fout << "\tProjectSection(ProjectDependencies) = postProject\n";
  203. this->WriteProjectDepends(fout, dspname, dir, t);
  204. fout << "\tEndProjectSection\n";
  205. fout <<"EndProject\n";
  206. }
  207. // Write a dsp file into the SLN file,
  208. // Note, that dependencies from executables to
  209. // the libraries it uses are also done here
  210. void cmGlobalVisualStudio71Generator::WriteProjectDepends(std::ostream& fout,
  211. const char* dspname,
  212. const char* ,
  213. const cmTarget& target
  214. )
  215. {
  216. // insert Begin Project Dependency Project_Dep_Name project stuff here
  217. if (target.GetType() != cmTarget::STATIC_LIBRARY)
  218. {
  219. cmTarget::LinkLibraries::const_iterator j, jend;
  220. j = target.GetLinkLibraries().begin();
  221. jend = target.GetLinkLibraries().end();
  222. for(;j!= jend; ++j)
  223. {
  224. if(j->first != dspname)
  225. {
  226. // is the library part of this SLN ? If so add dependency
  227. std::string libPath = j->first + "_CMAKE_PATH";
  228. const char* cacheValue
  229. = m_CMakeInstance->GetCacheDefinition(libPath.c_str());
  230. if(cacheValue && *cacheValue)
  231. {
  232. fout << "\t\t{" << this->CreateGUID(j->first.c_str()) << "} = {"
  233. << this->CreateGUID(j->first.c_str()) << "}\n";
  234. }
  235. }
  236. }
  237. }
  238. std::set<cmStdString>::const_iterator i, end;
  239. // write utility dependencies.
  240. i = target.GetUtilities().begin();
  241. end = target.GetUtilities().end();
  242. for(;i!= end; ++i)
  243. {
  244. if(*i != dspname)
  245. {
  246. fout << "\t\t{" << this->CreateGUID(i->c_str()) << "} = {"
  247. << this->CreateGUID(i->c_str()) << "}\n";
  248. }
  249. }
  250. }
  251. // Write a dsp file into the SLN file,
  252. // Note, that dependencies from executables to
  253. // the libraries it uses are also done here
  254. void
  255. cmGlobalVisualStudio71Generator::WriteProjectConfigurations(std::ostream& fout,
  256. const char* name,
  257. bool in_all_build)
  258. {
  259. std::string guid = this->CreateGUID(name);
  260. for(std::vector<std::string>::iterator i = m_Configurations.begin();
  261. i != m_Configurations.end(); ++i)
  262. {
  263. fout << "\t\t{" << guid << "}." << *i << ".ActiveCfg = " << *i << "|Win32\n";
  264. if (in_all_build)
  265. {
  266. fout << "\t\t{" << guid << "}." << *i << ".Build.0 = " << *i << "|Win32\n";
  267. }
  268. }
  269. }
  270. // Standard end of dsw file
  271. void cmGlobalVisualStudio71Generator::WriteSLNFooter(std::ostream& fout)
  272. {
  273. fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n"
  274. << "\tEndGlobalSection\n"
  275. << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n"
  276. << "\tEndGlobalSection\n"
  277. << "EndGlobal\n";
  278. }
  279. // ouput standard header for dsw file
  280. void cmGlobalVisualStudio71Generator::WriteSLNHeader(std::ostream& fout)
  281. {
  282. fout << "Microsoft Visual Studio Solution File, Format Version 8.00\n";
  283. }
  284. //----------------------------------------------------------------------------
  285. void cmGlobalVisualStudio71Generator::GetDocumentation(cmDocumentationEntry& entry) const
  286. {
  287. entry.name = this->GetName();
  288. entry.brief = "Generates Visual Studio .NET 2003 project files.";
  289. entry.full = "";
  290. }