cmGlobalVisualStudio8Generator.cxx 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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->SetExtraFlagTable(this->GetExtraFlagTableVS8());
  30. lg->SetGlobalGenerator(this);
  31. return lg;
  32. }
  33. // ouput standard header for dsw file
  34. void cmGlobalVisualStudio8Generator::WriteSLNHeader(std::ostream& fout)
  35. {
  36. fout << "Microsoft Visual Studio Solution File, Format Version 9.00\n";
  37. fout << "# Visual Studio 2005\n";
  38. }
  39. //----------------------------------------------------------------------------
  40. void cmGlobalVisualStudio8Generator
  41. ::GetDocumentation(cmDocumentationEntry& entry) const
  42. {
  43. entry.Name = this->GetName();
  44. entry.Brief = "Generates Visual Studio .NET 2005 project files.";
  45. entry.Full = "";
  46. }
  47. //----------------------------------------------------------------------------
  48. void cmGlobalVisualStudio8Generator::AddPlatformDefinitions(cmMakefile* mf)
  49. {
  50. mf->AddDefinition("MSVC80", "1");
  51. }
  52. //----------------------------------------------------------------------------
  53. void cmGlobalVisualStudio8Generator::Configure()
  54. {
  55. this->cmGlobalVisualStudio7Generator::Configure();
  56. this->CreateGUID(CMAKE_CHECK_BUILD_SYSTEM_TARGET);
  57. }
  58. //----------------------------------------------------------------------------
  59. void cmGlobalVisualStudio8Generator::Generate()
  60. {
  61. // Add a special target on which all other targets depend that
  62. // checks the build system and optionally re-runs CMake.
  63. const char* no_working_directory = 0;
  64. std::vector<std::string> no_depends;
  65. std::map<cmStdString, std::vector<cmLocalGenerator*> >::iterator it;
  66. for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
  67. {
  68. std::vector<cmLocalGenerator*>& generators = it->second;
  69. if(!generators.empty())
  70. {
  71. // Add the build-system check target to the first local
  72. // generator of this project.
  73. cmLocalVisualStudio7Generator* lg =
  74. static_cast<cmLocalVisualStudio7Generator*>(generators[0]);
  75. cmMakefile* mf = lg->GetMakefile();
  76. std::string cmake_command = mf->GetRequiredDefinition("CMAKE_COMMAND");
  77. cmCustomCommandLines noCommandLines;
  78. mf->AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, false,
  79. no_working_directory, no_depends,
  80. noCommandLines);
  81. cmTarget* tgt = mf->FindTarget(CMAKE_CHECK_BUILD_SYSTEM_TARGET, false);
  82. if(!tgt)
  83. {
  84. cmSystemTools::Error("Error adding target "
  85. CMAKE_CHECK_BUILD_SYSTEM_TARGET);
  86. continue;
  87. }
  88. // Add a custom rule to re-run CMake if any input files changed.
  89. const char* suppRegenRule =
  90. mf->GetDefinition("CMAKE_SUPPRESS_REGENERATION");
  91. if(!cmSystemTools::IsOn(suppRegenRule))
  92. {
  93. // Collect the input files used to generate all targets in this
  94. // project.
  95. std::vector<std::string> listFiles;
  96. for(unsigned int j = 0; j < generators.size(); ++j)
  97. {
  98. cmMakefile* lmf = generators[j]->GetMakefile();
  99. listFiles.insert(listFiles.end(), lmf->GetListFiles().begin(),
  100. lmf->GetListFiles().end());
  101. }
  102. // Sort the list of input files and remove duplicates.
  103. std::sort(listFiles.begin(), listFiles.end(),
  104. std::less<std::string>());
  105. std::vector<std::string>::iterator new_end =
  106. std::unique(listFiles.begin(), listFiles.end());
  107. listFiles.erase(new_end, listFiles.end());
  108. // Create a rule to re-run CMake.
  109. std::string stampName = cmake::GetCMakeFilesDirectoryPostSlash();
  110. stampName += CMAKE_CHECK_BUILD_SYSTEM_TARGET ".vcproj.stamp";
  111. const char* dsprule = mf->GetRequiredDefinition("CMAKE_COMMAND");
  112. cmCustomCommandLine commandLine;
  113. commandLine.push_back(dsprule);
  114. std::string argH = "-H";
  115. argH += lg->Convert(mf->GetHomeDirectory(),
  116. cmLocalGenerator::START_OUTPUT,
  117. cmLocalGenerator::UNCHANGED, true);
  118. commandLine.push_back(argH);
  119. std::string argB = "-B";
  120. argB += lg->Convert(mf->GetHomeOutputDirectory(),
  121. cmLocalGenerator::START_OUTPUT,
  122. cmLocalGenerator::UNCHANGED, true);
  123. commandLine.push_back(argB);
  124. commandLine.push_back("--check-stamp-file");
  125. commandLine.push_back(stampName.c_str());
  126. cmCustomCommandLines commandLines;
  127. commandLines.push_back(commandLine);
  128. // Add the rule. Note that we cannot use the CMakeLists.txt
  129. // file as the main dependency because it would get
  130. // overwritten by the AddVCProjBuildRule of the ALL_BUILD
  131. // target.
  132. const char* no_main_dependency = 0;
  133. const char* no_working_directory = 0;
  134. mf->AddCustomCommandToOutput(
  135. stampName.c_str(), listFiles,
  136. no_main_dependency, commandLines, "Checking Build System",
  137. no_working_directory, true);
  138. std::string ruleName = stampName;
  139. ruleName += ".rule";
  140. if(cmSourceFile* file = mf->GetSource(ruleName.c_str()))
  141. {
  142. tgt->AddSourceFile(file);
  143. }
  144. else
  145. {
  146. cmSystemTools::Error("Error adding rule for ", stampName.c_str());
  147. }
  148. }
  149. }
  150. }
  151. // Now perform the main generation.
  152. this->cmGlobalVisualStudio7Generator::Generate();
  153. }
  154. //----------------------------------------------------------------------------
  155. void cmGlobalVisualStudio8Generator::WriteSLNFile(
  156. std::ostream& fout, cmLocalGenerator* root,
  157. std::vector<cmLocalGenerator*>& generators)
  158. {
  159. // Make all targets depend on their respective project's build
  160. // system check target.
  161. unsigned int i;
  162. for(i = 0; i < generators.size(); ++i)
  163. {
  164. if(this->IsExcluded(root, generators[i]))
  165. {
  166. continue;
  167. }
  168. cmMakefile* mf = generators[i]->GetMakefile();
  169. cmTargets& tgts = mf->GetTargets();
  170. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
  171. {
  172. if(l->first == CMAKE_CHECK_BUILD_SYSTEM_TARGET)
  173. {
  174. for(unsigned int j = 0; j < generators.size(); ++j)
  175. {
  176. // Every target in all generators should depend on this target.
  177. cmMakefile* lmf = generators[j]->GetMakefile();
  178. cmTargets &atgts = lmf->GetTargets();
  179. for(cmTargets::iterator al = atgts.begin(); al != atgts.end(); ++al)
  180. {
  181. al->second.AddUtility(l->first.c_str());
  182. }
  183. }
  184. }
  185. }
  186. }
  187. // Now write the solution file.
  188. this->cmGlobalVisualStudio71Generator::WriteSLNFile(fout, root, generators);
  189. }
  190. //----------------------------------------------------------------------------
  191. void
  192. cmGlobalVisualStudio8Generator
  193. ::WriteSolutionConfigurations(std::ostream& fout)
  194. {
  195. fout << "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n";
  196. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  197. i != this->Configurations.end(); ++i)
  198. {
  199. fout << "\t\t" << *i << "|" << this->PlatformName << " = " << *i << "|"
  200. << this->PlatformName << "\n";
  201. }
  202. fout << "\tEndGlobalSection\n";
  203. }
  204. //----------------------------------------------------------------------------
  205. void
  206. cmGlobalVisualStudio8Generator
  207. ::WriteProjectConfigurations(std::ostream& fout, const char* name,
  208. bool partOfDefaultBuild)
  209. {
  210. std::string guid = this->GetGUID(name);
  211. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  212. i != this->Configurations.end(); ++i)
  213. {
  214. fout << "\t\t{" << guid << "}." << *i
  215. << "|" << this->PlatformName << ".ActiveCfg = "
  216. << *i << "|" << this->PlatformName << "\n";
  217. if(partOfDefaultBuild)
  218. {
  219. fout << "\t\t{" << guid << "}." << *i
  220. << "|" << this->PlatformName << ".Build.0 = "
  221. << *i << "|" << this->PlatformName << "\n";
  222. }
  223. }
  224. }
  225. //----------------------------------------------------------------------------
  226. static cmVS7FlagTable cmVS8ExtraFlagTable[] =
  227. {
  228. // Precompiled header and related options. Note that the
  229. // UsePrecompiledHeader entries are marked as "Continue" so that the
  230. // corresponding PrecompiledHeaderThrough entry can be found.
  231. {"UsePrecompiledHeader", "Yu", "Use Precompiled Header", "2",
  232. cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
  233. {"PrecompiledHeaderThrough", "Yu", "Precompiled Header Name", "",
  234. cmVS7FlagTable::UserValueRequired},
  235. // There is no YX option in the VS8 IDE.
  236. {0,0,0,0,0}
  237. };
  238. cmVS7FlagTable const* cmGlobalVisualStudio8Generator::GetExtraFlagTableVS8()
  239. {
  240. return cmVS8ExtraFlagTable;
  241. }