cmLocalVisualStudio10Generator.cxx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmLocalVisualStudio10Generator.h"
  4. #include <cmext/algorithm>
  5. #include "cm_expat.h"
  6. #include "cmAlgorithms.h"
  7. #include "cmGeneratorTarget.h"
  8. #include "cmGlobalVisualStudio10Generator.h"
  9. #include "cmMakefile.h"
  10. #include "cmVisualStudio10TargetGenerator.h"
  11. #include "cmXMLParser.h"
  12. #include "cmake.h"
  13. class cmVS10XMLParser : public cmXMLParser
  14. {
  15. public:
  16. virtual void EndElement(const std::string& /* name */) {}
  17. virtual void CharacterDataHandler(const char* data, int length)
  18. {
  19. if (this->DoGUID) {
  20. if (data[0] == '{') {
  21. // remove surrounding curly brackets
  22. this->GUID.assign(data + 1, length - 2);
  23. } else {
  24. this->GUID.assign(data, length);
  25. }
  26. this->DoGUID = false;
  27. }
  28. }
  29. virtual void StartElement(const std::string& name, const char**)
  30. {
  31. // once the GUID is found do nothing
  32. if (!this->GUID.empty()) {
  33. return;
  34. }
  35. if ("ProjectGUID" == name || "ProjectGuid" == name) {
  36. this->DoGUID = true;
  37. }
  38. }
  39. int InitializeParser()
  40. {
  41. this->DoGUID = false;
  42. int ret = cmXMLParser::InitializeParser();
  43. if (ret == 0) {
  44. return ret;
  45. }
  46. // visual studio projects have a strange encoding, but it is
  47. // really utf-8
  48. XML_SetEncoding(static_cast<XML_Parser>(this->Parser), "utf-8");
  49. return 1;
  50. }
  51. std::string GUID;
  52. bool DoGUID;
  53. };
  54. cmLocalVisualStudio10Generator::cmLocalVisualStudio10Generator(
  55. cmGlobalGenerator* gg, cmMakefile* mf)
  56. : cmLocalVisualStudio7Generator(gg, mf)
  57. {
  58. }
  59. cmLocalVisualStudio10Generator::~cmLocalVisualStudio10Generator()
  60. {
  61. }
  62. void cmLocalVisualStudio10Generator::GenerateTargetsDepthFirst(
  63. cmGeneratorTarget* target, std::vector<cmGeneratorTarget*>& remaining)
  64. {
  65. if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  66. return;
  67. }
  68. // Find this target in the list of remaining targets.
  69. auto it = std::find(remaining.begin(), remaining.end(), target);
  70. if (it == remaining.end()) {
  71. // This target was already handled.
  72. return;
  73. }
  74. // Remove this target from the list of remaining targets because
  75. // we are handling it now.
  76. *it = nullptr;
  77. auto& deps = this->GlobalGenerator->GetTargetDirectDepends(target);
  78. for (auto& d : deps) {
  79. // FIXME: Revise CreateSingleVCProj so we do not have to drop `const` here.
  80. auto dependee = const_cast<cmGeneratorTarget*>(&*d);
  81. GenerateTargetsDepthFirst(dependee, remaining);
  82. // Take the union of visited source files of custom commands
  83. auto visited = GetSourcesVisited(dependee);
  84. GetSourcesVisited(target).insert(visited.begin(), visited.end());
  85. }
  86. if (static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
  87. ->TargetIsFortranOnly(target)) {
  88. this->CreateSingleVCProj(target->GetName(), target);
  89. } else {
  90. cmVisualStudio10TargetGenerator tg(
  91. target,
  92. static_cast<cmGlobalVisualStudio10Generator*>(
  93. this->GetGlobalGenerator()));
  94. tg.Generate();
  95. }
  96. }
  97. void cmLocalVisualStudio10Generator::Generate()
  98. {
  99. std::vector<cmGeneratorTarget*> remaining;
  100. cm::append(remaining, this->GetGeneratorTargets());
  101. for (auto& t : remaining) {
  102. if (t) {
  103. this->GenerateTargetsDepthFirst(t, remaining);
  104. }
  105. }
  106. this->WriteStampFiles();
  107. }
  108. void cmLocalVisualStudio10Generator::ReadAndStoreExternalGUID(
  109. const std::string& name, const char* path)
  110. {
  111. cmVS10XMLParser parser;
  112. parser.ParseFile(path);
  113. // if we can not find a GUID then we will generate one later
  114. if (parser.GUID.empty()) {
  115. return;
  116. }
  117. std::string guidStoreName = cmStrCat(name, "_GUID_CMAKE");
  118. // save the GUID in the cache
  119. this->GlobalGenerator->GetCMakeInstance()->AddCacheEntry(
  120. guidStoreName.c_str(), parser.GUID.c_str(), "Stored GUID",
  121. cmStateEnums::INTERNAL);
  122. }
  123. const char* cmLocalVisualStudio10Generator::ReportErrorLabel() const
  124. {
  125. return ":VCEnd";
  126. }