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 <cm3p/expat.h>
  5. #include "cmGlobalGenerator.h"
  6. #include "cmGlobalVisualStudio10Generator.h"
  7. #include "cmGlobalVisualStudioGenerator.h"
  8. #include "cmStateTypes.h"
  9. #include "cmStringAlgorithms.h"
  10. #include "cmVisualStudio10TargetGenerator.h"
  11. #include "cmXMLParser.h"
  12. #include "cmake.h"
  13. class cmGeneratorTarget;
  14. class cmVS10XMLParser : public cmXMLParser
  15. {
  16. public:
  17. virtual void EndElement(const std::string& /* name */) {}
  18. virtual void CharacterDataHandler(const char* data, int length)
  19. {
  20. if (this->DoGUID) {
  21. if (data[0] == '{') {
  22. // remove surrounding curly brackets
  23. this->GUID.assign(data + 1, length - 2);
  24. } else {
  25. this->GUID.assign(data, length);
  26. }
  27. this->DoGUID = false;
  28. }
  29. }
  30. virtual void StartElement(const std::string& name, const char**)
  31. {
  32. // once the GUID is found do nothing
  33. if (!this->GUID.empty()) {
  34. return;
  35. }
  36. if ("ProjectGUID" == name || "ProjectGuid" == name) {
  37. this->DoGUID = true;
  38. }
  39. }
  40. int InitializeParser()
  41. {
  42. this->DoGUID = false;
  43. int ret = cmXMLParser::InitializeParser();
  44. if (ret == 0) {
  45. return ret;
  46. }
  47. // visual studio projects have a strange encoding, but it is
  48. // really utf-8
  49. XML_SetEncoding(static_cast<XML_Parser>(this->Parser), "utf-8");
  50. return 1;
  51. }
  52. std::string GUID;
  53. bool DoGUID;
  54. };
  55. cmLocalVisualStudio10Generator::cmLocalVisualStudio10Generator(
  56. cmGlobalGenerator* gg, cmMakefile* mf)
  57. : cmLocalVisualStudio7Generator(gg, mf)
  58. {
  59. }
  60. cmLocalVisualStudio10Generator::~cmLocalVisualStudio10Generator()
  61. {
  62. }
  63. void cmLocalVisualStudio10Generator::GenerateTarget(cmGeneratorTarget* target)
  64. {
  65. if (static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
  66. ->TargetIsFortranOnly(target)) {
  67. this->cmLocalVisualStudio7Generator::GenerateTarget(target);
  68. } else {
  69. cmVisualStudio10TargetGenerator tg(
  70. target,
  71. static_cast<cmGlobalVisualStudio10Generator*>(
  72. this->GetGlobalGenerator()));
  73. tg.Generate();
  74. }
  75. }
  76. void cmLocalVisualStudio10Generator::ReadAndStoreExternalGUID(
  77. const std::string& name, const char* path)
  78. {
  79. cmVS10XMLParser parser;
  80. parser.ParseFile(path);
  81. // if we can not find a GUID then we will generate one later
  82. if (parser.GUID.empty()) {
  83. return;
  84. }
  85. std::string guidStoreName = cmStrCat(name, "_GUID_CMAKE");
  86. // save the GUID in the cache
  87. this->GlobalGenerator->GetCMakeInstance()->AddCacheEntry(
  88. guidStoreName, parser.GUID.c_str(), "Stored GUID", cmStateEnums::INTERNAL);
  89. }
  90. const char* cmLocalVisualStudio10Generator::ReportErrorLabel() const
  91. {
  92. return ":VCEnd";
  93. }