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