cmGlobalVisualStudio8Generator.cxx 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 "windows.h" // this must be first to define GetCurrentDirectory
  14. #include "cmGlobalVisualStudio8Generator.h"
  15. #include "cmLocalVisualStudio7Generator.h"
  16. #include "cmMakefile.h"
  17. #include "cmake.h"
  18. cmGlobalVisualStudio8Generator::cmGlobalVisualStudio8Generator()
  19. {
  20. this->FindMakeProgramFile = "CMakeVS8FindMake.cmake";
  21. this->ProjectConfigurationSectionName = "ProjectConfigurationPlatforms";
  22. this->PlatformName = "Win32";
  23. }
  24. ///! Create a local generator appropriate to this Global Generator
  25. cmLocalGenerator *cmGlobalVisualStudio8Generator::CreateLocalGenerator()
  26. {
  27. cmLocalVisualStudio7Generator *lg = new cmLocalVisualStudio7Generator;
  28. lg->SetVersion8();
  29. lg->SetGlobalGenerator(this);
  30. return lg;
  31. }
  32. // ouput standard header for dsw file
  33. void cmGlobalVisualStudio8Generator::WriteSLNHeader(std::ostream& fout)
  34. {
  35. fout << "Microsoft Visual Studio Solution File, Format Version 9.00\n";
  36. fout << "# Visual Studio 2005\n";
  37. }
  38. //----------------------------------------------------------------------------
  39. void cmGlobalVisualStudio8Generator::GetDocumentation(cmDocumentationEntry& entry) const
  40. {
  41. entry.name = this->GetName();
  42. entry.brief = "Generates Visual Studio .NET 2005 project files.";
  43. entry.full = "";
  44. }
  45. //----------------------------------------------------------------------------
  46. void cmGlobalVisualStudio8Generator::Configure()
  47. {
  48. this->cmGlobalVisualStudio7Generator::Configure();
  49. this->CreateGUID(CMAKE_CHECK_BUILD_SYSTEM_TARGET);
  50. }
  51. //----------------------------------------------------------------------------
  52. void cmGlobalVisualStudio8Generator::Generate()
  53. {
  54. // Add a special target on which all other targets depend that
  55. // checks the build system and optionally re-runs CMake.
  56. const char* no_output = 0;
  57. const char* no_working_directory = 0;
  58. std::vector<std::string> no_depends;
  59. std::map<cmStdString, std::vector<cmLocalGenerator*> >::iterator it;
  60. for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
  61. {
  62. std::vector<cmLocalGenerator*>& generators = it->second;
  63. if(!generators.empty())
  64. {
  65. // Add the build-system check target to the first local
  66. // generator of this project.
  67. cmLocalVisualStudio7Generator* lg =
  68. static_cast<cmLocalVisualStudio7Generator*>(generators[0]);
  69. cmMakefile* mf = lg->GetMakefile();
  70. std::string cmake_command = mf->GetRequiredDefinition("CMAKE_COMMAND");
  71. mf->AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, true,
  72. no_output, no_depends,
  73. no_working_directory,
  74. "echo", "Checking build system");
  75. cmTarget* tgt = mf->FindTarget(CMAKE_CHECK_BUILD_SYSTEM_TARGET);
  76. if(!tgt)
  77. {
  78. cmSystemTools::Error("Error adding target " CMAKE_CHECK_BUILD_SYSTEM_TARGET);
  79. continue;
  80. }
  81. // Add a custom rule to re-run CMake if any input files changed.
  82. const char* suppRegenRule =
  83. mf->GetDefinition("CMAKE_SUPPRESS_REGENERATION");
  84. if(!cmSystemTools::IsOn(suppRegenRule))
  85. {
  86. // Collect the input files used to generate all targets in this
  87. // project.
  88. std::vector<std::string> listFiles;
  89. for(unsigned int j = 0; j < generators.size(); ++j)
  90. {
  91. cmMakefile* lmf = generators[j]->GetMakefile();
  92. listFiles.insert(listFiles.end(), lmf->GetListFiles().begin(),
  93. lmf->GetListFiles().end());
  94. }
  95. // Sort the list of input files and remove duplicates.
  96. std::sort(listFiles.begin(), listFiles.end(), std::less<std::string>());
  97. std::vector<std::string>::iterator new_end =
  98. std::unique(listFiles.begin(), listFiles.end());
  99. listFiles.erase(new_end, listFiles.end());
  100. // Create a rule to re-run CMake.
  101. const char* dsprule = mf->GetRequiredDefinition("CMAKE_COMMAND");
  102. cmCustomCommandLine commandLine;
  103. commandLine.push_back(dsprule);
  104. std::string argH = "-H";
  105. argH += lg->Convert(mf->GetHomeDirectory(),
  106. cmLocalGenerator::START_OUTPUT,
  107. cmLocalGenerator::SHELL, true);
  108. commandLine.push_back(argH);
  109. std::string argB = "-B";
  110. argB += lg->Convert(mf->GetHomeOutputDirectory(),
  111. cmLocalGenerator::START_OUTPUT,
  112. cmLocalGenerator::SHELL, true);
  113. commandLine.push_back(argB);
  114. cmCustomCommandLines commandLines;
  115. commandLines.push_back(commandLine);
  116. // Add the rule. Note that we cannot use the CMakeLists.txt
  117. // file as the main dependency because it would get
  118. // overwritten by the AddVCProjBuildRule of the ALL_BUILD
  119. // target.
  120. const char* no_comment = 0;
  121. const char* no_main_dependency = 0;
  122. const char* no_working_directory = 0;
  123. mf->AddCustomCommandToOutput(
  124. CMAKE_CHECK_BUILD_SYSTEM_TARGET ".vcproj.cmake", listFiles,
  125. no_main_dependency, commandLines, no_comment, no_working_directory, true);
  126. if(cmSourceFile* file = mf->GetSource(CMAKE_CHECK_BUILD_SYSTEM_TARGET ".vcproj.cmake.rule"))
  127. {
  128. tgt->GetSourceFiles().push_back(file);
  129. }
  130. else
  131. {
  132. cmSystemTools::Error("Error adding rule for " CMAKE_CHECK_BUILD_SYSTEM_TARGET ".vcproj.cmake");
  133. }
  134. }
  135. }
  136. }
  137. // Now perform the main generation.
  138. this->cmGlobalVisualStudio7Generator::Generate();
  139. }
  140. //----------------------------------------------------------------------------
  141. void cmGlobalVisualStudio8Generator::WriteSLNFile(
  142. std::ostream& fout, cmLocalGenerator* root,
  143. std::vector<cmLocalGenerator*>& generators)
  144. {
  145. // Make all targets depend on their respective project's build
  146. // system check target.
  147. unsigned int i;
  148. for(i = 0; i < generators.size(); ++i)
  149. {
  150. if(this->IsExcluded(root, generators[i]))
  151. {
  152. continue;
  153. }
  154. cmMakefile* mf = generators[i]->GetMakefile();
  155. std::vector<std::string> dspnames =
  156. static_cast<cmLocalVisualStudio7Generator*>(generators[i])
  157. ->GetCreatedProjectNames();
  158. cmTargets& tgts = mf->GetTargets();
  159. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
  160. {
  161. if(l->first == CMAKE_CHECK_BUILD_SYSTEM_TARGET)
  162. {
  163. for(unsigned int j = 0; j < generators.size(); ++j)
  164. {
  165. // Every target in all generators should depend on this target.
  166. cmMakefile* lmf = generators[j]->GetMakefile();
  167. cmTargets &atgts = lmf->GetTargets();
  168. for(cmTargets::iterator al = atgts.begin(); al != atgts.end(); ++al)
  169. {
  170. al->second.AddUtility(l->first.c_str());
  171. }
  172. }
  173. }
  174. }
  175. }
  176. // Now write the solution file.
  177. this->cmGlobalVisualStudio71Generator::WriteSLNFile(fout, root, generators);
  178. }
  179. //----------------------------------------------------------------------------
  180. void
  181. cmGlobalVisualStudio8Generator
  182. ::WriteSolutionConfigurations(std::ostream& fout)
  183. {
  184. fout << "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n";
  185. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  186. i != this->Configurations.end(); ++i)
  187. {
  188. fout << "\t\t" << *i << "|" << this->PlatformName << " = " << *i << "|"
  189. << this->PlatformName << "\n";
  190. }
  191. fout << "\tEndGlobalSection\n";
  192. }
  193. //----------------------------------------------------------------------------
  194. void
  195. cmGlobalVisualStudio8Generator
  196. ::WriteProjectConfigurations(std::ostream& fout,
  197. const char* name, bool in_all_build)
  198. {
  199. std::string guid = this->GetGUID(name);
  200. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  201. i != this->Configurations.end(); ++i)
  202. {
  203. fout << "\t\t{" << guid << "}." << *i << "|" << this->PlatformName << ".ActiveCfg = "
  204. << *i << "|" << this->PlatformName << "\n";
  205. if (in_all_build)
  206. {
  207. fout << "\t\t{" << guid << "}." << *i << "|" << this->PlatformName << ".Build.0 = "
  208. << *i << "|" << this->PlatformName << "\n";
  209. }
  210. }
  211. }