cmLocalVisualStudio10Generator.cxx 2.8 KB

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