cmLocalVisualStudio10Generator.cxx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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/string_view>
  5. #include <cm3p/expat.h>
  6. #include "cmGlobalGenerator.h"
  7. #include "cmGlobalVisualStudio10Generator.h"
  8. #include "cmGlobalVisualStudioGenerator.h"
  9. #include "cmStateTypes.h"
  10. #include "cmStringAlgorithms.h"
  11. #include "cmVisualStudio10TargetGenerator.h"
  12. #include "cmXMLParser.h"
  13. #include "cmake.h"
  14. class cmGeneratorTarget;
  15. class cmVS10XMLParser : public cmXMLParser
  16. {
  17. public:
  18. void EndElement(const std::string& /* name */) override {}
  19. void CharacterDataHandler(const char* data, int length) override
  20. {
  21. if (this->DoGUID) {
  22. if (data[0] == '{') {
  23. // remove surrounding curly brackets
  24. this->GUID.assign(data + 1, length - 2);
  25. } else {
  26. this->GUID.assign(data, length);
  27. }
  28. this->DoGUID = false;
  29. }
  30. }
  31. void StartElement(const std::string& name, const char**) override
  32. {
  33. // once the GUID is found do nothing
  34. if (!this->GUID.empty()) {
  35. return;
  36. }
  37. if (name == "ProjectGUID"_s || name == "ProjectGuid"_s) {
  38. this->DoGUID = true;
  39. }
  40. }
  41. int InitializeParser() override
  42. {
  43. this->DoGUID = false;
  44. int ret = cmXMLParser::InitializeParser();
  45. if (ret == 0) {
  46. return ret;
  47. }
  48. // visual studio projects have a strange encoding, but it is
  49. // really utf-8
  50. XML_SetEncoding(static_cast<XML_Parser>(this->Parser), "utf-8");
  51. return 1;
  52. }
  53. std::string GUID;
  54. bool DoGUID;
  55. };
  56. cmLocalVisualStudio10Generator::cmLocalVisualStudio10Generator(
  57. cmGlobalGenerator* gg, cmMakefile* mf)
  58. : cmLocalVisualStudio7Generator(gg, mf)
  59. {
  60. }
  61. cmLocalVisualStudio10Generator::~cmLocalVisualStudio10Generator() = default;
  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. }