cmGlobalVisualStudio71Generator.cxx 9.5 KB

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