cmLocalVisualStudio10Generator.cxx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 <cm3p/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::GenerateTarget(cmGeneratorTarget* target)
  63. {
  64. auto& targetVisited = this->GetSourcesVisited(target);
  65. auto& deps = this->GlobalGenerator->GetTargetDirectDepends(target);
  66. for (auto& d : deps) {
  67. // Take the union of visited source files of custom commands
  68. auto depVisited = this->GetSourcesVisited(d);
  69. targetVisited.insert(depVisited.begin(), depVisited.end());
  70. }
  71. if (static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
  72. ->TargetIsFortranOnly(target)) {
  73. this->cmLocalVisualStudio7Generator::GenerateTarget(target);
  74. } else {
  75. cmVisualStudio10TargetGenerator tg(
  76. target,
  77. static_cast<cmGlobalVisualStudio10Generator*>(
  78. this->GetGlobalGenerator()));
  79. tg.Generate();
  80. }
  81. }
  82. void cmLocalVisualStudio10Generator::ReadAndStoreExternalGUID(
  83. const std::string& name, const char* path)
  84. {
  85. cmVS10XMLParser parser;
  86. parser.ParseFile(path);
  87. // if we can not find a GUID then we will generate one later
  88. if (parser.GUID.empty()) {
  89. return;
  90. }
  91. std::string guidStoreName = cmStrCat(name, "_GUID_CMAKE");
  92. // save the GUID in the cache
  93. this->GlobalGenerator->GetCMakeInstance()->AddCacheEntry(
  94. guidStoreName, parser.GUID.c_str(), "Stored GUID", cmStateEnums::INTERNAL);
  95. }
  96. const char* cmLocalVisualStudio10Generator::ReportErrorLabel() const
  97. {
  98. return ":VCEnd";
  99. }