cmLocalVisualStudio10Generator.cxx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. if (static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
  65. ->TargetIsFortranOnly(target)) {
  66. this->cmLocalVisualStudio7Generator::GenerateTarget(target);
  67. } else {
  68. cmVisualStudio10TargetGenerator tg(
  69. target,
  70. static_cast<cmGlobalVisualStudio10Generator*>(
  71. this->GetGlobalGenerator()));
  72. tg.Generate();
  73. }
  74. }
  75. void cmLocalVisualStudio10Generator::ReadAndStoreExternalGUID(
  76. const std::string& name, const char* path)
  77. {
  78. cmVS10XMLParser parser;
  79. parser.ParseFile(path);
  80. // if we can not find a GUID then we will generate one later
  81. if (parser.GUID.empty()) {
  82. return;
  83. }
  84. std::string guidStoreName = cmStrCat(name, "_GUID_CMAKE");
  85. // save the GUID in the cache
  86. this->GlobalGenerator->GetCMakeInstance()->AddCacheEntry(
  87. guidStoreName, parser.GUID.c_str(), "Stored GUID", cmStateEnums::INTERNAL);
  88. }
  89. const char* cmLocalVisualStudio10Generator::ReportErrorLabel() const
  90. {
  91. return ":VCEnd";
  92. }